]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd rfapi: RR replated (Issue #91) treat filtered update
[mirror_frr.git] / bgpd / bgp_route.c
1 /* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4 This file is part of GNU Zebra.
5
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #include <zebra.h>
22
23 #include "lib/json.h"
24 #include "prefix.h"
25 #include "linklist.h"
26 #include "memory.h"
27 #include "command.h"
28 #include "stream.h"
29 #include "filter.h"
30 #include "log.h"
31 #include "routemap.h"
32 #include "buffer.h"
33 #include "sockunion.h"
34 #include "plist.h"
35 #include "thread.h"
36 #include "workqueue.h"
37 #include "queue.h"
38 #include "memory.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_table.h"
42 #include "bgpd/bgp_route.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_debug.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_regex.h"
47 #include "bgpd/bgp_community.h"
48 #include "bgpd/bgp_ecommunity.h"
49 #include "bgpd/bgp_clist.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_nexthop.h"
55 #include "bgpd/bgp_damp.h"
56 #include "bgpd/bgp_advertise.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_mpath.h"
60 #include "bgpd/bgp_nht.h"
61 #include "bgpd/bgp_updgrp.h"
62 #include "bgpd/bgp_vty.h"
63
64 #if ENABLE_BGP_VNC
65 #include "bgpd/rfapi/rfapi_backend.h"
66 #include "bgpd/rfapi/vnc_import_bgp.h"
67 #include "bgpd/rfapi/vnc_export_bgp.h"
68 #endif
69
70 /* Extern from bgp_dump.c */
71 extern const char *bgp_origin_str[];
72 extern const char *bgp_origin_long_str[];
73
74 struct bgp_node *
75 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
76 struct prefix_rd *prd)
77 {
78 struct bgp_node *rn;
79 struct bgp_node *prn = NULL;
80
81 assert (table);
82 if (!table)
83 return NULL;
84
85 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
86 {
87 prn = bgp_node_get (table, (struct prefix *) prd);
88
89 if (prn->info == NULL)
90 prn->info = bgp_table_init (afi, safi);
91 else
92 bgp_unlock_node (prn);
93 table = prn->info;
94 }
95
96 rn = bgp_node_get (table, p);
97
98 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
99 rn->prn = prn;
100
101 return rn;
102 }
103
104 /* Allocate bgp_info_extra */
105 static struct bgp_info_extra *
106 bgp_info_extra_new (void)
107 {
108 struct bgp_info_extra *new;
109 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
110 return new;
111 }
112
113 static void
114 bgp_info_extra_free (struct bgp_info_extra **extra)
115 {
116 if (extra && *extra)
117 {
118 if ((*extra)->damp_info)
119 bgp_damp_info_free ((*extra)->damp_info, 0);
120
121 (*extra)->damp_info = NULL;
122
123 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
124
125 *extra = NULL;
126 }
127 }
128
129 /* Get bgp_info extra information for the given bgp_info, lazy allocated
130 * if required.
131 */
132 struct bgp_info_extra *
133 bgp_info_extra_get (struct bgp_info *ri)
134 {
135 if (!ri->extra)
136 ri->extra = bgp_info_extra_new();
137 return ri->extra;
138 }
139
140 /* Allocate new bgp info structure. */
141 struct bgp_info *
142 bgp_info_new (void)
143 {
144 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
145 }
146
147 /* Free bgp route information. */
148 static void
149 bgp_info_free (struct bgp_info *binfo)
150 {
151 if (binfo->attr)
152 bgp_attr_unintern (&binfo->attr);
153
154 bgp_unlink_nexthop(binfo);
155 bgp_info_extra_free (&binfo->extra);
156 bgp_info_mpath_free (&binfo->mpath);
157
158 peer_unlock (binfo->peer); /* bgp_info peer reference */
159
160 XFREE (MTYPE_BGP_ROUTE, binfo);
161 }
162
163 struct bgp_info *
164 bgp_info_lock (struct bgp_info *binfo)
165 {
166 binfo->lock++;
167 return binfo;
168 }
169
170 struct bgp_info *
171 bgp_info_unlock (struct bgp_info *binfo)
172 {
173 assert (binfo && binfo->lock > 0);
174 binfo->lock--;
175
176 if (binfo->lock == 0)
177 {
178 #if 0
179 zlog_debug ("%s: unlocked and freeing", __func__);
180 zlog_backtrace (LOG_DEBUG);
181 #endif
182 bgp_info_free (binfo);
183 return NULL;
184 }
185
186 #if 0
187 if (binfo->lock == 1)
188 {
189 zlog_debug ("%s: unlocked to 1", __func__);
190 zlog_backtrace (LOG_DEBUG);
191 }
192 #endif
193
194 return binfo;
195 }
196
197 void
198 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
199 {
200 struct bgp_info *top;
201
202 top = rn->info;
203
204 ri->next = rn->info;
205 ri->prev = NULL;
206 if (top)
207 top->prev = ri;
208 rn->info = ri;
209
210 bgp_info_lock (ri);
211 bgp_lock_node (rn);
212 peer_lock (ri->peer); /* bgp_info peer reference */
213 }
214
215 /* Do the actual removal of info from RIB, for use by bgp_process
216 completion callback *only* */
217 static void
218 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
219 {
220 if (ri->next)
221 ri->next->prev = ri->prev;
222 if (ri->prev)
223 ri->prev->next = ri->next;
224 else
225 rn->info = ri->next;
226
227 bgp_info_mpath_dequeue (ri);
228 bgp_info_unlock (ri);
229 bgp_unlock_node (rn);
230 }
231
232 void
233 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
234 {
235 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
236 /* set of previous already took care of pcount */
237 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
238 }
239
240 /* undo the effects of a previous call to bgp_info_delete; typically
241 called when a route is deleted and then quickly re-added before the
242 deletion has been processed */
243 void
244 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
245 {
246 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
247 /* unset of previous already took care of pcount */
248 SET_FLAG (ri->flags, BGP_INFO_VALID);
249 }
250
251 /* Adjust pcount as required */
252 static void
253 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
254 {
255 struct bgp_table *table;
256
257 assert (rn && bgp_node_table (rn));
258 assert (ri && ri->peer && ri->peer->bgp);
259
260 table = bgp_node_table (rn);
261
262 if (ri->peer == ri->peer->bgp->peer_self)
263 return;
264
265 if (!BGP_INFO_COUNTABLE (ri)
266 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268
269 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
270
271 /* slight hack, but more robust against errors. */
272 if (ri->peer->pcount[table->afi][table->safi])
273 ri->peer->pcount[table->afi][table->safi]--;
274 else
275 {
276 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
277 __func__, ri->peer->host);
278 zlog_backtrace (LOG_WARNING);
279 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
280 }
281 }
282 else if (BGP_INFO_COUNTABLE (ri)
283 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
284 {
285 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
286 ri->peer->pcount[table->afi][table->safi]++;
287 }
288 }
289
290
291 /* Set/unset bgp_info flags, adjusting any other state as needed.
292 * This is here primarily to keep prefix-count in check.
293 */
294 void
295 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296 {
297 SET_FLAG (ri->flags, flag);
298
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304 }
305
306 void
307 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
308 {
309 UNSET_FLAG (ri->flags, flag);
310
311 /* early bath if we know it's not a flag that changes countability state */
312 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
313 return;
314
315 bgp_pcount_adjust (rn, ri);
316 }
317
318 /* Get MED value. If MED value is missing and "bgp bestpath
319 missing-as-worst" is specified, treat it as the worst value. */
320 static u_int32_t
321 bgp_med_value (struct attr *attr, struct bgp *bgp)
322 {
323 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
324 return attr->med;
325 else
326 {
327 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
328 return BGP_MED_MAX;
329 else
330 return 0;
331 }
332 }
333
334 void
335 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
336 {
337 if (ri->addpath_rx_id)
338 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
339 else
340 sprintf(buf, "path %s", ri->peer->host);
341 }
342
343 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
344 static int
345 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
346 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
347 const char *pfx_buf)
348 {
349 struct attr *newattr, *existattr;
350 struct attr_extra *newattre, *existattre;
351 bgp_peer_sort_t new_sort;
352 bgp_peer_sort_t exist_sort;
353 u_int32_t new_pref;
354 u_int32_t exist_pref;
355 u_int32_t new_med;
356 u_int32_t exist_med;
357 u_int32_t new_weight;
358 u_int32_t exist_weight;
359 uint32_t newm, existm;
360 struct in_addr new_id;
361 struct in_addr exist_id;
362 int new_cluster;
363 int exist_cluster;
364 int internal_as_route;
365 int confed_as_route;
366 int ret;
367 char new_buf[PATH_ADDPATH_STR_BUFFER];
368 char exist_buf[PATH_ADDPATH_STR_BUFFER];
369
370 *paths_eq = 0;
371
372 /* 0. Null check. */
373 if (new == NULL)
374 {
375 if (debug)
376 zlog_debug("%s: new is NULL", pfx_buf);
377 return 0;
378 }
379
380 if (debug)
381 bgp_info_path_with_addpath_rx_str (new, new_buf);
382
383 if (exist == NULL)
384 {
385 if (debug)
386 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
387 return 1;
388 }
389
390 if (debug)
391 {
392 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
393 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
394 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
395 }
396
397 newattr = new->attr;
398 existattr = exist->attr;
399 newattre = newattr->extra;
400 existattre = existattr->extra;
401
402 /* 1. Weight check. */
403 new_weight = exist_weight = 0;
404
405 if (newattre)
406 new_weight = newattre->weight;
407 if (existattre)
408 exist_weight = existattre->weight;
409
410 if (new_weight > exist_weight)
411 {
412 if (debug)
413 zlog_debug("%s: %s wins over %s due to weight %d > %d",
414 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
415 return 1;
416 }
417
418 if (new_weight < exist_weight)
419 {
420 if (debug)
421 zlog_debug("%s: %s loses to %s due to weight %d < %d",
422 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
423 return 0;
424 }
425
426 /* 2. Local preference check. */
427 new_pref = exist_pref = bgp->default_local_pref;
428
429 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
430 new_pref = newattr->local_pref;
431 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
432 exist_pref = existattr->local_pref;
433
434 if (new_pref > exist_pref)
435 {
436 if (debug)
437 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
438 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
439 return 1;
440 }
441
442 if (new_pref < exist_pref)
443 {
444 if (debug)
445 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
446 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
447 return 0;
448 }
449
450 /* 3. Local route check. We prefer:
451 * - BGP_ROUTE_STATIC
452 * - BGP_ROUTE_AGGREGATE
453 * - BGP_ROUTE_REDISTRIBUTE
454 */
455 if (! (new->sub_type == BGP_ROUTE_NORMAL))
456 {
457 if (debug)
458 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
459 pfx_buf, new_buf, exist_buf);
460 return 1;
461 }
462
463 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
464 {
465 if (debug)
466 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
467 pfx_buf, new_buf, exist_buf);
468 return 0;
469 }
470
471 /* 4. AS path length check. */
472 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
473 {
474 int exist_hops = aspath_count_hops (existattr->aspath);
475 int exist_confeds = aspath_count_confeds (existattr->aspath);
476
477 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
478 {
479 int aspath_hops;
480
481 aspath_hops = aspath_count_hops (newattr->aspath);
482 aspath_hops += aspath_count_confeds (newattr->aspath);
483
484 if ( aspath_hops < (exist_hops + exist_confeds))
485 {
486 if (debug)
487 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
488 pfx_buf, new_buf, exist_buf,
489 aspath_hops, (exist_hops + exist_confeds));
490 return 1;
491 }
492
493 if ( aspath_hops > (exist_hops + exist_confeds))
494 {
495 if (debug)
496 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
497 pfx_buf, new_buf, exist_buf,
498 aspath_hops, (exist_hops + exist_confeds));
499 return 0;
500 }
501 }
502 else
503 {
504 int newhops = aspath_count_hops (newattr->aspath);
505
506 if (newhops < exist_hops)
507 {
508 if (debug)
509 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
510 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
511 return 1;
512 }
513
514 if (newhops > exist_hops)
515 {
516 if (debug)
517 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
518 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
519 return 0;
520 }
521 }
522 }
523
524 /* 5. Origin check. */
525 if (newattr->origin < existattr->origin)
526 {
527 if (debug)
528 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
529 pfx_buf, new_buf, exist_buf,
530 bgp_origin_long_str[newattr->origin],
531 bgp_origin_long_str[existattr->origin]);
532 return 1;
533 }
534
535 if (newattr->origin > existattr->origin)
536 {
537 if (debug)
538 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
539 pfx_buf, new_buf, exist_buf,
540 bgp_origin_long_str[newattr->origin],
541 bgp_origin_long_str[existattr->origin]);
542 return 0;
543 }
544
545 /* 6. MED check. */
546 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
547 && aspath_count_hops (existattr->aspath) == 0);
548 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
549 && aspath_count_confeds (existattr->aspath) > 0
550 && aspath_count_hops (newattr->aspath) == 0
551 && aspath_count_hops (existattr->aspath) == 0);
552
553 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
554 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
555 && confed_as_route)
556 || aspath_cmp_left (newattr->aspath, existattr->aspath)
557 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
558 || internal_as_route)
559 {
560 new_med = bgp_med_value (new->attr, bgp);
561 exist_med = bgp_med_value (exist->attr, bgp);
562
563 if (new_med < exist_med)
564 {
565 if (debug)
566 zlog_debug("%s: %s wins over %s due to MED %d < %d",
567 pfx_buf, new_buf, exist_buf, new_med, exist_med);
568 return 1;
569 }
570
571 if (new_med > exist_med)
572 {
573 if (debug)
574 zlog_debug("%s: %s loses to %s due to MED %d > %d",
575 pfx_buf, new_buf, exist_buf, new_med, exist_med);
576 return 0;
577 }
578 }
579
580 /* 7. Peer type check. */
581 new_sort = new->peer->sort;
582 exist_sort = exist->peer->sort;
583
584 if (new_sort == BGP_PEER_EBGP
585 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
586 {
587 if (debug)
588 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
589 pfx_buf, new_buf, exist_buf);
590 return 1;
591 }
592
593 if (exist_sort == BGP_PEER_EBGP
594 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
595 {
596 if (debug)
597 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
598 pfx_buf, new_buf, exist_buf);
599 return 0;
600 }
601
602 /* 8. IGP metric check. */
603 newm = existm = 0;
604
605 if (new->extra)
606 newm = new->extra->igpmetric;
607 if (exist->extra)
608 existm = exist->extra->igpmetric;
609
610 if (newm < existm)
611 {
612 if (debug)
613 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
614 pfx_buf, new_buf, exist_buf, newm, existm);
615 ret = 1;
616 }
617
618 if (newm > existm)
619 {
620 if (debug)
621 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
622 pfx_buf, new_buf, exist_buf, newm, existm);
623 ret = 0;
624 }
625
626 /* 9. Same IGP metric. Compare the cluster list length as
627 representative of IGP hops metric. Rewrite the metric value
628 pair (newm, existm) with the cluster list length. Prefer the
629 path with smaller cluster list length. */
630 if (newm == existm)
631 {
632 if (peer_sort (new->peer) == BGP_PEER_IBGP
633 && peer_sort (exist->peer) == BGP_PEER_IBGP
634 && (mpath_cfg == NULL ||
635 CHECK_FLAG (mpath_cfg->ibgp_flags,
636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN)))
637 {
638 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
639 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
640
641 if (newm < existm)
642 {
643 if (debug)
644 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
645 pfx_buf, new_buf, exist_buf, newm, existm);
646 ret = 1;
647 }
648
649 if (newm > existm)
650 {
651 if (debug)
652 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
653 pfx_buf, new_buf, exist_buf, newm, existm);
654 ret = 0;
655 }
656 }
657 }
658
659 /* 10. confed-external vs. confed-internal */
660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
661 {
662 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
663 {
664 if (debug)
665 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
666 pfx_buf, new_buf, exist_buf);
667 return 1;
668 }
669
670 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
671 {
672 if (debug)
673 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
674 pfx_buf, new_buf, exist_buf);
675 return 0;
676 }
677 }
678
679 /* 11. Maximum path check. */
680 if (newm == existm)
681 {
682 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
683 {
684
685 /*
686 * For the two paths, all comparison steps till IGP metric
687 * have succeeded - including AS_PATH hop count. Since 'bgp
688 * bestpath as-path multipath-relax' knob is on, we don't need
689 * an exact match of AS_PATH. Thus, mark the paths are equal.
690 * That will trigger both these paths to get into the multipath
691 * array.
692 */
693 *paths_eq = 1;
694
695 if (debug)
696 zlog_debug("%s: %s and %s are equal via multipath-relax",
697 pfx_buf, new_buf, exist_buf);
698 }
699 else if (new->peer->sort == BGP_PEER_IBGP)
700 {
701 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
702 {
703 *paths_eq = 1;
704
705 if (debug)
706 zlog_debug("%s: %s and %s are equal via matching aspaths",
707 pfx_buf, new_buf, exist_buf);
708 }
709 }
710 else if (new->peer->as == exist->peer->as)
711 {
712 *paths_eq = 1;
713
714 if (debug)
715 zlog_debug("%s: %s and %s are equal via same remote-as",
716 pfx_buf, new_buf, exist_buf);
717 }
718 }
719 else
720 {
721 /*
722 * TODO: If unequal cost ibgp multipath is enabled we can
723 * mark the paths as equal here instead of returning
724 */
725 if (debug)
726 {
727 if (ret == 1)
728 zlog_debug("%s: %s wins over %s after IGP metric comparison",
729 pfx_buf, new_buf, exist_buf);
730 else
731 zlog_debug("%s: %s loses to %s after IGP metric comparison",
732 pfx_buf, new_buf, exist_buf);
733 }
734 return ret;
735 }
736
737 /* 12. If both paths are external, prefer the path that was received
738 first (the oldest one). This step minimizes route-flap, since a
739 newer path won't displace an older one, even if it was the
740 preferred route based on the additional decision criteria below. */
741 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
742 && new_sort == BGP_PEER_EBGP
743 && exist_sort == BGP_PEER_EBGP)
744 {
745 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
746 {
747 if (debug)
748 zlog_debug("%s: %s wins over %s due to oldest external",
749 pfx_buf, new_buf, exist_buf);
750 return 1;
751 }
752
753 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
754 {
755 if (debug)
756 zlog_debug("%s: %s loses to %s due to oldest external",
757 pfx_buf, new_buf, exist_buf);
758 return 0;
759 }
760 }
761
762 /* 13. Router-ID comparision. */
763 /* If one of the paths is "stale", the corresponding peer router-id will
764 * be 0 and would always win over the other path. If originator id is
765 * used for the comparision, it will decide which path is better.
766 */
767 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
768 new_id.s_addr = newattre->originator_id.s_addr;
769 else
770 new_id.s_addr = new->peer->remote_id.s_addr;
771 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
772 exist_id.s_addr = existattre->originator_id.s_addr;
773 else
774 exist_id.s_addr = exist->peer->remote_id.s_addr;
775
776 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
777 {
778 if (debug)
779 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
780 pfx_buf, new_buf, exist_buf);
781 return 1;
782 }
783
784 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
785 {
786 if (debug)
787 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
788 pfx_buf, new_buf, exist_buf);
789 return 0;
790 }
791
792 /* 14. Cluster length comparision. */
793 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
794 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
795
796 if (new_cluster < exist_cluster)
797 {
798 if (debug)
799 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
800 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
801 return 1;
802 }
803
804 if (new_cluster > exist_cluster)
805 {
806 if (debug)
807 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
808 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
809 return 0;
810 }
811
812 /* 15. Neighbor address comparision. */
813 /* Do this only if neither path is "stale" as stale paths do not have
814 * valid peer information (as the connection may or may not be up).
815 */
816 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
817 {
818 if (debug)
819 zlog_debug("%s: %s wins over %s due to latter path being STALE",
820 pfx_buf, new_buf, exist_buf);
821 return 1;
822 }
823
824 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
825 {
826 if (debug)
827 zlog_debug("%s: %s loses to %s due to former path being STALE",
828 pfx_buf, new_buf, exist_buf);
829 return 0;
830 }
831
832 /* locally configured routes to advertise do not have su_remote */
833 if (new->peer->su_remote == NULL)
834 return 0;
835 if (exist->peer->su_remote == NULL)
836 return 1;
837
838 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
839
840 if (ret == 1)
841 {
842 if (debug)
843 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
844 pfx_buf, new_buf, exist_buf);
845 return 0;
846 }
847
848 if (ret == -1)
849 {
850 if (debug)
851 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
852 pfx_buf, new_buf, exist_buf);
853 return 1;
854 }
855
856 if (debug)
857 zlog_debug("%s: %s wins over %s due to nothing left to compare",
858 pfx_buf, new_buf, exist_buf);
859
860 return 1;
861 }
862
863 /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
864 * is preferred, or 0 if they are the same (usually will only occur if
865 * multipath is enabled
866 * This version is compatible with */
867 int
868 bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
869 afi_t afi, safi_t safi)
870 {
871 int paths_eq;
872 int ret;
873 ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0, __func__);
874
875 if (paths_eq)
876 ret = 0;
877 else
878 {
879 if (ret == 1)
880 ret = -1;
881 else
882 ret = 1;
883 }
884 return ret;
885 }
886
887 static enum filter_type
888 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
889 afi_t afi, safi_t safi)
890 {
891 struct bgp_filter *filter;
892
893 filter = &peer->filter[afi][safi];
894
895 #define FILTER_EXIST_WARN(F,f,filter) \
896 if (BGP_DEBUG (update, UPDATE_IN) \
897 && !(F ## _IN (filter))) \
898 zlog_warn ("%s: Could not find configured input %s-list %s!", \
899 peer->host, #f, F ## _IN_NAME(filter));
900
901 if (DISTRIBUTE_IN_NAME (filter)) {
902 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
903
904 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
905 return FILTER_DENY;
906 }
907
908 if (PREFIX_LIST_IN_NAME (filter)) {
909 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
910
911 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
912 return FILTER_DENY;
913 }
914
915 if (FILTER_LIST_IN_NAME (filter)) {
916 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
917
918 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
919 return FILTER_DENY;
920 }
921
922 return FILTER_PERMIT;
923 #undef FILTER_EXIST_WARN
924 }
925
926 static enum filter_type
927 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
928 afi_t afi, safi_t safi)
929 {
930 struct bgp_filter *filter;
931
932 filter = &peer->filter[afi][safi];
933
934 #define FILTER_EXIST_WARN(F,f,filter) \
935 if (BGP_DEBUG (update, UPDATE_OUT) \
936 && !(F ## _OUT (filter))) \
937 zlog_warn ("%s: Could not find configured output %s-list %s!", \
938 peer->host, #f, F ## _OUT_NAME(filter));
939
940 if (DISTRIBUTE_OUT_NAME (filter)) {
941 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
942
943 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
944 return FILTER_DENY;
945 }
946
947 if (PREFIX_LIST_OUT_NAME (filter)) {
948 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
949
950 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
951 return FILTER_DENY;
952 }
953
954 if (FILTER_LIST_OUT_NAME (filter)) {
955 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
956
957 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
958 return FILTER_DENY;
959 }
960
961 return FILTER_PERMIT;
962 #undef FILTER_EXIST_WARN
963 }
964
965 /* If community attribute includes no_export then return 1. */
966 static int
967 bgp_community_filter (struct peer *peer, struct attr *attr)
968 {
969 if (attr->community)
970 {
971 /* NO_ADVERTISE check. */
972 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
973 return 1;
974
975 /* NO_EXPORT check. */
976 if (peer->sort == BGP_PEER_EBGP &&
977 community_include (attr->community, COMMUNITY_NO_EXPORT))
978 return 1;
979
980 /* NO_EXPORT_SUBCONFED check. */
981 if (peer->sort == BGP_PEER_EBGP
982 || peer->sort == BGP_PEER_CONFED)
983 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
984 return 1;
985 }
986 return 0;
987 }
988
989 /* Route reflection loop check. */
990 static int
991 bgp_cluster_filter (struct peer *peer, struct attr *attr)
992 {
993 struct in_addr cluster_id;
994
995 if (attr->extra && attr->extra->cluster)
996 {
997 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
998 cluster_id = peer->bgp->cluster_id;
999 else
1000 cluster_id = peer->bgp->router_id;
1001
1002 if (cluster_loop_check (attr->extra->cluster, cluster_id))
1003 return 1;
1004 }
1005 return 0;
1006 }
1007
1008 static int
1009 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1010 afi_t afi, safi_t safi, const char *rmap_name)
1011 {
1012 struct bgp_filter *filter;
1013 struct bgp_info info;
1014 route_map_result_t ret;
1015 struct route_map *rmap = NULL;
1016
1017 filter = &peer->filter[afi][safi];
1018
1019 /* Apply default weight value. */
1020 if (peer->weight[afi][safi])
1021 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1022
1023 if (rmap_name)
1024 {
1025 rmap = route_map_lookup_by_name(rmap_name);
1026
1027 if (rmap == NULL)
1028 return RMAP_DENY;
1029 }
1030 else
1031 {
1032 if (ROUTE_MAP_IN_NAME(filter))
1033 {
1034 rmap = ROUTE_MAP_IN (filter);
1035
1036 if (rmap == NULL)
1037 return RMAP_DENY;
1038 }
1039 }
1040
1041 /* Route map apply. */
1042 if (rmap)
1043 {
1044 /* Duplicate current value to new strucutre for modification. */
1045 info.peer = peer;
1046 info.attr = attr;
1047
1048 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1049
1050 /* Apply BGP route map to the attribute. */
1051 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1052
1053 peer->rmap_type = 0;
1054
1055 if (ret == RMAP_DENYMATCH)
1056 {
1057 /* Free newly generated AS path and community by route-map. */
1058 bgp_attr_flush (attr);
1059 return RMAP_DENY;
1060 }
1061 }
1062 return RMAP_PERMIT;
1063 }
1064
1065 static int
1066 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1067 afi_t afi, safi_t safi, const char *rmap_name)
1068 {
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 route_map_result_t ret;
1072 struct route_map *rmap = NULL;
1073
1074 filter = &peer->filter[afi][safi];
1075
1076 /* Apply default weight value. */
1077 if (peer->weight[afi][safi])
1078 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1079
1080 if (rmap_name)
1081 {
1082 rmap = route_map_lookup_by_name(rmap_name);
1083
1084 if (rmap == NULL)
1085 return RMAP_DENY;
1086 }
1087 else
1088 {
1089 if (ROUTE_MAP_OUT_NAME(filter))
1090 {
1091 rmap = ROUTE_MAP_OUT (filter);
1092
1093 if (rmap == NULL)
1094 return RMAP_DENY;
1095 }
1096 }
1097
1098 /* Route map apply. */
1099 if (rmap)
1100 {
1101 /* Duplicate current value to new strucutre for modification. */
1102 info.peer = peer;
1103 info.attr = attr;
1104
1105 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1106
1107 /* Apply BGP route map to the attribute. */
1108 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1109
1110 peer->rmap_type = 0;
1111
1112 if (ret == RMAP_DENYMATCH)
1113 /* caller has multiple error paths with bgp_attr_flush() */
1114 return RMAP_DENY;
1115 }
1116 return RMAP_PERMIT;
1117 }
1118
1119 /* If this is an EBGP peer with remove-private-AS */
1120 static void
1121 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1122 struct peer *peer, struct attr *attr)
1123 {
1124 if (peer->sort == BGP_PEER_EBGP &&
1125 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1126 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1128 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1129 {
1130 // Take action on the entire aspath
1131 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1132 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1133 {
1134 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1135 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1136
1137 // The entire aspath consists of private ASNs so create an empty aspath
1138 else if (aspath_private_as_check (attr->aspath))
1139 attr->aspath = aspath_empty_get ();
1140
1141 // There are some public and some private ASNs, remove the private ASNs
1142 else
1143 attr->aspath = aspath_remove_private_asns (attr->aspath);
1144 }
1145
1146 // 'all' was not specified so the entire aspath must be private ASNs
1147 // for us to do anything
1148 else if (aspath_private_as_check (attr->aspath))
1149 {
1150 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1151 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1152 else
1153 attr->aspath = aspath_empty_get ();
1154 }
1155 }
1156 }
1157
1158 /* If this is an EBGP peer with as-override */
1159 static void
1160 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1161 struct peer *peer, struct attr *attr)
1162 {
1163 if (peer->sort == BGP_PEER_EBGP &&
1164 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1165 {
1166 if (aspath_single_asn_check (attr->aspath, peer->as))
1167 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1168 }
1169 }
1170
1171 static void
1172 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1173 {
1174 if (family == AF_INET)
1175 attr->nexthop.s_addr = 0;
1176 #ifdef HAVE_IPV6
1177 if (family == AF_INET6)
1178 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1179 #endif
1180 }
1181
1182 int
1183 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1184 struct prefix *p, struct attr *attr)
1185 {
1186 struct bgp_filter *filter;
1187 struct peer *from;
1188 struct peer *peer;
1189 struct peer *onlypeer;
1190 struct bgp *bgp;
1191 struct attr *riattr;
1192 struct peer_af *paf;
1193 char buf[SU_ADDRSTRLEN];
1194 int ret;
1195 int transparent;
1196 int reflect;
1197 afi_t afi;
1198 safi_t safi;
1199 int samepeer_safe = 0; /* for synthetic mplsvpns routes */
1200
1201 if (DISABLE_BGP_ANNOUNCE)
1202 return 0;
1203
1204 afi = SUBGRP_AFI(subgrp);
1205 safi = SUBGRP_SAFI(subgrp);
1206 peer = SUBGRP_PEER(subgrp);
1207 onlypeer = NULL;
1208 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1209 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1210
1211 from = ri->peer;
1212 filter = &peer->filter[afi][safi];
1213 bgp = SUBGRP_INST(subgrp);
1214 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1215
1216 #if ENABLE_BGP_VNC
1217 if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) &&
1218 ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) ||
1219 (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
1220
1221 /*
1222 * direct and direct_ext type routes originate internally even
1223 * though they can have peer pointers that reference other systems
1224 */
1225 char buf[BUFSIZ];
1226 prefix2str(p, buf, BUFSIZ);
1227 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf);
1228 samepeer_safe = 1;
1229 }
1230 #endif
1231
1232 /* With addpath we may be asked to TX all kinds of paths so make sure
1233 * ri is valid */
1234 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1235 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1236 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1237 {
1238 return 0;
1239 }
1240
1241 /* If this is not the bestpath then check to see if there is an enabled addpath
1242 * feature that requires us to advertise it */
1243 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1244 {
1245 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1246 {
1247 return 0;
1248 }
1249 }
1250
1251 /* Aggregate-address suppress check. */
1252 if (ri->extra && ri->extra->suppress)
1253 if (! UNSUPPRESS_MAP_NAME (filter))
1254 {
1255 return 0;
1256 }
1257
1258 /* Do not send back route to sender. */
1259 if (onlypeer && from == onlypeer)
1260 {
1261 return 0;
1262 }
1263
1264 /* Do not send the default route in the BGP table if the neighbor is
1265 * configured for default-originate */
1266 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1267 {
1268 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1269 return 0;
1270 #ifdef HAVE_IPV6
1271 else if (p->family == AF_INET6 && p->prefixlen == 0)
1272 return 0;
1273 #endif /* HAVE_IPV6 */
1274 }
1275
1276 /* Transparency check. */
1277 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1278 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1279 transparent = 1;
1280 else
1281 transparent = 0;
1282
1283 /* If community is not disabled check the no-export and local. */
1284 if (! transparent && bgp_community_filter (peer, riattr))
1285 {
1286 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1287 zlog_debug ("subgrpannouncecheck: community filter check fail");
1288 return 0;
1289 }
1290
1291 /* If the attribute has originator-id and it is same as remote
1292 peer's id. */
1293 if (onlypeer &&
1294 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1295 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1296 {
1297 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1298 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1299 "remote router-id",
1300 onlypeer->host,
1301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1302 p->prefixlen);
1303 return 0;
1304 }
1305
1306 /* ORF prefix-list filter check */
1307 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1308 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1309 || CHECK_FLAG (peer->af_cap[afi][safi],
1310 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1311 if (peer->orf_plist[afi][safi])
1312 {
1313 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1314 {
1315 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1316 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1317 peer->host,
1318 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1319 p->prefixlen);
1320 return 0;
1321 }
1322 }
1323
1324 /* Output filter check. */
1325 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1326 {
1327 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1328 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1329 peer->host,
1330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1331 p->prefixlen);
1332 return 0;
1333 }
1334
1335 #ifdef BGP_SEND_ASPATH_CHECK
1336 /* AS path loop check. */
1337 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1338 {
1339 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1340 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1341 "that is part of AS path.",
1342 onlypeer->host, onlypeer->as);
1343 return 0;
1344 }
1345 #endif /* BGP_SEND_ASPATH_CHECK */
1346
1347 /* If we're a CONFED we need to loop check the CONFED ID too */
1348 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1349 {
1350 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1351 {
1352 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1353 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1354 " is AS path.",
1355 peer->host,
1356 bgp->confed_id);
1357 return 0;
1358 }
1359 }
1360
1361 /* Route-Reflect check. */
1362 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1363 reflect = 1;
1364 else
1365 reflect = 0;
1366
1367 /* IBGP reflection check. */
1368 if (reflect && !samepeer_safe)
1369 {
1370 /* A route from a Client peer. */
1371 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1372 {
1373 /* Reflect to all the Non-Client peers and also to the
1374 Client peers other than the originator. Originator check
1375 is already done. So there is noting to do. */
1376 /* no bgp client-to-client reflection check. */
1377 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1378 if (CHECK_FLAG (peer->af_flags[afi][safi],
1379 PEER_FLAG_REFLECTOR_CLIENT))
1380 return 0;
1381 }
1382 else
1383 {
1384 /* A route from a Non-client peer. Reflect to all other
1385 clients. */
1386 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1387 PEER_FLAG_REFLECTOR_CLIENT))
1388 return 0;
1389 }
1390 }
1391
1392 /* For modify attribute, copy it to temporary structure. */
1393 bgp_attr_dup (attr, riattr);
1394
1395 /* If local-preference is not set. */
1396 if ((peer->sort == BGP_PEER_IBGP
1397 || peer->sort == BGP_PEER_CONFED)
1398 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1399 {
1400 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1401 attr->local_pref = bgp->default_local_pref;
1402 }
1403
1404 /* If originator-id is not set and the route is to be reflected,
1405 set the originator id */
1406 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1407 {
1408 attr->extra = bgp_attr_extra_get(attr);
1409 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1410 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1411 }
1412
1413 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1414 if (peer->sort == BGP_PEER_EBGP
1415 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1416 {
1417 if (from != bgp->peer_self && ! transparent
1418 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1419 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1420 }
1421
1422 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1423 * in announce check, only certain flags and length (or number of nexthops
1424 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1425 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1426 * Typically, the source nexthop in the attribute is preserved but in the
1427 * scenarios where we know it will always be overwritten, we reset the
1428 * nexthop to "0" in an attempt to achieve better Update packing. An
1429 * example of this is when a prefix from each of 2 IBGP peers needs to be
1430 * announced to an EBGP peer (and they have the same attributes barring
1431 * their nexthop).
1432 */
1433 if (reflect)
1434 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1435
1436 #ifdef HAVE_IPV6
1437 #define NEXTHOP_IS_V6 (\
1438 (safi != SAFI_ENCAP && safi != SAFI_MPLS_VPN &&\
1439 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1440 ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
1441 attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
1442
1443 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1444 * the peer (group) is configured to receive link-local nexthop unchanged
1445 * and it is available in the prefix OR we're not reflecting the route and
1446 * the peer (group) to whom we're going to announce is on a shared network
1447 * and this is either a self-originated route or the peer is EBGP.
1448 */
1449 if (NEXTHOP_IS_V6)
1450 {
1451 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1452 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1454 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1455 (!reflect && peer->shared_network &&
1456 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1457 {
1458 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1459 }
1460
1461 /* Clear off link-local nexthop in source, whenever it is not needed to
1462 * ensure more prefixes share the same attribute for announcement.
1463 */
1464 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1465 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1466 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1467 }
1468 #endif /* HAVE_IPV6 */
1469
1470 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1471 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1472
1473 /* Route map & unsuppress-map apply. */
1474 if (ROUTE_MAP_OUT_NAME (filter)
1475 || (ri->extra && ri->extra->suppress) )
1476 {
1477 struct bgp_info info;
1478 struct attr dummy_attr;
1479 struct attr_extra dummy_extra;
1480
1481 dummy_attr.extra = &dummy_extra;
1482
1483 info.peer = peer;
1484 info.attr = attr;
1485 /* don't confuse inbound and outbound setting */
1486 RESET_FLAG(attr->rmap_change_flags);
1487
1488 /*
1489 * The route reflector is not allowed to modify the attributes
1490 * of the reflected IBGP routes unless explicitly allowed.
1491 */
1492 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1493 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1494 {
1495 bgp_attr_dup (&dummy_attr, attr);
1496 info.attr = &dummy_attr;
1497 }
1498
1499 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1500
1501 if (ri->extra && ri->extra->suppress)
1502 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1503 else
1504 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1505
1506 peer->rmap_type = 0;
1507
1508 if (ret == RMAP_DENYMATCH)
1509 {
1510 bgp_attr_flush (attr);
1511 return 0;
1512 }
1513 }
1514
1515 /* After route-map has been applied, we check to see if the nexthop to
1516 * be carried in the attribute (that is used for the announcement) can
1517 * be cleared off or not. We do this in all cases where we would be
1518 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1519 * the global nexthop here; the link-local nexthop would have been cleared
1520 * already, and if not, it is required by the update formation code.
1521 * Also see earlier comments in this function.
1522 */
1523 /*
1524 * If route-map has performed some operation on the nexthop or the peer
1525 * configuration says to pass it unchanged, we cannot reset the nexthop
1526 * here, so only attempt to do it if these aren't true. Note that the
1527 * route-map handler itself might have cleared the nexthop, if for example,
1528 * it is configured as 'peer-address'.
1529 */
1530 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1531 riattr->rmap_change_flags) &&
1532 !transparent &&
1533 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1534 {
1535 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1537 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1538 {
1539 if (!reflect ||
1540 CHECK_FLAG (peer->af_flags[afi][safi],
1541 PEER_FLAG_FORCE_NEXTHOP_SELF))
1542 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1543 AF_INET6 : p->family), attr);
1544 }
1545 else if (peer->sort == BGP_PEER_EBGP)
1546 {
1547 /* Can also reset the nexthop if announcing to EBGP, but only if
1548 * no peer in the subgroup is on a shared subnet.
1549 * Note: 3rd party nexthop currently implemented for IPv4 only.
1550 */
1551 SUBGRP_FOREACH_PEER (subgrp, paf)
1552 {
1553 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1554 break;
1555 }
1556 if (!paf)
1557 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1558 }
1559 /* If IPv6/MP and nexthop does not have any override and happens to
1560 * be a link-local address, reset it so that we don't pass along the
1561 * source's link-local IPv6 address to recipients who may not be on
1562 * the same interface.
1563 */
1564 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1565 {
1566 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1567 subgroup_announce_reset_nhop (AF_INET6, attr);
1568 }
1569 }
1570
1571 return 1;
1572 }
1573
1574 struct bgp_info_pair
1575 {
1576 struct bgp_info *old;
1577 struct bgp_info *new;
1578 };
1579
1580 static void
1581 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1582 struct bgp_maxpaths_cfg *mpath_cfg,
1583 struct bgp_info_pair *result)
1584 {
1585 struct bgp_info *new_select;
1586 struct bgp_info *old_select;
1587 struct bgp_info *ri;
1588 struct bgp_info *ri1;
1589 struct bgp_info *ri2;
1590 struct bgp_info *nextri = NULL;
1591 int paths_eq, do_mpath, debug;
1592 struct list mp_list;
1593 char pfx_buf[PREFIX2STR_BUFFER];
1594 char path_buf[PATH_ADDPATH_STR_BUFFER];
1595
1596 bgp_mp_list_init (&mp_list);
1597 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1598
1599 debug = bgp_debug_bestpath(&rn->p);
1600
1601 if (debug)
1602 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1603
1604 /* bgp deterministic-med */
1605 new_select = NULL;
1606 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1607 {
1608
1609 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1610 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1611 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1612
1613 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1614 {
1615 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1616 continue;
1617 if (BGP_INFO_HOLDDOWN (ri1))
1618 continue;
1619 if (ri1->peer && ri1->peer != bgp->peer_self)
1620 if (ri1->peer->status != Established)
1621 continue;
1622
1623 new_select = ri1;
1624 if (ri1->next)
1625 {
1626 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1627 {
1628 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1629 continue;
1630 if (BGP_INFO_HOLDDOWN (ri2))
1631 continue;
1632 if (ri2->peer &&
1633 ri2->peer != bgp->peer_self &&
1634 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1635 if (ri2->peer->status != Established)
1636 continue;
1637
1638 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1639 || aspath_cmp_left_confed (ri1->attr->aspath,
1640 ri2->attr->aspath))
1641 {
1642 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1643 mpath_cfg, debug, pfx_buf))
1644 {
1645 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1646 new_select = ri2;
1647 }
1648
1649 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1650 }
1651 }
1652 }
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1654 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1655
1656 if (debug)
1657 {
1658 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1659 zlog_debug("%s: %s is the bestpath from AS %d",
1660 pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath));
1661 }
1662 }
1663 }
1664
1665 /* Check old selected route and new selected route. */
1666 old_select = NULL;
1667 new_select = NULL;
1668 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1669 {
1670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1671 old_select = ri;
1672
1673 if (BGP_INFO_HOLDDOWN (ri))
1674 {
1675 /* reap REMOVED routes, if needs be
1676 * selected route must stay for a while longer though
1677 */
1678 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1679 && (ri != old_select))
1680 bgp_info_reap (rn, ri);
1681
1682 continue;
1683 }
1684
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
1691 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1692 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1693 {
1694 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1695 continue;
1696 }
1697
1698 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1699
1700 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1701 {
1702 new_select = ri;
1703 }
1704 }
1705
1706 /* Now that we know which path is the bestpath see if any of the other paths
1707 * qualify as multipaths
1708 */
1709 if (debug)
1710 {
1711 if (new_select)
1712 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1713 else
1714 sprintf (path_buf, "NONE");
1715 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1716 pfx_buf, path_buf,
1717 old_select ? old_select->peer->host : "NONE");
1718 }
1719
1720 if (do_mpath && new_select)
1721 {
1722 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1723 {
1724
1725 if (debug)
1726 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1727
1728 if (ri == new_select)
1729 {
1730 if (debug)
1731 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1732 pfx_buf, path_buf);
1733 bgp_mp_list_add (&mp_list, ri);
1734 continue;
1735 }
1736
1737 if (BGP_INFO_HOLDDOWN (ri))
1738 continue;
1739
1740 if (ri->peer &&
1741 ri->peer != bgp->peer_self &&
1742 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1743 if (ri->peer->status != Established)
1744 continue;
1745
1746 if (!bgp_info_nexthop_cmp (ri, new_select))
1747 {
1748 if (debug)
1749 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1750 pfx_buf, path_buf);
1751 continue;
1752 }
1753
1754 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1755
1756 if (paths_eq)
1757 {
1758 if (debug)
1759 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1760 pfx_buf, path_buf);
1761 bgp_mp_list_add (&mp_list, ri);
1762 }
1763 }
1764 }
1765
1766 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1767 bgp_info_mpath_aggregate_update (new_select, old_select);
1768 bgp_mp_list_clear (&mp_list);
1769
1770 result->old = old_select;
1771 result->new = new_select;
1772
1773 return;
1774 }
1775
1776 /*
1777 * A new route/change in bestpath of an existing route. Evaluate the path
1778 * for advertisement to the subgroup.
1779 */
1780 int
1781 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1782 struct bgp_info *selected,
1783 struct bgp_node *rn,
1784 u_int32_t addpath_tx_id)
1785 {
1786 struct prefix *p;
1787 struct peer *onlypeer;
1788 struct attr attr;
1789 struct attr_extra extra;
1790 afi_t afi;
1791 safi_t safi;
1792
1793 p = &rn->p;
1794 afi = SUBGRP_AFI(subgrp);
1795 safi = SUBGRP_SAFI(subgrp);
1796 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1797 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1798
1799 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1800 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1801 PEER_STATUS_ORF_WAIT_REFRESH))
1802 return 0;
1803
1804 memset(&extra, 0, sizeof(struct attr_extra));
1805 /* It's initialized in bgp_announce_check() */
1806 attr.extra = &extra;
1807
1808 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1809 if (selected)
1810 {
1811 if (subgroup_announce_check(selected, subgrp, p, &attr))
1812 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1813 else
1814 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1815 }
1816
1817 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1818 else
1819 {
1820 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1821 }
1822
1823 return 0;
1824 }
1825
1826 /*
1827 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1828 * This is called at the end of route processing.
1829 */
1830 static void
1831 bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1832 {
1833 struct bgp_info *ri;
1834
1835 for (ri = rn->info; ri; ri = ri->next)
1836 {
1837 if (BGP_INFO_HOLDDOWN (ri))
1838 continue;
1839 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
1840 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1841 }
1842 }
1843
1844 /*
1845 * Has the route changed from the RIB's perspective? This is invoked only
1846 * if the route selection returns the same best route as earlier - to
1847 * determine if we need to update zebra or not.
1848 */
1849 static int
1850 bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1851 {
1852 struct bgp_info *mpinfo;
1853
1854 /* If this is multipath, check all selected paths for any nexthop change or
1855 * attribute change. Some attribute changes (e.g., community) aren't of
1856 * relevance to the RIB, but we'll update zebra to ensure we handle the
1857 * case of BGP nexthop change. This is the behavior when the best path has
1858 * an attribute change anyway.
1859 */
1860 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1861 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1862 return 1;
1863
1864 /* If this is multipath, check all selected paths for any nexthop change */
1865 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1866 mpinfo = bgp_info_mpath_next (mpinfo))
1867 {
1868 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1869 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
1870 return 1;
1871 }
1872
1873 /* Nothing has changed from the RIB's perspective. */
1874 return 0;
1875 }
1876
1877 struct bgp_process_queue
1878 {
1879 struct bgp *bgp;
1880 struct bgp_node *rn;
1881 afi_t afi;
1882 safi_t safi;
1883 };
1884
1885 static wq_item_status
1886 bgp_process_main (struct work_queue *wq, void *data)
1887 {
1888 struct bgp_process_queue *pq = data;
1889 struct bgp *bgp = pq->bgp;
1890 struct bgp_node *rn = pq->rn;
1891 afi_t afi = pq->afi;
1892 safi_t safi = pq->safi;
1893 struct prefix *p = &rn->p;
1894 struct bgp_info *new_select;
1895 struct bgp_info *old_select;
1896 struct bgp_info_pair old_and_new;
1897
1898 /* Is it end of initial update? (after startup) */
1899 if (!rn)
1900 {
1901 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1902 sizeof(bgp->update_delay_zebra_resume_time));
1903
1904 bgp->main_zebra_update_hold = 0;
1905 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1906 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1907 {
1908 bgp_zebra_announce_table(bgp, afi, safi);
1909 }
1910 bgp->main_peers_update_hold = 0;
1911
1912 bgp_start_routeadv(bgp);
1913 return WQ_SUCCESS;
1914 }
1915
1916 /* Best path selection. */
1917 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1918 old_select = old_and_new.old;
1919 new_select = old_and_new.new;
1920
1921 /* Nothing to do. */
1922 if (old_select && old_select == new_select &&
1923 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1924 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1925 !bgp->addpath_tx_used[afi][safi])
1926 {
1927 if (bgp_zebra_has_route_changed (rn, old_select))
1928 {
1929 #if ENABLE_BGP_VNC
1930 vnc_import_bgp_add_route(bgp, p, old_select);
1931 vnc_import_bgp_exterior_add_route(bgp, p, old_select);
1932 #endif
1933 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1934 }
1935 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1936 bgp_zebra_clear_route_change_flags (rn);
1937 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1938 return WQ_SUCCESS;
1939 }
1940
1941 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1942 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1943
1944 /* bestpath has changed; bump version */
1945 if (old_select || new_select)
1946 {
1947 bgp_bump_version(rn);
1948
1949 if (!bgp->t_rmap_def_originate_eval)
1950 {
1951 bgp_lock (bgp);
1952 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1953 update_group_refresh_default_originate_route_map,
1954 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1955 }
1956 }
1957
1958 if (old_select)
1959 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1960 if (new_select)
1961 {
1962 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1963 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1964 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1965 }
1966
1967 #if ENABLE_BGP_VNC
1968 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
1969 if (old_select != new_select) {
1970 if (old_select) {
1971 vnc_import_bgp_exterior_del_route(bgp, p, old_select);
1972 vnc_import_bgp_del_route(bgp, p, old_select);
1973 }
1974 if (new_select) {
1975 vnc_import_bgp_exterior_add_route(bgp, p, new_select);
1976 vnc_import_bgp_add_route(bgp, p, new_select);
1977 }
1978 }
1979 }
1980 #endif
1981
1982 group_announce_route(bgp, afi, safi, rn, new_select);
1983
1984 /* FIB update. */
1985 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1986 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1987 !bgp_option_check (BGP_OPT_NO_FIB))
1988 {
1989 if (new_select
1990 && new_select->type == ZEBRA_ROUTE_BGP
1991 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1992 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1993 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1994 else
1995 {
1996 /* Withdraw the route from the kernel. */
1997 if (old_select
1998 && old_select->type == ZEBRA_ROUTE_BGP
1999 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2000 old_select->sub_type == BGP_ROUTE_AGGREGATE))
2001 bgp_zebra_withdraw (p, old_select, safi);
2002 }
2003 }
2004
2005 /* Clear any route change flags. */
2006 bgp_zebra_clear_route_change_flags (rn);
2007
2008 /* Reap old select bgp_info, if it has been removed */
2009 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2010 bgp_info_reap (rn, old_select);
2011
2012 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2013 return WQ_SUCCESS;
2014 }
2015
2016 static void
2017 bgp_processq_del (struct work_queue *wq, void *data)
2018 {
2019 struct bgp_process_queue *pq = data;
2020 struct bgp_table *table;
2021
2022 bgp_unlock (pq->bgp);
2023 if (pq->rn)
2024 {
2025 table = bgp_node_table (pq->rn);
2026 bgp_unlock_node (pq->rn);
2027 bgp_table_unlock (table);
2028 }
2029 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2030 }
2031
2032 void
2033 bgp_process_queue_init (void)
2034 {
2035 if (!bm->process_main_queue)
2036 {
2037 bm->process_main_queue
2038 = work_queue_new (bm->master, "process_main_queue");
2039
2040 if ( !bm->process_main_queue)
2041 {
2042 zlog_err ("%s: Failed to allocate work queue", __func__);
2043 exit (1);
2044 }
2045 }
2046
2047 bm->process_main_queue->spec.workfunc = &bgp_process_main;
2048 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
2049 bm->process_main_queue->spec.max_retries = 0;
2050 bm->process_main_queue->spec.hold = 50;
2051 /* Use a higher yield value of 50ms for main queue processing */
2052 bm->process_main_queue->spec.yield = 50 * 1000L;
2053 }
2054
2055 void
2056 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2057 {
2058 struct bgp_process_queue *pqnode;
2059
2060 /* already scheduled for processing? */
2061 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2062 return;
2063
2064 if (bm->process_main_queue == NULL)
2065 bgp_process_queue_init ();
2066
2067 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2068 sizeof (struct bgp_process_queue));
2069 if (!pqnode)
2070 return;
2071
2072 /* all unlocked in bgp_processq_del */
2073 bgp_table_lock (bgp_node_table (rn));
2074 pqnode->rn = bgp_lock_node (rn);
2075 pqnode->bgp = bgp;
2076 bgp_lock (bgp);
2077 pqnode->afi = afi;
2078 pqnode->safi = safi;
2079 work_queue_add (bm->process_main_queue, pqnode);
2080 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2081 return;
2082 }
2083
2084 void
2085 bgp_add_eoiu_mark (struct bgp *bgp)
2086 {
2087 struct bgp_process_queue *pqnode;
2088
2089 if (bm->process_main_queue == NULL)
2090 bgp_process_queue_init ();
2091
2092 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2093 sizeof (struct bgp_process_queue));
2094 if (!pqnode)
2095 return;
2096
2097 pqnode->rn = NULL;
2098 pqnode->bgp = bgp;
2099 bgp_lock (bgp);
2100 work_queue_add (bm->process_main_queue, pqnode);
2101 }
2102
2103 static int
2104 bgp_maximum_prefix_restart_timer (struct thread *thread)
2105 {
2106 struct peer *peer;
2107
2108 peer = THREAD_ARG (thread);
2109 peer->t_pmax_restart = NULL;
2110
2111 if (bgp_debug_neighbor_events(peer))
2112 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2113 peer->host);
2114
2115 peer_clear (peer, NULL);
2116
2117 return 0;
2118 }
2119
2120 int
2121 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2122 safi_t safi, int always)
2123 {
2124 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2125 return 0;
2126
2127 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
2128 {
2129 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2130 && ! always)
2131 return 0;
2132
2133 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2134 "limit %ld", afi_safi_print (afi, safi), peer->host,
2135 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2136 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2137
2138 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2139 return 0;
2140
2141 {
2142 u_int8_t ndata[7];
2143
2144 if (safi == SAFI_MPLS_VPN)
2145 safi = SAFI_MPLS_LABELED_VPN;
2146
2147 ndata[0] = (afi >> 8);
2148 ndata[1] = afi;
2149 ndata[2] = safi;
2150 ndata[3] = (peer->pmax[afi][safi] >> 24);
2151 ndata[4] = (peer->pmax[afi][safi] >> 16);
2152 ndata[5] = (peer->pmax[afi][safi] >> 8);
2153 ndata[6] = (peer->pmax[afi][safi]);
2154
2155 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2156 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2157 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2158 }
2159
2160 /* Dynamic peers will just close their connection. */
2161 if (peer_dynamic_neighbor (peer))
2162 return 1;
2163
2164 /* restart timer start */
2165 if (peer->pmax_restart[afi][safi])
2166 {
2167 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2168
2169 if (bgp_debug_neighbor_events(peer))
2170 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2171 peer->host, peer->v_pmax_restart);
2172
2173 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2174 peer->v_pmax_restart);
2175 }
2176
2177 return 1;
2178 }
2179 else
2180 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2181
2182 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2183 {
2184 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2185 && ! always)
2186 return 0;
2187
2188 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2189 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2190 peer->pmax[afi][safi]);
2191 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2192 }
2193 else
2194 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2195 return 0;
2196 }
2197
2198 /* Unconditionally remove the route from the RIB, without taking
2199 * damping into consideration (eg, because the session went down)
2200 */
2201 static void
2202 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2203 afi_t afi, safi_t safi)
2204 {
2205 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2206
2207 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2208 bgp_info_delete (rn, ri); /* keep historical info */
2209
2210 bgp_process (peer->bgp, rn, afi, safi);
2211 }
2212
2213 static void
2214 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2215 afi_t afi, safi_t safi, struct prefix_rd *prd)
2216 {
2217 int status = BGP_DAMP_NONE;
2218
2219 /* apply dampening, if result is suppressed, we'll be retaining
2220 * the bgp_info in the RIB for historical reference.
2221 */
2222 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2223 && peer->sort == BGP_PEER_EBGP)
2224 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2225 == BGP_DAMP_SUPPRESSED)
2226 {
2227 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2228 return;
2229 }
2230
2231 #if ENABLE_BGP_VNC
2232 if (safi == SAFI_MPLS_VPN) {
2233 struct bgp_node *prn = NULL;
2234 struct bgp_table *table = NULL;
2235
2236 prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd);
2237 if (prn->info) {
2238 table = (struct bgp_table *)(prn->info);
2239
2240 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2241 peer->bgp,
2242 prd,
2243 table,
2244 &rn->p,
2245 ri);
2246 }
2247 bgp_unlock_node(prn);
2248 }
2249 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2250 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2251
2252 vnc_import_bgp_del_route(peer->bgp, &rn->p, ri);
2253 vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri);
2254 }
2255 }
2256 #endif
2257 bgp_rib_remove (rn, ri, peer, afi, safi);
2258 }
2259
2260 static struct bgp_info *
2261 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2262 struct bgp_node *rn)
2263 {
2264 struct bgp_info *new;
2265
2266 /* Make new BGP info. */
2267 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2268 new->type = type;
2269 new->instance = instance;
2270 new->sub_type = sub_type;
2271 new->peer = peer;
2272 new->attr = attr;
2273 new->uptime = bgp_clock ();
2274 new->net = rn;
2275 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2276 return new;
2277 }
2278
2279 static void
2280 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2281 {
2282 if (addpath_id)
2283 sprintf(buf, " with addpath ID %d", addpath_id);
2284 }
2285
2286
2287 /* Check if received nexthop is valid or not. */
2288 static int
2289 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2290 {
2291 struct attr_extra *attre = attr->extra;
2292 int ret = 0;
2293
2294 /* Only validated for unicast and multicast currently. */
2295 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2296 return 0;
2297
2298 /* If NEXT_HOP is present, validate it. */
2299 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2300 {
2301 if (attr->nexthop.s_addr == 0 ||
2302 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2303 bgp_nexthop_self (bgp, attr))
2304 ret = 1;
2305 }
2306
2307 /* If MP_NEXTHOP is present, validate it. */
2308 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2309 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2310 * it is not an IPv6 link-local address.
2311 */
2312 if (attre && attre->mp_nexthop_len)
2313 {
2314 switch (attre->mp_nexthop_len)
2315 {
2316 case BGP_ATTR_NHLEN_IPV4:
2317 case BGP_ATTR_NHLEN_VPNV4:
2318 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2319 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2320 break;
2321
2322 #ifdef HAVE_IPV6
2323 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2324 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2325 case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
2326 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2327 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2328 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2329 break;
2330 #endif /* HAVE_IPV6 */
2331
2332 default:
2333 ret = 1;
2334 break;
2335 }
2336 }
2337
2338 return ret;
2339 }
2340
2341 int
2342 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2343 struct attr *attr, afi_t afi, safi_t safi, int type,
2344 int sub_type, struct prefix_rd *prd, u_char *tag,
2345 int soft_reconfig)
2346 {
2347 int ret;
2348 int aspath_loop_count = 0;
2349 struct bgp_node *rn;
2350 struct bgp *bgp;
2351 struct attr new_attr;
2352 struct attr_extra new_extra;
2353 struct attr *attr_new;
2354 struct bgp_info *ri;
2355 struct bgp_info *new;
2356 const char *reason;
2357 char buf[SU_ADDRSTRLEN];
2358 char buf2[30];
2359 int connected = 0;
2360 int do_loop_check = 1;
2361 #if ENABLE_BGP_VNC
2362 int vnc_implicit_withdraw = 0;
2363 #endif
2364
2365 memset (&new_attr, 0, sizeof(struct attr));
2366 memset (&new_extra, 0, sizeof(struct attr_extra));
2367
2368 bgp = peer->bgp;
2369 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2370
2371 /* When peer's soft reconfiguration enabled. Record input packet in
2372 Adj-RIBs-In. */
2373 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2374 && peer != bgp->peer_self)
2375 bgp_adj_in_set (rn, peer, attr, addpath_id);
2376
2377 /* Check previously received route. */
2378 for (ri = rn->info; ri; ri = ri->next)
2379 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2380 ri->addpath_rx_id == addpath_id)
2381 break;
2382
2383 /* AS path local-as loop check. */
2384 if (peer->change_local_as)
2385 {
2386 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2387 aspath_loop_count = 1;
2388
2389 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2390 {
2391 reason = "as-path contains our own AS;";
2392 goto filtered;
2393 }
2394 }
2395
2396 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2397 * as-path is our ASN then we do not need to call aspath_loop_check
2398 */
2399 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2400 if (aspath_get_last_as(attr->aspath) == bgp->as)
2401 do_loop_check = 0;
2402
2403 /* AS path loop check. */
2404 if (do_loop_check)
2405 {
2406 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2407 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2408 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2409 {
2410 reason = "as-path contains our own AS;";
2411 goto filtered;
2412 }
2413 }
2414
2415 /* Route reflector originator ID check. */
2416 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2417 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2418 {
2419 reason = "originator is us;";
2420 goto filtered;
2421 }
2422
2423 /* Route reflector cluster ID check. */
2424 if (bgp_cluster_filter (peer, attr))
2425 {
2426 reason = "reflected from the same cluster;";
2427 goto filtered;
2428 }
2429
2430 /* Apply incoming filter. */
2431 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2432 {
2433 reason = "filter;";
2434 goto filtered;
2435 }
2436
2437 new_attr.extra = &new_extra;
2438 bgp_attr_dup (&new_attr, attr);
2439
2440 /* Apply incoming route-map.
2441 * NB: new_attr may now contain newly allocated values from route-map "set"
2442 * commands, so we need bgp_attr_flush in the error paths, until we intern
2443 * the attr (which takes over the memory references) */
2444 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2445 {
2446 reason = "route-map;";
2447 bgp_attr_flush (&new_attr);
2448 goto filtered;
2449 }
2450
2451 /* next hop check. */
2452 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2453 {
2454 reason = "martian or self next-hop;";
2455 bgp_attr_flush (&new_attr);
2456 goto filtered;
2457 }
2458
2459 attr_new = bgp_attr_intern (&new_attr);
2460
2461 /* If the update is implicit withdraw. */
2462 if (ri)
2463 {
2464 ri->uptime = bgp_clock ();
2465
2466 /* Same attribute comes in. */
2467 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2468 && attrhash_cmp (ri->attr, attr_new))
2469 {
2470 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2471 && peer->sort == BGP_PEER_EBGP
2472 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2473 {
2474 if (bgp_debug_update(peer, p, NULL, 1))
2475 {
2476 bgp_info_addpath_rx_str(addpath_id, buf2);
2477 zlog_debug ("%s rcvd %s/%d%s",
2478 peer->host,
2479 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2480 p->prefixlen, buf2);
2481 }
2482
2483 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2484 {
2485 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2486 bgp_process (bgp, rn, afi, safi);
2487 }
2488 }
2489 else /* Duplicate - odd */
2490 {
2491 if (bgp_debug_update(peer, p, NULL, 1))
2492 {
2493 if (!peer->rcvd_attr_printed)
2494 {
2495 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2496 peer->rcvd_attr_printed = 1;
2497 }
2498
2499 bgp_info_addpath_rx_str(addpath_id, buf2);
2500 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2501 peer->host,
2502 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2503 p->prefixlen, buf2);
2504 }
2505
2506 /* graceful restart STALE flag unset. */
2507 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2508 {
2509 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2510 bgp_process (bgp, rn, afi, safi);
2511 }
2512 }
2513
2514 bgp_unlock_node (rn);
2515 bgp_attr_unintern (&attr_new);
2516
2517 return 0;
2518 }
2519
2520 /* Withdraw/Announce before we fully processed the withdraw */
2521 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2522 {
2523 if (bgp_debug_update(peer, p, NULL, 1))
2524 {
2525 bgp_info_addpath_rx_str(addpath_id, buf2);
2526 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2527 peer->host,
2528 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2529 p->prefixlen, buf2);
2530 }
2531 bgp_info_restore (rn, ri);
2532 }
2533
2534 /* Received Logging. */
2535 if (bgp_debug_update(peer, p, NULL, 1))
2536 {
2537 bgp_info_addpath_rx_str(addpath_id, buf2);
2538 zlog_debug ("%s rcvd %s/%d%s",
2539 peer->host,
2540 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2541 p->prefixlen, buf2);
2542 }
2543
2544 /* graceful restart STALE flag unset. */
2545 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2546 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2547
2548 /* The attribute is changed. */
2549 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2550
2551 /* implicit withdraw, decrement aggregate and pcount here.
2552 * only if update is accepted, they'll increment below.
2553 */
2554 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2555
2556 /* Update bgp route dampening information. */
2557 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2558 && peer->sort == BGP_PEER_EBGP)
2559 {
2560 /* This is implicit withdraw so we should update dampening
2561 information. */
2562 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2563 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2564 }
2565 #if ENABLE_BGP_VNC
2566 if (safi == SAFI_MPLS_VPN) {
2567 struct bgp_node *prn = NULL;
2568 struct bgp_table *table = NULL;
2569
2570 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2571 if (prn->info) {
2572 table = (struct bgp_table *)(prn->info);
2573
2574 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2575 bgp,
2576 prd,
2577 table,
2578 p,
2579 ri);
2580 }
2581 bgp_unlock_node(prn);
2582 }
2583 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2584 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2585 /*
2586 * Implicit withdraw case.
2587 */
2588 ++vnc_implicit_withdraw;
2589 vnc_import_bgp_del_route(bgp, p, ri);
2590 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2591 }
2592 }
2593 #endif
2594
2595 /* Update to new attribute. */
2596 bgp_attr_unintern (&ri->attr);
2597 ri->attr = attr_new;
2598
2599 /* Update MPLS tag. */
2600 if (safi == SAFI_MPLS_VPN)
2601 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2602
2603 #if ENABLE_BGP_VNC
2604 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2605 {
2606 if (vnc_implicit_withdraw)
2607 {
2608 /*
2609 * Add back the route with its new attributes (e.g., nexthop).
2610 * The route is still selected, until the route selection
2611 * queued by bgp_process actually runs. We have to make this
2612 * update to the VNC side immediately to avoid racing against
2613 * configuration changes (e.g., route-map changes) which
2614 * trigger re-importation of the entire RIB.
2615 */
2616 vnc_import_bgp_add_route(bgp, p, ri);
2617 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2618 }
2619 }
2620 #endif
2621
2622 /* Update bgp route dampening information. */
2623 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2624 && peer->sort == BGP_PEER_EBGP)
2625 {
2626 /* Now we do normal update dampening. */
2627 ret = bgp_damp_update (ri, rn, afi, safi);
2628 if (ret == BGP_DAMP_SUPPRESSED)
2629 {
2630 bgp_unlock_node (rn);
2631 return 0;
2632 }
2633 }
2634
2635 /* Nexthop reachability check. */
2636 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2637 {
2638 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2639 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2640 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2641 connected = 1;
2642 else
2643 connected = 0;
2644
2645 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2646 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2647 else
2648 {
2649 if (BGP_DEBUG(nht, NHT))
2650 {
2651 char buf1[INET6_ADDRSTRLEN];
2652 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2653 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2654 }
2655 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2656 }
2657 }
2658 else
2659 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2660
2661 #if ENABLE_BGP_VNC
2662 if (safi == SAFI_MPLS_VPN)
2663 {
2664 struct bgp_node *prn = NULL;
2665 struct bgp_table *table = NULL;
2666
2667 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2668 if (prn->info)
2669 {
2670 table = (struct bgp_table *)(prn->info);
2671
2672 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2673 bgp,
2674 prd,
2675 table,
2676 p,
2677 ri);
2678 }
2679 bgp_unlock_node(prn);
2680 }
2681 #endif
2682
2683 /* Process change. */
2684 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2685
2686 bgp_process (bgp, rn, afi, safi);
2687 bgp_unlock_node (rn);
2688
2689 #if ENABLE_BGP_VNC
2690 if (SAFI_MPLS_VPN == safi)
2691 {
2692 uint32_t label = decode_label(tag);
2693
2694 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2695 &label);
2696 }
2697 if (SAFI_ENCAP == safi)
2698 {
2699 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2700 NULL);
2701 }
2702 #endif
2703
2704 return 0;
2705 } // End of implicit withdraw
2706
2707 /* Received Logging. */
2708 if (bgp_debug_update(peer, p, NULL, 1))
2709 {
2710 if (!peer->rcvd_attr_printed)
2711 {
2712 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2713 peer->rcvd_attr_printed = 1;
2714 }
2715
2716 bgp_info_addpath_rx_str(addpath_id, buf2);
2717 zlog_debug ("%s rcvd %s/%d%s",
2718 peer->host,
2719 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2720 p->prefixlen, buf2);
2721 }
2722
2723 /* Make new BGP info. */
2724 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2725
2726 /* Update MPLS tag. */
2727 if (safi == SAFI_MPLS_VPN)
2728 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2729
2730 /* Nexthop reachability check. */
2731 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2732 {
2733 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2734 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2735 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2736 connected = 1;
2737 else
2738 connected = 0;
2739
2740 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2741 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2742 else
2743 {
2744 if (BGP_DEBUG(nht, NHT))
2745 {
2746 char buf1[INET6_ADDRSTRLEN];
2747 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2748 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2749 }
2750 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2751 }
2752 }
2753 else
2754 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2755
2756 /* Addpath ID */
2757 new->addpath_rx_id = addpath_id;
2758
2759 /* Increment prefix */
2760 bgp_aggregate_increment (bgp, p, new, afi, safi);
2761
2762 /* Register new BGP information. */
2763 bgp_info_add (rn, new);
2764
2765 /* route_node_get lock */
2766 bgp_unlock_node (rn);
2767
2768 #if ENABLE_BGP_VNC
2769 if (safi == SAFI_MPLS_VPN)
2770 {
2771 struct bgp_node *prn = NULL;
2772 struct bgp_table *table = NULL;
2773
2774 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2775 if (prn->info)
2776 {
2777 table = (struct bgp_table *)(prn->info);
2778
2779 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2780 bgp,
2781 prd,
2782 table,
2783 p,
2784 new);
2785 }
2786 bgp_unlock_node(prn);
2787 }
2788 #endif
2789
2790 /* If maximum prefix count is configured and current prefix
2791 count exeed it. */
2792 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2793 return -1;
2794
2795 /* Process change. */
2796 bgp_process (bgp, rn, afi, safi);
2797
2798 #if ENABLE_BGP_VNC
2799 if (SAFI_MPLS_VPN == safi)
2800 {
2801 uint32_t label = decode_label(tag);
2802
2803 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2804 &label);
2805 }
2806 if (SAFI_ENCAP == safi)
2807 {
2808 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2809 NULL);
2810 }
2811 #endif
2812
2813 return 0;
2814
2815 /* This BGP update is filtered. Log the reason then update BGP
2816 entry. */
2817 filtered:
2818 if (bgp_debug_update(peer, p, NULL, 1))
2819 {
2820 if (!peer->rcvd_attr_printed)
2821 {
2822 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2823 peer->rcvd_attr_printed = 1;
2824 }
2825
2826 bgp_info_addpath_rx_str(addpath_id, buf2);
2827 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2828 peer->host,
2829 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2830 p->prefixlen, buf2, reason);
2831 }
2832
2833 if (ri)
2834 bgp_rib_remove (rn, ri, peer, afi, safi);
2835
2836 bgp_unlock_node (rn);
2837
2838 #if ENABLE_BGP_VNC
2839 /*
2840 * Filtered update is treated as an implicit withdrawal (see bgp_rib_remove()
2841 * a few lines above)
2842 */
2843 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2844 {
2845 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2846 }
2847 #endif
2848
2849 return 0;
2850 }
2851
2852 int
2853 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2854 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2855 struct prefix_rd *prd, u_char *tag)
2856 {
2857 struct bgp *bgp;
2858 char buf[SU_ADDRSTRLEN];
2859 char buf2[30];
2860 struct bgp_node *rn;
2861 struct bgp_info *ri;
2862
2863 #if ENABLE_BGP_VNC
2864 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2865 {
2866 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2867 }
2868 #endif
2869
2870 bgp = peer->bgp;
2871
2872 /* Lookup node. */
2873 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2874
2875 /* If peer is soft reconfiguration enabled. Record input packet for
2876 * further calculation.
2877 *
2878 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2879 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2880 * the iteration over all RS clients.
2881 * Since we need to remove the entry from adj_in anyway, do that first and
2882 * if there was no entry, we don't need to do anything more.
2883 */
2884 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2885 && peer != bgp->peer_self)
2886 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2887 {
2888 if (bgp_debug_update (peer, p, NULL, 1))
2889 zlog_debug ("%s withdrawing route %s/%d "
2890 "not in adj-in", peer->host,
2891 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2892 p->prefixlen);
2893 bgp_unlock_node (rn);
2894 return 0;
2895 }
2896
2897 /* Lookup withdrawn route. */
2898 for (ri = rn->info; ri; ri = ri->next)
2899 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2900 ri->addpath_rx_id == addpath_id)
2901 break;
2902
2903 /* Logging. */
2904 if (bgp_debug_update(peer, p, NULL, 1))
2905 {
2906 bgp_info_addpath_rx_str(addpath_id, buf2);
2907 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2908 peer->host,
2909 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2910 p->prefixlen, buf2);
2911 }
2912
2913 /* Withdraw specified route from routing table. */
2914 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2915 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2916 else if (bgp_debug_update(peer, p, NULL, 1))
2917 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2918 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2919 p->prefixlen);
2920
2921 /* Unlock bgp_node_get() lock. */
2922 bgp_unlock_node (rn);
2923
2924 return 0;
2925 }
2926
2927 void
2928 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2929 {
2930 struct update_subgroup *subgrp;
2931 subgrp = peer_subgroup(peer, afi, safi);
2932 subgroup_default_originate(subgrp, withdraw);
2933 }
2934
2935
2936 /*
2937 * bgp_stop_announce_route_timer
2938 */
2939 void
2940 bgp_stop_announce_route_timer (struct peer_af *paf)
2941 {
2942 if (!paf->t_announce_route)
2943 return;
2944
2945 THREAD_TIMER_OFF (paf->t_announce_route);
2946 }
2947
2948 /*
2949 * bgp_announce_route_timer_expired
2950 *
2951 * Callback that is invoked when the route announcement timer for a
2952 * peer_af expires.
2953 */
2954 static int
2955 bgp_announce_route_timer_expired (struct thread *t)
2956 {
2957 struct peer_af *paf;
2958 struct peer *peer;
2959
2960 paf = THREAD_ARG (t);
2961 peer = paf->peer;
2962
2963 assert (paf->t_announce_route);
2964 paf->t_announce_route = NULL;
2965
2966 if (peer->status != Established)
2967 return 0;
2968
2969 if (!peer->afc_nego[paf->afi][paf->safi])
2970 return 0;
2971
2972 peer_af_announce_route (paf, 1);
2973 return 0;
2974 }
2975
2976 /*
2977 * bgp_announce_route
2978 *
2979 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2980 */
2981 void
2982 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2983 {
2984 struct peer_af *paf;
2985 struct update_subgroup *subgrp;
2986
2987 paf = peer_af_find (peer, afi, safi);
2988 if (!paf)
2989 return;
2990 subgrp = PAF_SUBGRP(paf);
2991
2992 /*
2993 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2994 * or a refresh has already been triggered.
2995 */
2996 if (!subgrp || paf->t_announce_route)
2997 return;
2998
2999 /*
3000 * Start a timer to stagger/delay the announce. This serves
3001 * two purposes - announcement can potentially be combined for
3002 * multiple peers and the announcement doesn't happen in the
3003 * vty context.
3004 */
3005 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3006 bgp_announce_route_timer_expired, paf,
3007 (subgrp->peer_count == 1) ?
3008 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3009 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3010 }
3011
3012 /*
3013 * Announce routes from all AF tables to a peer.
3014 *
3015 * This should ONLY be called when there is a need to refresh the
3016 * routes to the peer based on a policy change for this peer alone
3017 * or a route refresh request received from the peer.
3018 * The operation will result in splitting the peer from its existing
3019 * subgroups and putting it in new subgroups.
3020 */
3021 void
3022 bgp_announce_route_all (struct peer *peer)
3023 {
3024 afi_t afi;
3025 safi_t safi;
3026
3027 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3028 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3029 bgp_announce_route (peer, afi, safi);
3030 }
3031
3032 static void
3033 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
3034 struct bgp_table *table, struct prefix_rd *prd)
3035 {
3036 int ret;
3037 struct bgp_node *rn;
3038 struct bgp_adj_in *ain;
3039
3040 if (! table)
3041 table = peer->bgp->rib[afi][safi];
3042
3043 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3044 for (ain = rn->adj_in; ain; ain = ain->next)
3045 {
3046 if (ain->peer == peer)
3047 {
3048 struct bgp_info *ri = rn->info;
3049 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
3050
3051 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
3052 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
3053 prd, tag, 1);
3054
3055 if (ret < 0)
3056 {
3057 bgp_unlock_node (rn);
3058 return;
3059 }
3060 }
3061 }
3062 }
3063
3064 void
3065 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3066 {
3067 struct bgp_node *rn;
3068 struct bgp_table *table;
3069
3070 if (peer->status != Established)
3071 return;
3072
3073 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3074 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3075 else
3076 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3077 rn = bgp_route_next (rn))
3078 if ((table = rn->info) != NULL)
3079 {
3080 struct prefix_rd prd;
3081 prd.family = AF_UNSPEC;
3082 prd.prefixlen = 64;
3083 memcpy(&prd.val, rn->p.u.val, 8);
3084
3085 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3086 }
3087 }
3088
3089
3090 struct bgp_clear_node_queue
3091 {
3092 struct bgp_node *rn;
3093 };
3094
3095 static wq_item_status
3096 bgp_clear_route_node (struct work_queue *wq, void *data)
3097 {
3098 struct bgp_clear_node_queue *cnq = data;
3099 struct bgp_node *rn = cnq->rn;
3100 struct peer *peer = wq->spec.data;
3101 struct bgp_info *ri;
3102 afi_t afi = bgp_node_table (rn)->afi;
3103 safi_t safi = bgp_node_table (rn)->safi;
3104
3105 assert (rn && peer);
3106
3107 /* It is possible that we have multiple paths for a prefix from a peer
3108 * if that peer is using AddPath.
3109 */
3110 for (ri = rn->info; ri; ri = ri->next)
3111 if (ri->peer == peer)
3112 {
3113 /* graceful restart STALE flag set. */
3114 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3115 && peer->nsf[afi][safi]
3116 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3117 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3118 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3119 else
3120 bgp_rib_remove (rn, ri, peer, afi, safi);
3121 }
3122 return WQ_SUCCESS;
3123 }
3124
3125 static void
3126 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3127 {
3128 struct bgp_clear_node_queue *cnq = data;
3129 struct bgp_node *rn = cnq->rn;
3130 struct bgp_table *table = bgp_node_table (rn);
3131
3132 bgp_unlock_node (rn);
3133 bgp_table_unlock (table);
3134 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3135 }
3136
3137 static void
3138 bgp_clear_node_complete (struct work_queue *wq)
3139 {
3140 struct peer *peer = wq->spec.data;
3141
3142 /* Tickle FSM to start moving again */
3143 BGP_EVENT_ADD (peer, Clearing_Completed);
3144
3145 peer_unlock (peer); /* bgp_clear_route */
3146 }
3147
3148 static void
3149 bgp_clear_node_queue_init (struct peer *peer)
3150 {
3151 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3152
3153 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3154 #undef CLEAR_QUEUE_NAME_LEN
3155
3156 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3157 {
3158 zlog_err ("%s: Failed to allocate work queue", __func__);
3159 exit (1);
3160 }
3161 peer->clear_node_queue->spec.hold = 10;
3162 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3163 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3164 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3165 peer->clear_node_queue->spec.max_retries = 0;
3166
3167 /* we only 'lock' this peer reference when the queue is actually active */
3168 peer->clear_node_queue->spec.data = peer;
3169 }
3170
3171 static void
3172 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3173 struct bgp_table *table)
3174 {
3175 struct bgp_node *rn;
3176 int force = bm->process_main_queue ? 0 : 1;
3177
3178 if (! table)
3179 table = peer->bgp->rib[afi][safi];
3180
3181 /* If still no table => afi/safi isn't configured at all or smth. */
3182 if (! table)
3183 return;
3184
3185 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3186 {
3187 struct bgp_info *ri, *next;
3188 struct bgp_adj_in *ain;
3189 struct bgp_adj_in *ain_next;
3190
3191 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3192 * queued for every clearing peer, regardless of whether it is
3193 * relevant to the peer at hand.
3194 *
3195 * Overview: There are 3 different indices which need to be
3196 * scrubbed, potentially, when a peer is removed:
3197 *
3198 * 1 peer's routes visible via the RIB (ie accepted routes)
3199 * 2 peer's routes visible by the (optional) peer's adj-in index
3200 * 3 other routes visible by the peer's adj-out index
3201 *
3202 * 3 there is no hurry in scrubbing, once the struct peer is
3203 * removed from bgp->peer, we could just GC such deleted peer's
3204 * adj-outs at our leisure.
3205 *
3206 * 1 and 2 must be 'scrubbed' in some way, at least made
3207 * invisible via RIB index before peer session is allowed to be
3208 * brought back up. So one needs to know when such a 'search' is
3209 * complete.
3210 *
3211 * Ideally:
3212 *
3213 * - there'd be a single global queue or a single RIB walker
3214 * - rather than tracking which route_nodes still need to be
3215 * examined on a peer basis, we'd track which peers still
3216 * aren't cleared
3217 *
3218 * Given that our per-peer prefix-counts now should be reliable,
3219 * this may actually be achievable. It doesn't seem to be a huge
3220 * problem at this time,
3221 *
3222 * It is possible that we have multiple paths for a prefix from a peer
3223 * if that peer is using AddPath.
3224 */
3225 ain = rn->adj_in;
3226 while (ain)
3227 {
3228 ain_next = ain->next;
3229
3230 if (ain->peer == peer)
3231 {
3232 bgp_adj_in_remove (rn, ain);
3233 bgp_unlock_node (rn);
3234 }
3235
3236 ain = ain_next;
3237 }
3238
3239 for (ri = rn->info; ri; ri = next)
3240 {
3241 next = ri->next;
3242 if (ri->peer != peer)
3243 continue;
3244
3245 if (force)
3246 bgp_info_reap (rn, ri);
3247 else
3248 {
3249 struct bgp_clear_node_queue *cnq;
3250
3251 /* both unlocked in bgp_clear_node_queue_del */
3252 bgp_table_lock (bgp_node_table (rn));
3253 bgp_lock_node (rn);
3254 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3255 sizeof (struct bgp_clear_node_queue));
3256 cnq->rn = rn;
3257 work_queue_add (peer->clear_node_queue, cnq);
3258 break;
3259 }
3260 }
3261 }
3262 return;
3263 }
3264
3265 void
3266 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3267 {
3268 struct bgp_node *rn;
3269 struct bgp_table *table;
3270
3271 if (peer->clear_node_queue == NULL)
3272 bgp_clear_node_queue_init (peer);
3273
3274 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3275 * Idle until it receives a Clearing_Completed event. This protects
3276 * against peers which flap faster than we can we clear, which could
3277 * lead to:
3278 *
3279 * a) race with routes from the new session being installed before
3280 * clear_route_node visits the node (to delete the route of that
3281 * peer)
3282 * b) resource exhaustion, clear_route_node likely leads to an entry
3283 * on the process_main queue. Fast-flapping could cause that queue
3284 * to grow and grow.
3285 */
3286
3287 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3288 * the unlock will happen upon work-queue completion; other wise, the
3289 * unlock happens at the end of this function.
3290 */
3291 if (!peer->clear_node_queue->thread)
3292 peer_lock (peer);
3293
3294 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3295 bgp_clear_route_table (peer, afi, safi, NULL);
3296 else
3297 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3298 rn = bgp_route_next (rn))
3299 if ((table = rn->info) != NULL)
3300 bgp_clear_route_table (peer, afi, safi, table);
3301
3302 /* unlock if no nodes got added to the clear-node-queue. */
3303 if (!peer->clear_node_queue->thread)
3304 peer_unlock (peer);
3305
3306 }
3307
3308 void
3309 bgp_clear_route_all (struct peer *peer)
3310 {
3311 afi_t afi;
3312 safi_t safi;
3313
3314 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3315 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3316 bgp_clear_route (peer, afi, safi);
3317
3318 #if ENABLE_BGP_VNC
3319 rfapiProcessPeerDown(peer);
3320 #endif
3321 }
3322
3323 void
3324 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3325 {
3326 struct bgp_table *table;
3327 struct bgp_node *rn;
3328 struct bgp_adj_in *ain;
3329 struct bgp_adj_in *ain_next;
3330
3331 table = peer->bgp->rib[afi][safi];
3332
3333 /* It is possible that we have multiple paths for a prefix from a peer
3334 * if that peer is using AddPath.
3335 */
3336 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3337 {
3338 ain = rn->adj_in;
3339
3340 while (ain)
3341 {
3342 ain_next = ain->next;
3343
3344 if (ain->peer == peer)
3345 {
3346 bgp_adj_in_remove (rn, ain);
3347 bgp_unlock_node (rn);
3348 }
3349
3350 ain = ain_next;
3351 }
3352 }
3353 }
3354
3355 void
3356 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3357 {
3358 struct bgp_node *rn;
3359 struct bgp_info *ri;
3360 struct bgp_table *table;
3361
3362 table = peer->bgp->rib[afi][safi];
3363
3364 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3365 {
3366 for (ri = rn->info; ri; ri = ri->next)
3367 if (ri->peer == peer)
3368 {
3369 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3370 bgp_rib_remove (rn, ri, peer, afi, safi);
3371 break;
3372 }
3373 }
3374 }
3375
3376 static void
3377 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3378 {
3379 struct bgp_node *rn;
3380 struct bgp_info *ri;
3381 struct bgp_info *next;
3382
3383 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3384 for (ri = rn->info; ri; ri = next)
3385 {
3386 next = ri->next;
3387 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3388 && ri->type == ZEBRA_ROUTE_BGP
3389 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3390 ri->sub_type == BGP_ROUTE_AGGREGATE))
3391 {
3392 #if ENABLE_BGP_VNC
3393 if (table->owner && table->owner->bgp)
3394 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3395 #endif
3396 bgp_zebra_withdraw (&rn->p, ri, safi);
3397 bgp_info_reap (rn, ri);
3398 }
3399 }
3400 }
3401
3402 /* Delete all kernel routes. */
3403 void
3404 bgp_cleanup_routes (struct bgp *bgp)
3405 {
3406 afi_t afi;
3407
3408 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3409 {
3410 struct bgp_node *rn;
3411
3412 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3413
3414 /*
3415 * VPN and ENCAP tables are two-level (RD is top level)
3416 */
3417 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3418 rn = bgp_route_next (rn))
3419 {
3420 if (rn->info)
3421 {
3422 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3423 bgp_table_finish ((struct bgp_table **)&(rn->info));
3424 rn->info = NULL;
3425 bgp_unlock_node(rn);
3426 }
3427 }
3428
3429 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3430 rn = bgp_route_next (rn))
3431 {
3432 if (rn->info)
3433 {
3434 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3435 bgp_table_finish ((struct bgp_table **)&(rn->info));
3436 rn->info = NULL;
3437 bgp_unlock_node(rn);
3438 }
3439 }
3440 }
3441 }
3442
3443 void
3444 bgp_reset (void)
3445 {
3446 vty_reset ();
3447 bgp_zclient_reset ();
3448 access_list_reset ();
3449 prefix_list_reset ();
3450 }
3451
3452 static int
3453 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3454 {
3455 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3456 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3457 }
3458
3459 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3460 value. */
3461 int
3462 bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3463 struct bgp_nlri *packet)
3464 {
3465 u_char *pnt;
3466 u_char *lim;
3467 struct prefix p;
3468 int psize;
3469 int ret;
3470 afi_t afi;
3471 safi_t safi;
3472 int addpath_encoded;
3473 u_int32_t addpath_id;
3474
3475 /* Check peer status. */
3476 if (peer->status != Established)
3477 return 0;
3478
3479 pnt = packet->nlri;
3480 lim = pnt + packet->length;
3481 afi = packet->afi;
3482 safi = packet->safi;
3483 addpath_id = 0;
3484 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3485
3486 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3487 syntactic validity. If the field is syntactically incorrect,
3488 then the Error Subcode is set to Invalid Network Field. */
3489 for (; pnt < lim; pnt += psize)
3490 {
3491 /* Clear prefix structure. */
3492 memset (&p, 0, sizeof (struct prefix));
3493
3494 if (addpath_encoded)
3495 {
3496
3497 /* When packet overflow occurs return immediately. */
3498 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3499 return -1;
3500
3501 addpath_id = ntohl(*((uint32_t*) pnt));
3502 pnt += BGP_ADDPATH_ID_LEN;
3503 }
3504
3505 /* Fetch prefix length. */
3506 p.prefixlen = *pnt++;
3507 /* afi/safi validity already verified by caller, bgp_update_receive */
3508 p.family = afi2family (afi);
3509
3510 /* Prefix length check. */
3511 if (p.prefixlen > prefix_blen (&p) * 8)
3512 {
3513 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3514 peer->host, p.prefixlen, packet->afi);
3515 return -1;
3516 }
3517
3518 /* Packet size overflow check. */
3519 psize = PSIZE (p.prefixlen);
3520
3521 /* When packet overflow occur return immediately. */
3522 if (pnt + psize > lim)
3523 {
3524 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3525 peer->host, p.prefixlen);
3526 return -1;
3527 }
3528
3529 /* Defensive coding, double-check the psize fits in a struct prefix */
3530 if (psize > (ssize_t) sizeof(p.u))
3531 {
3532 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3533 peer->host, p.prefixlen, sizeof(p.u));
3534 return -1;
3535 }
3536
3537 /* Fetch prefix from NLRI packet. */
3538 memcpy (&p.u.prefix, pnt, psize);
3539
3540 /* Check address. */
3541 if (afi == AFI_IP && safi == SAFI_UNICAST)
3542 {
3543 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3544 {
3545 /* From RFC4271 Section 6.3:
3546 *
3547 * If a prefix in the NLRI field is semantically incorrect
3548 * (e.g., an unexpected multicast IP address), an error SHOULD
3549 * be logged locally, and the prefix SHOULD be ignored.
3550 */
3551 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3552 peer->host, inet_ntoa (p.u.prefix4));
3553 continue;
3554 }
3555 }
3556
3557 #ifdef HAVE_IPV6
3558 /* Check address. */
3559 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3560 {
3561 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3562 {
3563 char buf[BUFSIZ];
3564
3565 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3566 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3567
3568 continue;
3569 }
3570 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3571 {
3572 char buf[BUFSIZ];
3573
3574 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3575 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3576
3577 continue;
3578 }
3579 }
3580 #endif /* HAVE_IPV6 */
3581
3582 /* Normal process. */
3583 if (attr)
3584 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3585 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3586 else
3587 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3588 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3589
3590 /* Address family configuration mismatch or maximum-prefix count
3591 overflow. */
3592 if (ret < 0)
3593 return -1;
3594 }
3595
3596 /* Packet length consistency check. */
3597 if (pnt != lim)
3598 {
3599 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3600 peer->host);
3601 return -1;
3602 }
3603
3604 return 0;
3605 }
3606
3607 static struct bgp_static *
3608 bgp_static_new (void)
3609 {
3610 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3611 }
3612
3613 static void
3614 bgp_static_free (struct bgp_static *bgp_static)
3615 {
3616 if (bgp_static->rmap.name)
3617 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3618 XFREE (MTYPE_BGP_STATIC, bgp_static);
3619 }
3620
3621 static void
3622 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3623 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3624 {
3625 struct bgp_node *rn;
3626 struct bgp_info *ri;
3627 struct bgp_info *new;
3628 struct bgp_info info;
3629 struct attr attr;
3630 struct attr *attr_new;
3631 int ret;
3632 #if ENABLE_BGP_VNC
3633 int vnc_implicit_withdraw = 0;
3634 #endif
3635
3636 assert (bgp_static);
3637 if (!bgp_static)
3638 return;
3639
3640 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3641
3642 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3643
3644 attr.nexthop = bgp_static->igpnexthop;
3645 attr.med = bgp_static->igpmetric;
3646 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3647
3648 if (bgp_static->atomic)
3649 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3650
3651 /* Apply route-map. */
3652 if (bgp_static->rmap.name)
3653 {
3654 struct attr attr_tmp = attr;
3655 info.peer = bgp->peer_self;
3656 info.attr = &attr_tmp;
3657
3658 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3659
3660 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3661
3662 bgp->peer_self->rmap_type = 0;
3663
3664 if (ret == RMAP_DENYMATCH)
3665 {
3666 /* Free uninterned attribute. */
3667 bgp_attr_flush (&attr_tmp);
3668
3669 /* Unintern original. */
3670 aspath_unintern (&attr.aspath);
3671 bgp_attr_extra_free (&attr);
3672 bgp_static_withdraw (bgp, p, afi, safi);
3673 return;
3674 }
3675 attr_new = bgp_attr_intern (&attr_tmp);
3676 }
3677 else
3678 attr_new = bgp_attr_intern (&attr);
3679
3680 for (ri = rn->info; ri; ri = ri->next)
3681 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3682 && ri->sub_type == BGP_ROUTE_STATIC)
3683 break;
3684
3685 if (ri)
3686 {
3687 if (attrhash_cmp (ri->attr, attr_new) &&
3688 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3689 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3690 {
3691 bgp_unlock_node (rn);
3692 bgp_attr_unintern (&attr_new);
3693 aspath_unintern (&attr.aspath);
3694 bgp_attr_extra_free (&attr);
3695 return;
3696 }
3697 else
3698 {
3699 /* The attribute is changed. */
3700 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3701
3702 /* Rewrite BGP route information. */
3703 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3704 bgp_info_restore(rn, ri);
3705 else
3706 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3707 #if ENABLE_BGP_VNC
3708 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3709 {
3710 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3711 {
3712 /*
3713 * Implicit withdraw case.
3714 * We have to do this before ri is changed
3715 */
3716 ++vnc_implicit_withdraw;
3717 vnc_import_bgp_del_route(bgp, p, ri);
3718 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3719 }
3720 }
3721 #endif
3722 bgp_attr_unintern (&ri->attr);
3723 ri->attr = attr_new;
3724 ri->uptime = bgp_clock ();
3725 #if ENABLE_BGP_VNC
3726 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3727 {
3728 if (vnc_implicit_withdraw)
3729 {
3730 vnc_import_bgp_add_route(bgp, p, ri);
3731 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3732 }
3733 }
3734 #endif
3735
3736 /* Nexthop reachability check. */
3737 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3738 {
3739 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3740 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3741 else
3742 {
3743 if (BGP_DEBUG(nht, NHT))
3744 {
3745 char buf1[INET6_ADDRSTRLEN];
3746 inet_ntop(p->family, &p->u.prefix, buf1,
3747 INET6_ADDRSTRLEN);
3748 zlog_debug("%s(%s): Route not in table, not advertising",
3749 __FUNCTION__, buf1);
3750 }
3751 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3752 }
3753 }
3754 else
3755 {
3756 /* Delete the NHT structure if any, if we're toggling between
3757 * enabling/disabling import check. We deregister the route
3758 * from NHT to avoid overloading NHT and the process interaction
3759 */
3760 bgp_unlink_nexthop(ri);
3761 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3762 }
3763 /* Process change. */
3764 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3765 bgp_process (bgp, rn, afi, safi);
3766 bgp_unlock_node (rn);
3767 aspath_unintern (&attr.aspath);
3768 bgp_attr_extra_free (&attr);
3769 return;
3770 }
3771 }
3772
3773 /* Make new BGP info. */
3774 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3775 rn);
3776 /* Nexthop reachability check. */
3777 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3778 {
3779 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3780 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3781 else
3782 {
3783 if (BGP_DEBUG(nht, NHT))
3784 {
3785 char buf1[INET6_ADDRSTRLEN];
3786 inet_ntop(p->family, &p->u.prefix, buf1,
3787 INET6_ADDRSTRLEN);
3788 zlog_debug("%s(%s): Route not in table, not advertising",
3789 __FUNCTION__, buf1);
3790 }
3791 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3792 }
3793 }
3794 else
3795 {
3796 /* Delete the NHT structure if any, if we're toggling between
3797 * enabling/disabling import check. We deregister the route
3798 * from NHT to avoid overloading NHT and the process interaction
3799 */
3800 bgp_unlink_nexthop(new);
3801
3802 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3803 }
3804
3805 /* Aggregate address increment. */
3806 bgp_aggregate_increment (bgp, p, new, afi, safi);
3807
3808 /* Register new BGP information. */
3809 bgp_info_add (rn, new);
3810
3811 /* route_node_get lock */
3812 bgp_unlock_node (rn);
3813
3814 /* Process change. */
3815 bgp_process (bgp, rn, afi, safi);
3816
3817 /* Unintern original. */
3818 aspath_unintern (&attr.aspath);
3819 bgp_attr_extra_free (&attr);
3820 }
3821
3822 void
3823 bgp_static_update (struct bgp *bgp, struct prefix *p,
3824 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3825 {
3826 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3827 }
3828
3829 void
3830 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3831 safi_t safi)
3832 {
3833 struct bgp_node *rn;
3834 struct bgp_info *ri;
3835
3836 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3837
3838 /* Check selected route and self inserted route. */
3839 for (ri = rn->info; ri; ri = ri->next)
3840 if (ri->peer == bgp->peer_self
3841 && ri->type == ZEBRA_ROUTE_BGP
3842 && ri->sub_type == BGP_ROUTE_STATIC)
3843 break;
3844
3845 /* Withdraw static BGP route from routing table. */
3846 if (ri)
3847 {
3848 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3849 bgp_unlink_nexthop(ri);
3850 bgp_info_delete (rn, ri);
3851 bgp_process (bgp, rn, afi, safi);
3852 }
3853
3854 /* Unlock bgp_node_lookup. */
3855 bgp_unlock_node (rn);
3856 }
3857
3858 /*
3859 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3860 */
3861 static void
3862 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3863 safi_t safi, struct prefix_rd *prd, u_char *tag)
3864 {
3865 struct bgp_node *rn;
3866 struct bgp_info *ri;
3867
3868 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3869
3870 /* Check selected route and self inserted route. */
3871 for (ri = rn->info; ri; ri = ri->next)
3872 if (ri->peer == bgp->peer_self
3873 && ri->type == ZEBRA_ROUTE_BGP
3874 && ri->sub_type == BGP_ROUTE_STATIC)
3875 break;
3876
3877 /* Withdraw static BGP route from routing table. */
3878 if (ri)
3879 {
3880 #if ENABLE_BGP_VNC
3881 rfapiProcessWithdraw(
3882 ri->peer,
3883 NULL,
3884 p,
3885 prd,
3886 ri->attr,
3887 afi,
3888 safi,
3889 ri->type,
3890 1); /* Kill, since it is an administrative change */
3891 #endif
3892 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3893 bgp_info_delete (rn, ri);
3894 bgp_process (bgp, rn, afi, safi);
3895 }
3896
3897 /* Unlock bgp_node_lookup. */
3898 bgp_unlock_node (rn);
3899 }
3900
3901 static void
3902 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3903 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3904 {
3905 struct bgp_node *rn;
3906 struct bgp_info *new;
3907 struct attr *attr_new;
3908 struct attr attr = { 0 };
3909 struct bgp_info *ri;
3910 #if ENABLE_BGP_VNC
3911 u_int32_t label = 0;
3912 #endif
3913
3914 assert (bgp_static);
3915
3916 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3917
3918 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3919
3920 attr.nexthop = bgp_static->igpnexthop;
3921 attr.med = bgp_static->igpmetric;
3922 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3923
3924 /* Apply route-map. */
3925 if (bgp_static->rmap.name)
3926 {
3927 struct attr attr_tmp = attr;
3928 struct bgp_info info;
3929 int ret;
3930
3931 info.peer = bgp->peer_self;
3932 info.attr = &attr_tmp;
3933
3934 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3935
3936 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3937
3938 bgp->peer_self->rmap_type = 0;
3939
3940 if (ret == RMAP_DENYMATCH)
3941 {
3942 /* Free uninterned attribute. */
3943 bgp_attr_flush (&attr_tmp);
3944
3945 /* Unintern original. */
3946 aspath_unintern (&attr.aspath);
3947 bgp_attr_extra_free (&attr);
3948 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3949 bgp_static->tag);
3950 return;
3951 }
3952
3953 attr_new = bgp_attr_intern (&attr_tmp);
3954 }
3955 else
3956 {
3957 attr_new = bgp_attr_intern (&attr);
3958 }
3959
3960 for (ri = rn->info; ri; ri = ri->next)
3961 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3962 && ri->sub_type == BGP_ROUTE_STATIC)
3963 break;
3964
3965 if (ri)
3966 {
3967 if (attrhash_cmp (ri->attr, attr_new) &&
3968 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3969 {
3970 bgp_unlock_node (rn);
3971 bgp_attr_unintern (&attr_new);
3972 aspath_unintern (&attr.aspath);
3973 bgp_attr_extra_free (&attr);
3974 return;
3975 }
3976 else
3977 {
3978 /* The attribute is changed. */
3979 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3980
3981 /* Rewrite BGP route information. */
3982 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3983 bgp_info_restore(rn, ri);
3984 else
3985 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3986 bgp_attr_unintern (&ri->attr);
3987 ri->attr = attr_new;
3988 ri->uptime = bgp_clock ();
3989 #if ENABLE_BGP_VNC
3990 if (ri->extra)
3991 label = decode_label (ri->extra->tag);
3992 #endif
3993
3994 /* Process change. */
3995 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3996 bgp_process (bgp, rn, afi, safi);
3997 #if ENABLE_BGP_VNC
3998 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
3999 ri->attr, afi, safi,
4000 ri->type, ri->sub_type, &label);
4001 #endif
4002 bgp_unlock_node (rn);
4003 aspath_unintern (&attr.aspath);
4004 bgp_attr_extra_free (&attr);
4005 return;
4006 }
4007 }
4008
4009
4010 /* Make new BGP info. */
4011 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4012 rn);
4013 SET_FLAG (new->flags, BGP_INFO_VALID);
4014 new->extra = bgp_info_extra_new();
4015 memcpy (new->extra->tag, bgp_static->tag, 3);
4016 #if ENABLE_BGP_VNC
4017 label = decode_label (bgp_static->tag);
4018 #endif
4019
4020 /* Aggregate address increment. */
4021 bgp_aggregate_increment (bgp, p, new, afi, safi);
4022
4023 /* Register new BGP information. */
4024 bgp_info_add (rn, new);
4025
4026 /* route_node_get lock */
4027 bgp_unlock_node (rn);
4028
4029 /* Process change. */
4030 bgp_process (bgp, rn, afi, safi);
4031
4032 #if ENABLE_BGP_VNC
4033 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4034 new->attr, afi, safi,
4035 new->type, new->sub_type, &label);
4036 #endif
4037
4038 /* Unintern original. */
4039 aspath_unintern (&attr.aspath);
4040 bgp_attr_extra_free (&attr);
4041 }
4042
4043 /* Configure static BGP network. When user don't run zebra, static
4044 route should be installed as valid. */
4045 static int
4046 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4047 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4048 {
4049 int ret;
4050 struct prefix p;
4051 struct bgp_static *bgp_static;
4052 struct bgp_node *rn;
4053 u_char need_update = 0;
4054
4055 /* Convert IP prefix string to struct prefix. */
4056 ret = str2prefix (ip_str, &p);
4057 if (! ret)
4058 {
4059 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4060 return CMD_WARNING;
4061 }
4062 #ifdef HAVE_IPV6
4063 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4064 {
4065 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4066 VTY_NEWLINE);
4067 return CMD_WARNING;
4068 }
4069 #endif /* HAVE_IPV6 */
4070
4071 apply_mask (&p);
4072
4073 /* Set BGP static route configuration. */
4074 rn = bgp_node_get (bgp->route[afi][safi], &p);
4075
4076 if (rn->info)
4077 {
4078 /* Configuration change. */
4079 bgp_static = rn->info;
4080
4081 /* Check previous routes are installed into BGP. */
4082 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4083 need_update = 1;
4084
4085 bgp_static->backdoor = backdoor;
4086
4087 if (rmap)
4088 {
4089 if (bgp_static->rmap.name)
4090 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4091 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4092 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4093 }
4094 else
4095 {
4096 if (bgp_static->rmap.name)
4097 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4098 bgp_static->rmap.name = NULL;
4099 bgp_static->rmap.map = NULL;
4100 bgp_static->valid = 0;
4101 }
4102 bgp_unlock_node (rn);
4103 }
4104 else
4105 {
4106 /* New configuration. */
4107 bgp_static = bgp_static_new ();
4108 bgp_static->backdoor = backdoor;
4109 bgp_static->valid = 0;
4110 bgp_static->igpmetric = 0;
4111 bgp_static->igpnexthop.s_addr = 0;
4112
4113 if (rmap)
4114 {
4115 if (bgp_static->rmap.name)
4116 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4117 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4118 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4119 }
4120 rn->info = bgp_static;
4121 }
4122
4123 bgp_static->valid = 1;
4124 if (need_update)
4125 bgp_static_withdraw (bgp, &p, afi, safi);
4126
4127 if (! bgp_static->backdoor)
4128 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4129
4130 return CMD_SUCCESS;
4131 }
4132
4133 /* Configure static BGP network. */
4134 static int
4135 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4136 afi_t afi, safi_t safi)
4137 {
4138 int ret;
4139 struct prefix p;
4140 struct bgp_static *bgp_static;
4141 struct bgp_node *rn;
4142
4143 /* Convert IP prefix string to struct prefix. */
4144 ret = str2prefix (ip_str, &p);
4145 if (! ret)
4146 {
4147 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4148 return CMD_WARNING;
4149 }
4150 #ifdef HAVE_IPV6
4151 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4152 {
4153 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4154 VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157 #endif /* HAVE_IPV6 */
4158
4159 apply_mask (&p);
4160
4161 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4162 if (! rn)
4163 {
4164 vty_out (vty, "%% Can't find specified static route configuration.%s",
4165 VTY_NEWLINE);
4166 return CMD_WARNING;
4167 }
4168
4169 bgp_static = rn->info;
4170
4171 /* Update BGP RIB. */
4172 if (! bgp_static->backdoor)
4173 bgp_static_withdraw (bgp, &p, afi, safi);
4174
4175 /* Clear configuration. */
4176 bgp_static_free (bgp_static);
4177 rn->info = NULL;
4178 bgp_unlock_node (rn);
4179 bgp_unlock_node (rn);
4180
4181 return CMD_SUCCESS;
4182 }
4183
4184 void
4185 bgp_static_add (struct bgp *bgp)
4186 {
4187 afi_t afi;
4188 safi_t safi;
4189 struct bgp_node *rn;
4190 struct bgp_node *rm;
4191 struct bgp_table *table;
4192 struct bgp_static *bgp_static;
4193
4194 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4195 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4196 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4197 if (rn->info != NULL)
4198 {
4199 if (safi == SAFI_MPLS_VPN)
4200 {
4201 table = rn->info;
4202
4203 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4204 {
4205 bgp_static = rn->info;
4206 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4207 }
4208 }
4209 else
4210 {
4211 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4212 }
4213 }
4214 }
4215
4216 /* Called from bgp_delete(). Delete all static routes from the BGP
4217 instance. */
4218 void
4219 bgp_static_delete (struct bgp *bgp)
4220 {
4221 afi_t afi;
4222 safi_t safi;
4223 struct bgp_node *rn;
4224 struct bgp_node *rm;
4225 struct bgp_table *table;
4226 struct bgp_static *bgp_static;
4227
4228 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4229 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4230 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4231 if (rn->info != NULL)
4232 {
4233 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4234 {
4235 table = rn->info;
4236
4237 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4238 {
4239 bgp_static = rn->info;
4240 bgp_static_withdraw_safi (bgp, &rm->p,
4241 AFI_IP, safi,
4242 (struct prefix_rd *)&rn->p,
4243 bgp_static->tag);
4244 bgp_static_free (bgp_static);
4245 rn->info = NULL;
4246 bgp_unlock_node (rn);
4247 }
4248 }
4249 else
4250 {
4251 bgp_static = rn->info;
4252 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4253 bgp_static_free (bgp_static);
4254 rn->info = NULL;
4255 bgp_unlock_node (rn);
4256 }
4257 }
4258 }
4259
4260 void
4261 bgp_static_redo_import_check (struct bgp *bgp)
4262 {
4263 afi_t afi;
4264 safi_t safi;
4265 struct bgp_node *rn;
4266 struct bgp_static *bgp_static;
4267
4268 /* Use this flag to force reprocessing of the route */
4269 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4270 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4271 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4272 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4273 if (rn->info != NULL)
4274 {
4275 bgp_static = rn->info;
4276 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4277 }
4278 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4279 }
4280
4281 static void
4282 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4283 {
4284 struct bgp_table *table;
4285 struct bgp_node *rn;
4286 struct bgp_info *ri;
4287
4288 table = bgp->rib[afi][safi];
4289 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4290 {
4291 for (ri = rn->info; ri; ri = ri->next)
4292 {
4293 if (ri->peer == bgp->peer_self &&
4294 ((ri->type == ZEBRA_ROUTE_BGP &&
4295 ri->sub_type == BGP_ROUTE_STATIC) ||
4296 (ri->type != ZEBRA_ROUTE_BGP &&
4297 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4298 {
4299 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4300 bgp_unlink_nexthop(ri);
4301 bgp_info_delete (rn, ri);
4302 bgp_process (bgp, rn, afi, safi);
4303 }
4304 }
4305 }
4306 }
4307
4308 /*
4309 * Purge all networks and redistributed routes from routing table.
4310 * Invoked upon the instance going down.
4311 */
4312 void
4313 bgp_purge_static_redist_routes (struct bgp *bgp)
4314 {
4315 afi_t afi;
4316 safi_t safi;
4317
4318 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4319 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4320 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4321 }
4322
4323 /*
4324 * gpz 110624
4325 * Currently this is used to set static routes for VPN and ENCAP.
4326 * I think it can probably be factored with bgp_static_set.
4327 */
4328 int
4329 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4330 const char *rd_str, const char *tag_str,
4331 const char *rmap_str)
4332 {
4333 int ret;
4334 struct prefix p;
4335 struct prefix_rd prd;
4336 struct bgp *bgp;
4337 struct bgp_node *prn;
4338 struct bgp_node *rn;
4339 struct bgp_table *table;
4340 struct bgp_static *bgp_static;
4341 u_char tag[3];
4342
4343 bgp = vty->index;
4344
4345 ret = str2prefix (ip_str, &p);
4346 if (! ret)
4347 {
4348 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4349 return CMD_WARNING;
4350 }
4351 apply_mask (&p);
4352
4353 ret = str2prefix_rd (rd_str, &prd);
4354 if (! ret)
4355 {
4356 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4357 return CMD_WARNING;
4358 }
4359
4360 ret = str2tag (tag_str, tag);
4361 if (! ret)
4362 {
4363 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4364 return CMD_WARNING;
4365 }
4366
4367 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4368 (struct prefix *)&prd);
4369 if (prn->info == NULL)
4370 prn->info = bgp_table_init (AFI_IP, safi);
4371 else
4372 bgp_unlock_node (prn);
4373 table = prn->info;
4374
4375 rn = bgp_node_get (table, &p);
4376
4377 if (rn->info)
4378 {
4379 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4380 bgp_unlock_node (rn);
4381 }
4382 else
4383 {
4384 /* New configuration. */
4385 bgp_static = bgp_static_new ();
4386 bgp_static->backdoor = 0;
4387 bgp_static->valid = 0;
4388 bgp_static->igpmetric = 0;
4389 bgp_static->igpnexthop.s_addr = 0;
4390 memcpy(bgp_static->tag, tag, 3);
4391 bgp_static->prd = prd;
4392
4393 if (rmap_str)
4394 {
4395 if (bgp_static->rmap.name)
4396 free (bgp_static->rmap.name);
4397 bgp_static->rmap.name = strdup (rmap_str);
4398 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4399 }
4400 rn->info = bgp_static;
4401
4402 bgp_static->valid = 1;
4403 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4404 }
4405
4406 return CMD_SUCCESS;
4407 }
4408
4409 /* Configure static BGP network. */
4410 int
4411 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4412 const char *rd_str, const char *tag_str)
4413 {
4414 int ret;
4415 struct bgp *bgp;
4416 struct prefix p;
4417 struct prefix_rd prd;
4418 struct bgp_node *prn;
4419 struct bgp_node *rn;
4420 struct bgp_table *table;
4421 struct bgp_static *bgp_static;
4422 u_char tag[3];
4423
4424 bgp = vty->index;
4425
4426 /* Convert IP prefix string to struct prefix. */
4427 ret = str2prefix (ip_str, &p);
4428 if (! ret)
4429 {
4430 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4431 return CMD_WARNING;
4432 }
4433 apply_mask (&p);
4434
4435 ret = str2prefix_rd (rd_str, &prd);
4436 if (! ret)
4437 {
4438 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4439 return CMD_WARNING;
4440 }
4441
4442 ret = str2tag (tag_str, tag);
4443 if (! ret)
4444 {
4445 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4446 return CMD_WARNING;
4447 }
4448
4449 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4450 (struct prefix *)&prd);
4451 if (prn->info == NULL)
4452 prn->info = bgp_table_init (AFI_IP, safi);
4453 else
4454 bgp_unlock_node (prn);
4455 table = prn->info;
4456
4457 rn = bgp_node_lookup (table, &p);
4458
4459 if (rn)
4460 {
4461 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4462
4463 bgp_static = rn->info;
4464 bgp_static_free (bgp_static);
4465 rn->info = NULL;
4466 bgp_unlock_node (rn);
4467 bgp_unlock_node (rn);
4468 }
4469 else
4470 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4471
4472 return CMD_SUCCESS;
4473 }
4474
4475 static int
4476 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4477 const char *rmap_name)
4478 {
4479 struct bgp_rmap *rmap;
4480
4481 rmap = &bgp->table_map[afi][safi];
4482 if (rmap_name)
4483 {
4484 if (rmap->name)
4485 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4486 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4487 rmap->map = route_map_lookup_by_name (rmap_name);
4488 }
4489 else
4490 {
4491 if (rmap->name)
4492 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4493 rmap->name = NULL;
4494 rmap->map = NULL;
4495 }
4496
4497 bgp_zebra_announce_table(bgp, afi, safi);
4498
4499 return CMD_SUCCESS;
4500 }
4501
4502 static int
4503 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4504 const char *rmap_name)
4505 {
4506 struct bgp_rmap *rmap;
4507
4508 rmap = &bgp->table_map[afi][safi];
4509 if (rmap->name)
4510 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4511 rmap->name = NULL;
4512 rmap->map = NULL;
4513
4514 bgp_zebra_announce_table(bgp, afi, safi);
4515
4516 return CMD_SUCCESS;
4517 }
4518
4519 int
4520 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4521 safi_t safi, int *write)
4522 {
4523 if (bgp->table_map[afi][safi].name)
4524 {
4525 bgp_config_write_family_header (vty, afi, safi, write);
4526 vty_out (vty, " table-map %s%s",
4527 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4528 }
4529
4530 return 0;
4531 }
4532
4533 DEFUN (bgp_table_map,
4534 bgp_table_map_cmd,
4535 "table-map WORD",
4536 "BGP table to RIB route download filter\n"
4537 "Name of the route map\n")
4538 {
4539 return bgp_table_map_set (vty, vty->index,
4540 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4541 }
4542 DEFUN (no_bgp_table_map,
4543 no_bgp_table_map_cmd,
4544 "no table-map WORD",
4545 "BGP table to RIB route download filter\n"
4546 "Name of the route map\n")
4547 {
4548 return bgp_table_map_unset (vty, vty->index,
4549 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4550 }
4551
4552 DEFUN (bgp_network,
4553 bgp_network_cmd,
4554 "network A.B.C.D/M",
4555 "Specify a network to announce via BGP\n"
4556 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4557 {
4558 return bgp_static_set (vty, vty->index, argv[0],
4559 AFI_IP, bgp_node_safi (vty), NULL, 0);
4560 }
4561
4562 DEFUN (bgp_network_route_map,
4563 bgp_network_route_map_cmd,
4564 "network A.B.C.D/M route-map WORD",
4565 "Specify a network to announce via BGP\n"
4566 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4567 "Route-map to modify the attributes\n"
4568 "Name of the route map\n")
4569 {
4570 return bgp_static_set (vty, vty->index, argv[0],
4571 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4572 }
4573
4574 DEFUN (bgp_network_backdoor,
4575 bgp_network_backdoor_cmd,
4576 "network A.B.C.D/M backdoor",
4577 "Specify a network to announce via BGP\n"
4578 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4579 "Specify a BGP backdoor route\n")
4580 {
4581 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4582 NULL, 1);
4583 }
4584
4585 DEFUN (bgp_network_mask,
4586 bgp_network_mask_cmd,
4587 "network A.B.C.D mask A.B.C.D",
4588 "Specify a network to announce via BGP\n"
4589 "Network number\n"
4590 "Network mask\n"
4591 "Network mask\n")
4592 {
4593 int ret;
4594 char prefix_str[BUFSIZ];
4595
4596 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4597 if (! ret)
4598 {
4599 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4600 return CMD_WARNING;
4601 }
4602
4603 return bgp_static_set (vty, vty->index, prefix_str,
4604 AFI_IP, bgp_node_safi (vty), NULL, 0);
4605 }
4606
4607 DEFUN (bgp_network_mask_route_map,
4608 bgp_network_mask_route_map_cmd,
4609 "network A.B.C.D mask A.B.C.D route-map WORD",
4610 "Specify a network to announce via BGP\n"
4611 "Network number\n"
4612 "Network mask\n"
4613 "Network mask\n"
4614 "Route-map to modify the attributes\n"
4615 "Name of the route map\n")
4616 {
4617 int ret;
4618 char prefix_str[BUFSIZ];
4619
4620 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4621 if (! ret)
4622 {
4623 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4624 return CMD_WARNING;
4625 }
4626
4627 return bgp_static_set (vty, vty->index, prefix_str,
4628 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4629 }
4630
4631 DEFUN (bgp_network_mask_backdoor,
4632 bgp_network_mask_backdoor_cmd,
4633 "network A.B.C.D mask A.B.C.D backdoor",
4634 "Specify a network to announce via BGP\n"
4635 "Network number\n"
4636 "Network mask\n"
4637 "Network mask\n"
4638 "Specify a BGP backdoor route\n")
4639 {
4640 int ret;
4641 char prefix_str[BUFSIZ];
4642
4643 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4644 if (! ret)
4645 {
4646 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4647 return CMD_WARNING;
4648 }
4649
4650 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4651 NULL, 1);
4652 }
4653
4654 DEFUN (bgp_network_mask_natural,
4655 bgp_network_mask_natural_cmd,
4656 "network A.B.C.D",
4657 "Specify a network to announce via BGP\n"
4658 "Network number\n")
4659 {
4660 int ret;
4661 char prefix_str[BUFSIZ];
4662
4663 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4664 if (! ret)
4665 {
4666 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4667 return CMD_WARNING;
4668 }
4669
4670 return bgp_static_set (vty, vty->index, prefix_str,
4671 AFI_IP, bgp_node_safi (vty), NULL, 0);
4672 }
4673
4674 DEFUN (bgp_network_mask_natural_route_map,
4675 bgp_network_mask_natural_route_map_cmd,
4676 "network A.B.C.D route-map WORD",
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "Route-map to modify the attributes\n"
4680 "Name of the route map\n")
4681 {
4682 int ret;
4683 char prefix_str[BUFSIZ];
4684
4685 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4686 if (! ret)
4687 {
4688 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4689 return CMD_WARNING;
4690 }
4691
4692 return bgp_static_set (vty, vty->index, prefix_str,
4693 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4694 }
4695
4696 DEFUN (bgp_network_mask_natural_backdoor,
4697 bgp_network_mask_natural_backdoor_cmd,
4698 "network A.B.C.D backdoor",
4699 "Specify a network to announce via BGP\n"
4700 "Network number\n"
4701 "Specify a BGP backdoor route\n")
4702 {
4703 int ret;
4704 char prefix_str[BUFSIZ];
4705
4706 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4707 if (! ret)
4708 {
4709 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4710 return CMD_WARNING;
4711 }
4712
4713 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4714 NULL, 1);
4715 }
4716
4717 DEFUN (no_bgp_network,
4718 no_bgp_network_cmd,
4719 "no network A.B.C.D/M",
4720 NO_STR
4721 "Specify a network to announce via BGP\n"
4722 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4723 {
4724 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4725 bgp_node_safi (vty));
4726 }
4727
4728 ALIAS (no_bgp_network,
4729 no_bgp_network_route_map_cmd,
4730 "no network A.B.C.D/M route-map WORD",
4731 NO_STR
4732 "Specify a network to announce via BGP\n"
4733 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4734 "Route-map to modify the attributes\n"
4735 "Name of the route map\n")
4736
4737 ALIAS (no_bgp_network,
4738 no_bgp_network_backdoor_cmd,
4739 "no network A.B.C.D/M backdoor",
4740 NO_STR
4741 "Specify a network to announce via BGP\n"
4742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4743 "Specify a BGP backdoor route\n")
4744
4745 DEFUN (no_bgp_network_mask,
4746 no_bgp_network_mask_cmd,
4747 "no network A.B.C.D mask A.B.C.D",
4748 NO_STR
4749 "Specify a network to announce via BGP\n"
4750 "Network number\n"
4751 "Network mask\n"
4752 "Network mask\n")
4753 {
4754 int ret;
4755 char prefix_str[BUFSIZ];
4756
4757 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4758 if (! ret)
4759 {
4760 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4761 return CMD_WARNING;
4762 }
4763
4764 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4765 bgp_node_safi (vty));
4766 }
4767
4768 ALIAS (no_bgp_network_mask,
4769 no_bgp_network_mask_route_map_cmd,
4770 "no network A.B.C.D mask A.B.C.D route-map WORD",
4771 NO_STR
4772 "Specify a network to announce via BGP\n"
4773 "Network number\n"
4774 "Network mask\n"
4775 "Network mask\n"
4776 "Route-map to modify the attributes\n"
4777 "Name of the route map\n")
4778
4779 ALIAS (no_bgp_network_mask,
4780 no_bgp_network_mask_backdoor_cmd,
4781 "no network A.B.C.D mask A.B.C.D backdoor",
4782 NO_STR
4783 "Specify a network to announce via BGP\n"
4784 "Network number\n"
4785 "Network mask\n"
4786 "Network mask\n"
4787 "Specify a BGP backdoor route\n")
4788
4789 DEFUN (no_bgp_network_mask_natural,
4790 no_bgp_network_mask_natural_cmd,
4791 "no network A.B.C.D",
4792 NO_STR
4793 "Specify a network to announce via BGP\n"
4794 "Network number\n")
4795 {
4796 int ret;
4797 char prefix_str[BUFSIZ];
4798
4799 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4800 if (! ret)
4801 {
4802 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4803 return CMD_WARNING;
4804 }
4805
4806 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4807 bgp_node_safi (vty));
4808 }
4809
4810 ALIAS (no_bgp_network_mask_natural,
4811 no_bgp_network_mask_natural_route_map_cmd,
4812 "no network A.B.C.D route-map WORD",
4813 NO_STR
4814 "Specify a network to announce via BGP\n"
4815 "Network number\n"
4816 "Route-map to modify the attributes\n"
4817 "Name of the route map\n")
4818
4819 ALIAS (no_bgp_network_mask_natural,
4820 no_bgp_network_mask_natural_backdoor_cmd,
4821 "no network A.B.C.D backdoor",
4822 NO_STR
4823 "Specify a network to announce via BGP\n"
4824 "Network number\n"
4825 "Specify a BGP backdoor route\n")
4826
4827 #ifdef HAVE_IPV6
4828 DEFUN (ipv6_bgp_network,
4829 ipv6_bgp_network_cmd,
4830 "network X:X::X:X/M",
4831 "Specify a network to announce via BGP\n"
4832 "IPv6 prefix <network>/<length>\n")
4833 {
4834 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4835 NULL, 0);
4836 }
4837
4838 DEFUN (ipv6_bgp_network_route_map,
4839 ipv6_bgp_network_route_map_cmd,
4840 "network X:X::X:X/M route-map WORD",
4841 "Specify a network to announce via BGP\n"
4842 "IPv6 prefix <network>/<length>\n"
4843 "Route-map to modify the attributes\n"
4844 "Name of the route map\n")
4845 {
4846 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4847 bgp_node_safi (vty), argv[1], 0);
4848 }
4849
4850 DEFUN (no_ipv6_bgp_network,
4851 no_ipv6_bgp_network_cmd,
4852 "no network X:X::X:X/M",
4853 NO_STR
4854 "Specify a network to announce via BGP\n"
4855 "IPv6 prefix <network>/<length>\n")
4856 {
4857 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4858 }
4859
4860 ALIAS (no_ipv6_bgp_network,
4861 no_ipv6_bgp_network_route_map_cmd,
4862 "no network X:X::X:X/M route-map WORD",
4863 NO_STR
4864 "Specify a network to announce via BGP\n"
4865 "IPv6 prefix <network>/<length>\n"
4866 "Route-map to modify the attributes\n"
4867 "Name of the route map\n")
4868
4869 ALIAS (ipv6_bgp_network,
4870 old_ipv6_bgp_network_cmd,
4871 "ipv6 bgp network X:X::X:X/M",
4872 IPV6_STR
4873 BGP_STR
4874 "Specify a network to announce via BGP\n"
4875 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4876
4877 ALIAS (no_ipv6_bgp_network,
4878 old_no_ipv6_bgp_network_cmd,
4879 "no ipv6 bgp network X:X::X:X/M",
4880 NO_STR
4881 IPV6_STR
4882 BGP_STR
4883 "Specify a network to announce via BGP\n"
4884 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4885 #endif /* HAVE_IPV6 */
4886
4887 /* Aggreagete address:
4888
4889 advertise-map Set condition to advertise attribute
4890 as-set Generate AS set path information
4891 attribute-map Set attributes of aggregate
4892 route-map Set parameters of aggregate
4893 summary-only Filter more specific routes from updates
4894 suppress-map Conditionally filter more specific routes from updates
4895 <cr>
4896 */
4897 struct bgp_aggregate
4898 {
4899 /* Summary-only flag. */
4900 u_char summary_only;
4901
4902 /* AS set generation. */
4903 u_char as_set;
4904
4905 /* Route-map for aggregated route. */
4906 struct route_map *map;
4907
4908 /* Suppress-count. */
4909 unsigned long count;
4910
4911 /* SAFI configuration. */
4912 safi_t safi;
4913 };
4914
4915 static struct bgp_aggregate *
4916 bgp_aggregate_new (void)
4917 {
4918 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4919 }
4920
4921 static void
4922 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4923 {
4924 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4925 }
4926
4927 /* Update an aggregate as routes are added/removed from the BGP table */
4928 static void
4929 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4930 afi_t afi, safi_t safi, struct bgp_info *del,
4931 struct bgp_aggregate *aggregate)
4932 {
4933 struct bgp_table *table;
4934 struct bgp_node *top;
4935 struct bgp_node *rn;
4936 u_char origin;
4937 struct aspath *aspath = NULL;
4938 struct aspath *asmerge = NULL;
4939 struct community *community = NULL;
4940 struct community *commerge = NULL;
4941 #if defined(AGGREGATE_NEXTHOP_CHECK)
4942 struct in_addr nexthop;
4943 u_int32_t med = 0;
4944 #endif
4945 struct bgp_info *ri;
4946 struct bgp_info *new;
4947 int first = 1;
4948 unsigned long match = 0;
4949 u_char atomic_aggregate = 0;
4950
4951 /* Record adding route's nexthop and med. */
4952 if (rinew)
4953 {
4954 #if defined(AGGREGATE_NEXTHOP_CHECK)
4955 nexthop = rinew->attr->nexthop;
4956 med = rinew->attr->med;
4957 #endif
4958 }
4959
4960 /* ORIGIN attribute: If at least one route among routes that are
4961 aggregated has ORIGIN with the value INCOMPLETE, then the
4962 aggregated route must have the ORIGIN attribute with the value
4963 INCOMPLETE. Otherwise, if at least one route among routes that
4964 are aggregated has ORIGIN with the value EGP, then the aggregated
4965 route must have the origin attribute with the value EGP. In all
4966 other case the value of the ORIGIN attribute of the aggregated
4967 route is INTERNAL. */
4968 origin = BGP_ORIGIN_IGP;
4969
4970 table = bgp->rib[afi][safi];
4971
4972 top = bgp_node_get (table, p);
4973 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4974 if (rn->p.prefixlen > p->prefixlen)
4975 {
4976 match = 0;
4977
4978 for (ri = rn->info; ri; ri = ri->next)
4979 {
4980 if (BGP_INFO_HOLDDOWN (ri))
4981 continue;
4982
4983 if (del && ri == del)
4984 continue;
4985
4986 if (! rinew && first)
4987 {
4988 #if defined(AGGREGATE_NEXTHOP_CHECK)
4989 nexthop = ri->attr->nexthop;
4990 med = ri->attr->med;
4991 #endif
4992 first = 0;
4993 }
4994
4995 #ifdef AGGREGATE_NEXTHOP_CHECK
4996 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4997 || ri->attr->med != med)
4998 {
4999 if (aspath)
5000 aspath_free (aspath);
5001 if (community)
5002 community_free (community);
5003 bgp_unlock_node (rn);
5004 bgp_unlock_node (top);
5005 return;
5006 }
5007 #endif /* AGGREGATE_NEXTHOP_CHECK */
5008
5009 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5010 atomic_aggregate = 1;
5011
5012 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5013 {
5014 if (aggregate->summary_only)
5015 {
5016 (bgp_info_extra_get (ri))->suppress++;
5017 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5018 match++;
5019 }
5020
5021 aggregate->count++;
5022
5023 if (origin < ri->attr->origin)
5024 origin = ri->attr->origin;
5025
5026 if (aggregate->as_set)
5027 {
5028 if (aspath)
5029 {
5030 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5031 aspath_free (aspath);
5032 aspath = asmerge;
5033 }
5034 else
5035 aspath = aspath_dup (ri->attr->aspath);
5036
5037 if (ri->attr->community)
5038 {
5039 if (community)
5040 {
5041 commerge = community_merge (community,
5042 ri->attr->community);
5043 community = community_uniq_sort (commerge);
5044 community_free (commerge);
5045 }
5046 else
5047 community = community_dup (ri->attr->community);
5048 }
5049 }
5050 }
5051 }
5052 if (match)
5053 bgp_process (bgp, rn, afi, safi);
5054 }
5055 bgp_unlock_node (top);
5056
5057 if (rinew)
5058 {
5059 aggregate->count++;
5060
5061 if (aggregate->summary_only)
5062 (bgp_info_extra_get (rinew))->suppress++;
5063
5064 if (origin < rinew->attr->origin)
5065 origin = rinew->attr->origin;
5066
5067 if (aggregate->as_set)
5068 {
5069 if (aspath)
5070 {
5071 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5072 aspath_free (aspath);
5073 aspath = asmerge;
5074 }
5075 else
5076 aspath = aspath_dup (rinew->attr->aspath);
5077
5078 if (rinew->attr->community)
5079 {
5080 if (community)
5081 {
5082 commerge = community_merge (community,
5083 rinew->attr->community);
5084 community = community_uniq_sort (commerge);
5085 community_free (commerge);
5086 }
5087 else
5088 community = community_dup (rinew->attr->community);
5089 }
5090 }
5091 }
5092
5093 if (aggregate->count > 0)
5094 {
5095 rn = bgp_node_get (table, p);
5096 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5097 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5098 aggregate->as_set,
5099 atomic_aggregate), rn);
5100 SET_FLAG (new->flags, BGP_INFO_VALID);
5101
5102 bgp_info_add (rn, new);
5103 bgp_unlock_node (rn);
5104 bgp_process (bgp, rn, afi, safi);
5105 }
5106 else
5107 {
5108 if (aspath)
5109 aspath_free (aspath);
5110 if (community)
5111 community_free (community);
5112 }
5113 }
5114
5115 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5116 struct bgp_aggregate *);
5117
5118 void
5119 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5120 struct bgp_info *ri, afi_t afi, safi_t safi)
5121 {
5122 struct bgp_node *child;
5123 struct bgp_node *rn;
5124 struct bgp_aggregate *aggregate;
5125 struct bgp_table *table;
5126
5127 /* MPLS-VPN aggregation is not yet supported. */
5128 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5129 return;
5130
5131 table = bgp->aggregate[afi][safi];
5132
5133 /* No aggregates configured. */
5134 if (bgp_table_top_nolock (table) == NULL)
5135 return;
5136
5137 if (p->prefixlen == 0)
5138 return;
5139
5140 if (BGP_INFO_HOLDDOWN (ri))
5141 return;
5142
5143 child = bgp_node_get (table, p);
5144
5145 /* Aggregate address configuration check. */
5146 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5147 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5148 {
5149 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5150 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5151 }
5152 bgp_unlock_node (child);
5153 }
5154
5155 void
5156 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5157 struct bgp_info *del, afi_t afi, safi_t safi)
5158 {
5159 struct bgp_node *child;
5160 struct bgp_node *rn;
5161 struct bgp_aggregate *aggregate;
5162 struct bgp_table *table;
5163
5164 /* MPLS-VPN aggregation is not yet supported. */
5165 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5166 return;
5167
5168 table = bgp->aggregate[afi][safi];
5169
5170 /* No aggregates configured. */
5171 if (bgp_table_top_nolock (table) == NULL)
5172 return;
5173
5174 if (p->prefixlen == 0)
5175 return;
5176
5177 child = bgp_node_get (table, p);
5178
5179 /* Aggregate address configuration check. */
5180 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5181 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5182 {
5183 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5184 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5185 }
5186 bgp_unlock_node (child);
5187 }
5188
5189 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5190 static void
5191 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5192 struct bgp_aggregate *aggregate)
5193 {
5194 struct bgp_table *table;
5195 struct bgp_node *top;
5196 struct bgp_node *rn;
5197 struct bgp_info *new;
5198 struct bgp_info *ri;
5199 unsigned long match;
5200 u_char origin = BGP_ORIGIN_IGP;
5201 struct aspath *aspath = NULL;
5202 struct aspath *asmerge = NULL;
5203 struct community *community = NULL;
5204 struct community *commerge = NULL;
5205 u_char atomic_aggregate = 0;
5206
5207 table = bgp->rib[afi][safi];
5208
5209 /* Sanity check. */
5210 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5211 return;
5212 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5213 return;
5214
5215 /* If routes exists below this node, generate aggregate routes. */
5216 top = bgp_node_get (table, p);
5217 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5218 if (rn->p.prefixlen > p->prefixlen)
5219 {
5220 match = 0;
5221
5222 for (ri = rn->info; ri; ri = ri->next)
5223 {
5224 if (BGP_INFO_HOLDDOWN (ri))
5225 continue;
5226
5227 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5228 atomic_aggregate = 1;
5229
5230 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5231 {
5232 /* summary-only aggregate route suppress aggregated
5233 route announcement. */
5234 if (aggregate->summary_only)
5235 {
5236 (bgp_info_extra_get (ri))->suppress++;
5237 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5238 match++;
5239 }
5240
5241 /* If at least one route among routes that are aggregated has
5242 * ORIGIN with the value INCOMPLETE, then the aggregated route
5243 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5244 * Otherwise, if at least one route among routes that are
5245 * aggregated has ORIGIN with the value EGP, then the aggregated
5246 * route MUST have the ORIGIN attribute with the value EGP.
5247 */
5248 if (origin < ri->attr->origin)
5249 origin = ri->attr->origin;
5250
5251 /* as-set aggregate route generate origin, as path,
5252 community aggregation. */
5253 if (aggregate->as_set)
5254 {
5255 if (aspath)
5256 {
5257 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5258 aspath_free (aspath);
5259 aspath = asmerge;
5260 }
5261 else
5262 aspath = aspath_dup (ri->attr->aspath);
5263
5264 if (ri->attr->community)
5265 {
5266 if (community)
5267 {
5268 commerge = community_merge (community,
5269 ri->attr->community);
5270 community = community_uniq_sort (commerge);
5271 community_free (commerge);
5272 }
5273 else
5274 community = community_dup (ri->attr->community);
5275 }
5276 }
5277 aggregate->count++;
5278 }
5279 }
5280
5281 /* If this node is suppressed, process the change. */
5282 if (match)
5283 bgp_process (bgp, rn, afi, safi);
5284 }
5285 bgp_unlock_node (top);
5286
5287 /* Add aggregate route to BGP table. */
5288 if (aggregate->count)
5289 {
5290 rn = bgp_node_get (table, p);
5291 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5292 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5293 aggregate->as_set,
5294 atomic_aggregate), rn);
5295 SET_FLAG (new->flags, BGP_INFO_VALID);
5296
5297 bgp_info_add (rn, new);
5298 bgp_unlock_node (rn);
5299
5300 /* Process change. */
5301 bgp_process (bgp, rn, afi, safi);
5302 }
5303 else
5304 {
5305 if (aspath)
5306 aspath_free (aspath);
5307 if (community)
5308 community_free (community);
5309 }
5310 }
5311
5312 void
5313 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5314 safi_t safi, struct bgp_aggregate *aggregate)
5315 {
5316 struct bgp_table *table;
5317 struct bgp_node *top;
5318 struct bgp_node *rn;
5319 struct bgp_info *ri;
5320 unsigned long match;
5321
5322 table = bgp->rib[afi][safi];
5323
5324 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5325 return;
5326 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5327 return;
5328
5329 /* If routes exists below this node, generate aggregate routes. */
5330 top = bgp_node_get (table, p);
5331 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5332 if (rn->p.prefixlen > p->prefixlen)
5333 {
5334 match = 0;
5335
5336 for (ri = rn->info; ri; ri = ri->next)
5337 {
5338 if (BGP_INFO_HOLDDOWN (ri))
5339 continue;
5340
5341 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5342 {
5343 if (aggregate->summary_only && ri->extra)
5344 {
5345 ri->extra->suppress--;
5346
5347 if (ri->extra->suppress == 0)
5348 {
5349 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5350 match++;
5351 }
5352 }
5353 aggregate->count--;
5354 }
5355 }
5356
5357 /* If this node was suppressed, process the change. */
5358 if (match)
5359 bgp_process (bgp, rn, afi, safi);
5360 }
5361 bgp_unlock_node (top);
5362
5363 /* Delete aggregate route from BGP table. */
5364 rn = bgp_node_get (table, p);
5365
5366 for (ri = rn->info; ri; ri = ri->next)
5367 if (ri->peer == bgp->peer_self
5368 && ri->type == ZEBRA_ROUTE_BGP
5369 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5370 break;
5371
5372 /* Withdraw static BGP route from routing table. */
5373 if (ri)
5374 {
5375 bgp_info_delete (rn, ri);
5376 bgp_process (bgp, rn, afi, safi);
5377 }
5378
5379 /* Unlock bgp_node_lookup. */
5380 bgp_unlock_node (rn);
5381 }
5382
5383 /* Aggregate route attribute. */
5384 #define AGGREGATE_SUMMARY_ONLY 1
5385 #define AGGREGATE_AS_SET 1
5386
5387 static int
5388 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5389 afi_t afi, safi_t safi)
5390 {
5391 int ret;
5392 struct prefix p;
5393 struct bgp_node *rn;
5394 struct bgp *bgp;
5395 struct bgp_aggregate *aggregate;
5396
5397 /* Convert string to prefix structure. */
5398 ret = str2prefix (prefix_str, &p);
5399 if (!ret)
5400 {
5401 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5402 return CMD_WARNING;
5403 }
5404 apply_mask (&p);
5405
5406 /* Get BGP structure. */
5407 bgp = vty->index;
5408
5409 /* Old configuration check. */
5410 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5411 if (! rn)
5412 {
5413 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5414 VTY_NEWLINE);
5415 return CMD_WARNING;
5416 }
5417
5418 aggregate = rn->info;
5419 if (aggregate->safi & SAFI_UNICAST)
5420 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5421 if (aggregate->safi & SAFI_MULTICAST)
5422 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5423
5424 /* Unlock aggregate address configuration. */
5425 rn->info = NULL;
5426 bgp_aggregate_free (aggregate);
5427 bgp_unlock_node (rn);
5428 bgp_unlock_node (rn);
5429
5430 return CMD_SUCCESS;
5431 }
5432
5433 static int
5434 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5435 afi_t afi, safi_t safi,
5436 u_char summary_only, u_char as_set)
5437 {
5438 int ret;
5439 struct prefix p;
5440 struct bgp_node *rn;
5441 struct bgp *bgp;
5442 struct bgp_aggregate *aggregate;
5443
5444 /* Convert string to prefix structure. */
5445 ret = str2prefix (prefix_str, &p);
5446 if (!ret)
5447 {
5448 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5449 return CMD_WARNING;
5450 }
5451 apply_mask (&p);
5452
5453 /* Get BGP structure. */
5454 bgp = vty->index;
5455
5456 /* Old configuration check. */
5457 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5458
5459 if (rn->info)
5460 {
5461 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5462 /* try to remove the old entry */
5463 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5464 if (ret)
5465 {
5466 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5467 bgp_unlock_node (rn);
5468 return CMD_WARNING;
5469 }
5470 }
5471
5472 /* Make aggregate address structure. */
5473 aggregate = bgp_aggregate_new ();
5474 aggregate->summary_only = summary_only;
5475 aggregate->as_set = as_set;
5476 aggregate->safi = safi;
5477 rn->info = aggregate;
5478
5479 /* Aggregate address insert into BGP routing table. */
5480 if (safi & SAFI_UNICAST)
5481 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5482 if (safi & SAFI_MULTICAST)
5483 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5484
5485 return CMD_SUCCESS;
5486 }
5487
5488 DEFUN (aggregate_address,
5489 aggregate_address_cmd,
5490 "aggregate-address A.B.C.D/M",
5491 "Configure BGP aggregate entries\n"
5492 "Aggregate prefix\n")
5493 {
5494 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5495 }
5496
5497 DEFUN (aggregate_address_mask,
5498 aggregate_address_mask_cmd,
5499 "aggregate-address A.B.C.D A.B.C.D",
5500 "Configure BGP aggregate entries\n"
5501 "Aggregate address\n"
5502 "Aggregate mask\n")
5503 {
5504 int ret;
5505 char prefix_str[BUFSIZ];
5506
5507 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5508
5509 if (! ret)
5510 {
5511 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5512 return CMD_WARNING;
5513 }
5514
5515 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5516 0, 0);
5517 }
5518
5519 DEFUN (aggregate_address_summary_only,
5520 aggregate_address_summary_only_cmd,
5521 "aggregate-address A.B.C.D/M summary-only",
5522 "Configure BGP aggregate entries\n"
5523 "Aggregate prefix\n"
5524 "Filter more specific routes from updates\n")
5525 {
5526 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5527 AGGREGATE_SUMMARY_ONLY, 0);
5528 }
5529
5530 DEFUN (aggregate_address_mask_summary_only,
5531 aggregate_address_mask_summary_only_cmd,
5532 "aggregate-address A.B.C.D A.B.C.D summary-only",
5533 "Configure BGP aggregate entries\n"
5534 "Aggregate address\n"
5535 "Aggregate mask\n"
5536 "Filter more specific routes from updates\n")
5537 {
5538 int ret;
5539 char prefix_str[BUFSIZ];
5540
5541 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5542
5543 if (! ret)
5544 {
5545 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5546 return CMD_WARNING;
5547 }
5548
5549 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5550 AGGREGATE_SUMMARY_ONLY, 0);
5551 }
5552
5553 DEFUN (aggregate_address_as_set,
5554 aggregate_address_as_set_cmd,
5555 "aggregate-address A.B.C.D/M as-set",
5556 "Configure BGP aggregate entries\n"
5557 "Aggregate prefix\n"
5558 "Generate AS set path information\n")
5559 {
5560 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5561 0, AGGREGATE_AS_SET);
5562 }
5563
5564 DEFUN (aggregate_address_mask_as_set,
5565 aggregate_address_mask_as_set_cmd,
5566 "aggregate-address A.B.C.D A.B.C.D as-set",
5567 "Configure BGP aggregate entries\n"
5568 "Aggregate address\n"
5569 "Aggregate mask\n"
5570 "Generate AS set path information\n")
5571 {
5572 int ret;
5573 char prefix_str[BUFSIZ];
5574
5575 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5576
5577 if (! ret)
5578 {
5579 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5580 return CMD_WARNING;
5581 }
5582
5583 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5584 0, AGGREGATE_AS_SET);
5585 }
5586
5587
5588 DEFUN (aggregate_address_as_set_summary,
5589 aggregate_address_as_set_summary_cmd,
5590 "aggregate-address A.B.C.D/M as-set summary-only",
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n"
5593 "Generate AS set path information\n"
5594 "Filter more specific routes from updates\n")
5595 {
5596 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5597 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5598 }
5599
5600 ALIAS (aggregate_address_as_set_summary,
5601 aggregate_address_summary_as_set_cmd,
5602 "aggregate-address A.B.C.D/M summary-only as-set",
5603 "Configure BGP aggregate entries\n"
5604 "Aggregate prefix\n"
5605 "Filter more specific routes from updates\n"
5606 "Generate AS set path information\n")
5607
5608 DEFUN (aggregate_address_mask_as_set_summary,
5609 aggregate_address_mask_as_set_summary_cmd,
5610 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5611 "Configure BGP aggregate entries\n"
5612 "Aggregate address\n"
5613 "Aggregate mask\n"
5614 "Generate AS set path information\n"
5615 "Filter more specific routes from updates\n")
5616 {
5617 int ret;
5618 char prefix_str[BUFSIZ];
5619
5620 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5621
5622 if (! ret)
5623 {
5624 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5625 return CMD_WARNING;
5626 }
5627
5628 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5629 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5630 }
5631
5632 ALIAS (aggregate_address_mask_as_set_summary,
5633 aggregate_address_mask_summary_as_set_cmd,
5634 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5635 "Configure BGP aggregate entries\n"
5636 "Aggregate address\n"
5637 "Aggregate mask\n"
5638 "Filter more specific routes from updates\n"
5639 "Generate AS set path information\n")
5640
5641 DEFUN (no_aggregate_address,
5642 no_aggregate_address_cmd,
5643 "no aggregate-address A.B.C.D/M",
5644 NO_STR
5645 "Configure BGP aggregate entries\n"
5646 "Aggregate prefix\n")
5647 {
5648 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5649 }
5650
5651 ALIAS (no_aggregate_address,
5652 no_aggregate_address_summary_only_cmd,
5653 "no aggregate-address A.B.C.D/M summary-only",
5654 NO_STR
5655 "Configure BGP aggregate entries\n"
5656 "Aggregate prefix\n"
5657 "Filter more specific routes from updates\n")
5658
5659 ALIAS (no_aggregate_address,
5660 no_aggregate_address_as_set_cmd,
5661 "no aggregate-address A.B.C.D/M as-set",
5662 NO_STR
5663 "Configure BGP aggregate entries\n"
5664 "Aggregate prefix\n"
5665 "Generate AS set path information\n")
5666
5667 ALIAS (no_aggregate_address,
5668 no_aggregate_address_as_set_summary_cmd,
5669 "no aggregate-address A.B.C.D/M as-set summary-only",
5670 NO_STR
5671 "Configure BGP aggregate entries\n"
5672 "Aggregate prefix\n"
5673 "Generate AS set path information\n"
5674 "Filter more specific routes from updates\n")
5675
5676 ALIAS (no_aggregate_address,
5677 no_aggregate_address_summary_as_set_cmd,
5678 "no aggregate-address A.B.C.D/M summary-only as-set",
5679 NO_STR
5680 "Configure BGP aggregate entries\n"
5681 "Aggregate prefix\n"
5682 "Filter more specific routes from updates\n"
5683 "Generate AS set path information\n")
5684
5685 DEFUN (no_aggregate_address_mask,
5686 no_aggregate_address_mask_cmd,
5687 "no aggregate-address A.B.C.D A.B.C.D",
5688 NO_STR
5689 "Configure BGP aggregate entries\n"
5690 "Aggregate address\n"
5691 "Aggregate mask\n")
5692 {
5693 int ret;
5694 char prefix_str[BUFSIZ];
5695
5696 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5697
5698 if (! ret)
5699 {
5700 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5701 return CMD_WARNING;
5702 }
5703
5704 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5705 }
5706
5707 ALIAS (no_aggregate_address_mask,
5708 no_aggregate_address_mask_summary_only_cmd,
5709 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5710 NO_STR
5711 "Configure BGP aggregate entries\n"
5712 "Aggregate address\n"
5713 "Aggregate mask\n"
5714 "Filter more specific routes from updates\n")
5715
5716 ALIAS (no_aggregate_address_mask,
5717 no_aggregate_address_mask_as_set_cmd,
5718 "no aggregate-address A.B.C.D A.B.C.D as-set",
5719 NO_STR
5720 "Configure BGP aggregate entries\n"
5721 "Aggregate address\n"
5722 "Aggregate mask\n"
5723 "Generate AS set path information\n")
5724
5725 ALIAS (no_aggregate_address_mask,
5726 no_aggregate_address_mask_as_set_summary_cmd,
5727 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5728 NO_STR
5729 "Configure BGP aggregate entries\n"
5730 "Aggregate address\n"
5731 "Aggregate mask\n"
5732 "Generate AS set path information\n"
5733 "Filter more specific routes from updates\n")
5734
5735 ALIAS (no_aggregate_address_mask,
5736 no_aggregate_address_mask_summary_as_set_cmd,
5737 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5738 NO_STR
5739 "Configure BGP aggregate entries\n"
5740 "Aggregate address\n"
5741 "Aggregate mask\n"
5742 "Filter more specific routes from updates\n"
5743 "Generate AS set path information\n")
5744
5745 #ifdef HAVE_IPV6
5746 DEFUN (ipv6_aggregate_address,
5747 ipv6_aggregate_address_cmd,
5748 "aggregate-address X:X::X:X/M",
5749 "Configure BGP aggregate entries\n"
5750 "Aggregate prefix\n")
5751 {
5752 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5753 }
5754
5755 DEFUN (ipv6_aggregate_address_summary_only,
5756 ipv6_aggregate_address_summary_only_cmd,
5757 "aggregate-address X:X::X:X/M summary-only",
5758 "Configure BGP aggregate entries\n"
5759 "Aggregate prefix\n"
5760 "Filter more specific routes from updates\n")
5761 {
5762 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5763 AGGREGATE_SUMMARY_ONLY, 0);
5764 }
5765
5766 DEFUN (no_ipv6_aggregate_address,
5767 no_ipv6_aggregate_address_cmd,
5768 "no aggregate-address X:X::X:X/M",
5769 NO_STR
5770 "Configure BGP aggregate entries\n"
5771 "Aggregate prefix\n")
5772 {
5773 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5774 }
5775
5776 DEFUN (no_ipv6_aggregate_address_summary_only,
5777 no_ipv6_aggregate_address_summary_only_cmd,
5778 "no aggregate-address X:X::X:X/M summary-only",
5779 NO_STR
5780 "Configure BGP aggregate entries\n"
5781 "Aggregate prefix\n"
5782 "Filter more specific routes from updates\n")
5783 {
5784 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5785 }
5786
5787 ALIAS (ipv6_aggregate_address,
5788 old_ipv6_aggregate_address_cmd,
5789 "ipv6 bgp aggregate-address X:X::X:X/M",
5790 IPV6_STR
5791 BGP_STR
5792 "Configure BGP aggregate entries\n"
5793 "Aggregate prefix\n")
5794
5795 ALIAS (ipv6_aggregate_address_summary_only,
5796 old_ipv6_aggregate_address_summary_only_cmd,
5797 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5798 IPV6_STR
5799 BGP_STR
5800 "Configure BGP aggregate entries\n"
5801 "Aggregate prefix\n"
5802 "Filter more specific routes from updates\n")
5803
5804 ALIAS (no_ipv6_aggregate_address,
5805 old_no_ipv6_aggregate_address_cmd,
5806 "no ipv6 bgp aggregate-address X:X::X:X/M",
5807 NO_STR
5808 IPV6_STR
5809 BGP_STR
5810 "Configure BGP aggregate entries\n"
5811 "Aggregate prefix\n")
5812
5813 ALIAS (no_ipv6_aggregate_address_summary_only,
5814 old_no_ipv6_aggregate_address_summary_only_cmd,
5815 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5816 NO_STR
5817 IPV6_STR
5818 BGP_STR
5819 "Configure BGP aggregate entries\n"
5820 "Aggregate prefix\n"
5821 "Filter more specific routes from updates\n")
5822 #endif /* HAVE_IPV6 */
5823
5824 /* Redistribute route treatment. */
5825 void
5826 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5827 const struct in6_addr *nexthop6, unsigned int ifindex,
5828 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
5829 {
5830 struct bgp_info *new;
5831 struct bgp_info *bi;
5832 struct bgp_info info;
5833 struct bgp_node *bn;
5834 struct attr attr;
5835 struct attr *new_attr;
5836 afi_t afi;
5837 int ret;
5838 struct bgp_redist *red;
5839
5840 /* Make default attribute. */
5841 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5842 if (nexthop)
5843 attr.nexthop = *nexthop;
5844 attr.nh_ifindex = ifindex;
5845
5846 #ifdef HAVE_IPV6
5847 if (nexthop6)
5848 {
5849 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5850 extra->mp_nexthop_global = *nexthop6;
5851 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5852 }
5853 #endif
5854
5855 attr.med = metric;
5856 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5857 attr.extra->tag = tag;
5858
5859 afi = family2afi (p->family);
5860
5861 red = bgp_redist_lookup(bgp, afi, type, instance);
5862 if (red)
5863 {
5864 struct attr attr_new;
5865 struct attr_extra extra_new;
5866
5867 /* Copy attribute for modification. */
5868 attr_new.extra = &extra_new;
5869 bgp_attr_dup (&attr_new, &attr);
5870
5871 if (red->redist_metric_flag)
5872 attr_new.med = red->redist_metric;
5873
5874 /* Apply route-map. */
5875 if (red->rmap.name)
5876 {
5877 info.peer = bgp->peer_self;
5878 info.attr = &attr_new;
5879
5880 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5881
5882 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5883
5884 bgp->peer_self->rmap_type = 0;
5885
5886 if (ret == RMAP_DENYMATCH)
5887 {
5888 /* Free uninterned attribute. */
5889 bgp_attr_flush (&attr_new);
5890
5891 /* Unintern original. */
5892 aspath_unintern (&attr.aspath);
5893 bgp_attr_extra_free (&attr);
5894 bgp_redistribute_delete (bgp, p, type, instance);
5895 return;
5896 }
5897 }
5898
5899 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5900 afi, SAFI_UNICAST, p, NULL);
5901
5902 new_attr = bgp_attr_intern (&attr_new);
5903
5904 for (bi = bn->info; bi; bi = bi->next)
5905 if (bi->peer == bgp->peer_self
5906 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5907 break;
5908
5909 if (bi)
5910 {
5911 /* Ensure the (source route) type is updated. */
5912 bi->type = type;
5913 if (attrhash_cmp (bi->attr, new_attr) &&
5914 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5915 {
5916 bgp_attr_unintern (&new_attr);
5917 aspath_unintern (&attr.aspath);
5918 bgp_attr_extra_free (&attr);
5919 bgp_unlock_node (bn);
5920 return;
5921 }
5922 else
5923 {
5924 /* The attribute is changed. */
5925 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5926
5927 /* Rewrite BGP route information. */
5928 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5929 bgp_info_restore(bn, bi);
5930 else
5931 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5932 bgp_attr_unintern (&bi->attr);
5933 bi->attr = new_attr;
5934 bi->uptime = bgp_clock ();
5935
5936 /* Process change. */
5937 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5938 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5939 bgp_unlock_node (bn);
5940 aspath_unintern (&attr.aspath);
5941 bgp_attr_extra_free (&attr);
5942 return;
5943 }
5944 }
5945
5946 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5947 new_attr, bn);
5948 SET_FLAG (new->flags, BGP_INFO_VALID);
5949
5950 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5951 bgp_info_add (bn, new);
5952 bgp_unlock_node (bn);
5953 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5954 }
5955
5956 /* Unintern original. */
5957 aspath_unintern (&attr.aspath);
5958 bgp_attr_extra_free (&attr);
5959 }
5960
5961 void
5962 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5963 {
5964 afi_t afi;
5965 struct bgp_node *rn;
5966 struct bgp_info *ri;
5967 struct bgp_redist *red;
5968
5969 afi = family2afi (p->family);
5970
5971 red = bgp_redist_lookup(bgp, afi, type, instance);
5972 if (red)
5973 {
5974 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5975
5976 for (ri = rn->info; ri; ri = ri->next)
5977 if (ri->peer == bgp->peer_self
5978 && ri->type == type)
5979 break;
5980
5981 if (ri)
5982 {
5983 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5984 bgp_info_delete (rn, ri);
5985 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5986 }
5987 bgp_unlock_node (rn);
5988 }
5989 }
5990
5991 /* Withdraw specified route type's route. */
5992 void
5993 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5994 {
5995 struct bgp_node *rn;
5996 struct bgp_info *ri;
5997 struct bgp_table *table;
5998
5999 table = bgp->rib[afi][SAFI_UNICAST];
6000
6001 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6002 {
6003 for (ri = rn->info; ri; ri = ri->next)
6004 if (ri->peer == bgp->peer_self
6005 && ri->type == type
6006 && ri->instance == instance)
6007 break;
6008
6009 if (ri)
6010 {
6011 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6012 bgp_info_delete (rn, ri);
6013 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6014 }
6015 }
6016 }
6017
6018 /* Static function to display route. */
6019 static void
6020 route_vty_out_route (struct prefix *p, struct vty *vty)
6021 {
6022 int len;
6023 u_int32_t destination;
6024 char buf[BUFSIZ];
6025
6026 if (p->family == AF_INET)
6027 {
6028 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6029 destination = ntohl (p->u.prefix4.s_addr);
6030
6031 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6032 || (IN_CLASSB (destination) && p->prefixlen == 16)
6033 || (IN_CLASSA (destination) && p->prefixlen == 8)
6034 || p->u.prefix4.s_addr == 0)
6035 {
6036 /* When mask is natural, mask is not displayed. */
6037 }
6038 else
6039 len += vty_out (vty, "/%d", p->prefixlen);
6040 }
6041 else
6042 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6043 p->prefixlen);
6044
6045 len = 17 - len;
6046 if (len < 1)
6047 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6048 else
6049 vty_out (vty, "%*s", len, " ");
6050 }
6051
6052 enum bgp_display_type
6053 {
6054 normal_list,
6055 };
6056
6057 /* Print the short form route status for a bgp_info */
6058 static void
6059 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6060 json_object *json_path)
6061 {
6062 if (json_path)
6063 {
6064
6065 /* Route status display. */
6066 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6067 json_object_boolean_true_add(json_path, "removed");
6068
6069 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6070 json_object_boolean_true_add(json_path, "stale");
6071
6072 if (binfo->extra && binfo->extra->suppress)
6073 json_object_boolean_true_add(json_path, "suppressed");
6074
6075 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6076 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6077 json_object_boolean_true_add(json_path, "valid");
6078
6079 /* Selected */
6080 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6081 json_object_boolean_true_add(json_path, "history");
6082
6083 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6084 json_object_boolean_true_add(json_path, "damped");
6085
6086 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6087 json_object_boolean_true_add(json_path, "bestpath");
6088
6089 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6090 json_object_boolean_true_add(json_path, "multipath");
6091
6092 /* Internal route. */
6093 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6094 json_object_string_add(json_path, "pathFrom", "internal");
6095 else
6096 json_object_string_add(json_path, "pathFrom", "external");
6097
6098 return;
6099 }
6100
6101 /* Route status display. */
6102 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6103 vty_out (vty, "R");
6104 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6105 vty_out (vty, "S");
6106 else if (binfo->extra && binfo->extra->suppress)
6107 vty_out (vty, "s");
6108 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6109 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6110 vty_out (vty, "*");
6111 else
6112 vty_out (vty, " ");
6113
6114 /* Selected */
6115 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6116 vty_out (vty, "h");
6117 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6118 vty_out (vty, "d");
6119 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6120 vty_out (vty, ">");
6121 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6122 vty_out (vty, "=");
6123 else
6124 vty_out (vty, " ");
6125
6126 /* Internal route. */
6127 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6128 vty_out (vty, "i");
6129 else
6130 vty_out (vty, " ");
6131 }
6132
6133 /* called from terminal list command */
6134 void
6135 route_vty_out (struct vty *vty, struct prefix *p,
6136 struct bgp_info *binfo, int display, safi_t safi,
6137 json_object *json_paths)
6138 {
6139 struct attr *attr;
6140 json_object *json_path = NULL;
6141 json_object *json_nexthops = NULL;
6142 json_object *json_nexthop_global = NULL;
6143 json_object *json_nexthop_ll = NULL;
6144
6145 if (json_paths)
6146 json_path = json_object_new_object();
6147
6148 /* short status lead text */
6149 route_vty_short_status_out (vty, binfo, json_path);
6150
6151 if (!json_paths)
6152 {
6153 /* print prefix and mask */
6154 if (! display)
6155 route_vty_out_route (p, vty);
6156 else
6157 vty_out (vty, "%*s", 17, " ");
6158 }
6159
6160 /* Print attribute */
6161 attr = binfo->attr;
6162 if (attr)
6163 {
6164 /*
6165 * For ENCAP routes, nexthop address family is not
6166 * neccessarily the same as the prefix address family.
6167 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6168 */
6169 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6170 {
6171 if (attr->extra)
6172 {
6173 char buf[BUFSIZ];
6174 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6175
6176 switch (af)
6177 {
6178 case AF_INET:
6179 vty_out (vty, "%s", inet_ntop(af,
6180 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6181 break;
6182 #if HAVE_IPV6
6183 case AF_INET6:
6184 vty_out (vty, "%s", inet_ntop(af,
6185 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6186 break;
6187 #endif
6188 default:
6189 vty_out(vty, "?");
6190 break;
6191 }
6192 }
6193 else
6194 vty_out(vty, "?");
6195 }
6196 /* IPv4 Next Hop */
6197 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6198 {
6199 if (json_paths)
6200 {
6201 json_nexthop_global = json_object_new_object();
6202
6203 if (safi == SAFI_MPLS_VPN)
6204 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6205 else
6206 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6207
6208 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6209 json_object_boolean_true_add(json_nexthop_global, "used");
6210 }
6211 else
6212 {
6213 if (safi == SAFI_MPLS_VPN)
6214 vty_out (vty, "%-16s",
6215 inet_ntoa (attr->extra->mp_nexthop_global_in));
6216 else
6217 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6218 }
6219 }
6220
6221 /* IPv6 Next Hop */
6222 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6223 {
6224 int len;
6225 char buf[BUFSIZ];
6226
6227 if (json_paths)
6228 {
6229 json_nexthop_global = json_object_new_object();
6230 json_object_string_add(json_nexthop_global, "ip",
6231 inet_ntop (AF_INET6,
6232 &attr->extra->mp_nexthop_global,
6233 buf, BUFSIZ));
6234 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6235 json_object_string_add(json_nexthop_global, "scope", "global");
6236
6237 /* We display both LL & GL if both have been received */
6238 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6239 {
6240 json_nexthop_ll = json_object_new_object();
6241 json_object_string_add(json_nexthop_ll, "ip",
6242 inet_ntop (AF_INET6,
6243 &attr->extra->mp_nexthop_local,
6244 buf, BUFSIZ));
6245 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6246 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6247
6248 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6249 &attr->extra->mp_nexthop_local) != 0) &&
6250 !attr->extra->mp_nexthop_prefer_global)
6251 json_object_boolean_true_add(json_nexthop_ll, "used");
6252 else
6253 json_object_boolean_true_add(json_nexthop_global, "used");
6254 }
6255 else
6256 json_object_boolean_true_add(json_nexthop_global, "used");
6257 }
6258 else
6259 {
6260 /* Display LL if LL/Global both in table unless prefer-global is set */
6261 if (((attr->extra->mp_nexthop_len == 32) &&
6262 !attr->extra->mp_nexthop_prefer_global) ||
6263 (binfo->peer->conf_if))
6264 {
6265 if (binfo->peer->conf_if)
6266 {
6267 len = vty_out (vty, "%s",
6268 binfo->peer->conf_if);
6269 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6270
6271 if (len < 1)
6272 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6273 else
6274 vty_out (vty, "%*s", len, " ");
6275 }
6276 else
6277 {
6278 len = vty_out (vty, "%s",
6279 inet_ntop (AF_INET6,
6280 &attr->extra->mp_nexthop_local,
6281 buf, BUFSIZ));
6282 len = 16 - len;
6283
6284 if (len < 1)
6285 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6286 else
6287 vty_out (vty, "%*s", len, " ");
6288 }
6289 }
6290 else
6291 {
6292 len = vty_out (vty, "%s",
6293 inet_ntop (AF_INET6,
6294 &attr->extra->mp_nexthop_global,
6295 buf, BUFSIZ));
6296 len = 16 - len;
6297
6298 if (len < 1)
6299 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6300 else
6301 vty_out (vty, "%*s", len, " ");
6302 }
6303 }
6304 }
6305
6306 /* MED/Metric */
6307 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6308 if (json_paths)
6309 json_object_int_add(json_path, "med", attr->med);
6310 else
6311 vty_out (vty, "%10u", attr->med);
6312 else
6313 if (!json_paths)
6314 vty_out (vty, " ");
6315
6316 /* Local Pref */
6317 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6318 if (json_paths)
6319 json_object_int_add(json_path, "localpref", attr->local_pref);
6320 else
6321 vty_out (vty, "%7u", attr->local_pref);
6322 else
6323 if (!json_paths)
6324 vty_out (vty, " ");
6325
6326 if (json_paths)
6327 {
6328 if (attr->extra)
6329 json_object_int_add(json_path, "weight", attr->extra->weight);
6330 else
6331 json_object_int_add(json_path, "weight", 0);
6332 }
6333 else
6334 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6335
6336 if (json_paths) {
6337 char buf[BUFSIZ];
6338 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6339 }
6340
6341 /* Print aspath */
6342 if (attr->aspath)
6343 {
6344 if (json_paths)
6345 json_object_string_add(json_path, "aspath", attr->aspath->str);
6346 else
6347 aspath_print_vty (vty, "%s", attr->aspath, " ");
6348 }
6349
6350 /* Print origin */
6351 if (json_paths)
6352 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6353 else
6354 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6355 }
6356 else
6357 {
6358 if (json_paths)
6359 json_object_string_add(json_path, "alert", "No attributes");
6360 else
6361 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6362 }
6363
6364 if (json_paths)
6365 {
6366 if (json_nexthop_global || json_nexthop_ll)
6367 {
6368 json_nexthops = json_object_new_array();
6369
6370 if (json_nexthop_global)
6371 json_object_array_add(json_nexthops, json_nexthop_global);
6372
6373 if (json_nexthop_ll)
6374 json_object_array_add(json_nexthops, json_nexthop_ll);
6375
6376 json_object_object_add(json_path, "nexthops", json_nexthops);
6377 }
6378
6379 json_object_array_add(json_paths, json_path);
6380 }
6381 else
6382 {
6383 vty_out (vty, "%s", VTY_NEWLINE);
6384 #if ENABLE_BGP_VNC
6385 /* prints an additional line, indented, with VNC info, if present */
6386 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6387 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6388 #endif
6389 }
6390 }
6391
6392 /* called from terminal list command */
6393 void
6394 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6395 u_char use_json, json_object *json_ar)
6396 {
6397 json_object *json_status = NULL;
6398 json_object *json_net = NULL;
6399 char buff[BUFSIZ];
6400 /* Route status display. */
6401 if (use_json)
6402 {
6403 json_status = json_object_new_object();
6404 json_net = json_object_new_object();
6405 }
6406 else
6407 {
6408 vty_out (vty, "*");
6409 vty_out (vty, ">");
6410 vty_out (vty, " ");
6411 }
6412
6413 /* print prefix and mask */
6414 if (use_json)
6415 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6416 else
6417 route_vty_out_route (p, vty);
6418
6419 /* Print attribute */
6420 if (attr)
6421 {
6422 if (use_json)
6423 {
6424 if (p->family == AF_INET &&
6425 (safi == SAFI_MPLS_VPN ||
6426 safi == SAFI_ENCAP ||
6427 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6428 {
6429 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6430 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6431 else
6432 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6433 }
6434 #ifdef HAVE_IPV6
6435 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6436 {
6437 char buf[BUFSIZ];
6438
6439 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6440 buf, BUFSIZ));
6441 }
6442 #endif /* HAVE_IPV6 */
6443
6444 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6445 json_object_int_add(json_net, "metric", attr->med);
6446
6447 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6448 json_object_int_add(json_net, "localPref", attr->local_pref);
6449
6450 if (attr->extra)
6451 json_object_int_add(json_net, "weight", attr->extra->weight);
6452 else
6453 json_object_int_add(json_net, "weight", 0);
6454
6455 /* Print aspath */
6456 if (attr->aspath)
6457 json_object_string_add(json_net, "asPath", attr->aspath->str);
6458
6459 /* Print origin */
6460 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6461 }
6462 else
6463 {
6464 if (p->family == AF_INET &&
6465 (safi == SAFI_MPLS_VPN ||
6466 safi == SAFI_ENCAP ||
6467 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6468 {
6469 if (attr->extra &&
6470 (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP))
6471 vty_out (vty, "%-16s",
6472 inet_ntoa (attr->extra->mp_nexthop_global_in));
6473 else
6474 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6475 }
6476 #ifdef HAVE_IPV6
6477 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6478 {
6479 int len;
6480 char buf[BUFSIZ];
6481 if (attr->extra)
6482 {
6483 len = vty_out (vty, "%s",
6484 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6485 buf, BUFSIZ));
6486 len = 16 - len;
6487 }
6488 else
6489 len = 0;
6490 if (len < 1)
6491 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6492 else
6493 vty_out (vty, "%*s", len, " ");
6494 }
6495 #endif /* HAVE_IPV6 */
6496 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6497 vty_out (vty, "%10u", attr->med);
6498 else
6499 vty_out (vty, " ");
6500
6501 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6502 vty_out (vty, "%7u", attr->local_pref);
6503 else
6504 vty_out (vty, " ");
6505
6506 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6507
6508 /* Print aspath */
6509 if (attr->aspath)
6510 aspath_print_vty (vty, "%s", attr->aspath, " ");
6511
6512 /* Print origin */
6513 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6514 }
6515 }
6516 if (use_json)
6517 {
6518 json_object_boolean_true_add(json_status, "*");
6519 json_object_boolean_true_add(json_status, ">");
6520 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6521 char buf_cut[BUFSIZ];
6522 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6523 }
6524 else
6525 vty_out (vty, "%s", VTY_NEWLINE);
6526 }
6527
6528 void
6529 route_vty_out_tag (struct vty *vty, struct prefix *p,
6530 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6531 {
6532 json_object *json_out = NULL;
6533 struct attr *attr;
6534 u_int32_t label = 0;
6535
6536 if (!binfo->extra)
6537 return;
6538
6539 if (json)
6540 json_out = json_object_new_object();
6541
6542 /* short status lead text */
6543 route_vty_short_status_out (vty, binfo, json_out);
6544
6545 /* print prefix and mask */
6546 if (json == NULL)
6547 {
6548 if (! display)
6549 route_vty_out_route (p, vty);
6550 else
6551 vty_out (vty, "%*s", 17, " ");
6552 }
6553
6554 /* Print attribute */
6555 attr = binfo->attr;
6556 if (attr)
6557 {
6558 if (p->family == AF_INET
6559 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6560 {
6561 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6562 {
6563 if (json)
6564 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6565 else
6566 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6567 }
6568 else
6569 {
6570 if (json)
6571 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6572 else
6573 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6574 }
6575 }
6576 #ifdef HAVE_IPV6
6577 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6578 {
6579 assert (attr->extra);
6580 char buf_a[BUFSIZ];
6581 char buf_b[BUFSIZ];
6582 char buf_c[BUFSIZ];
6583 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6584 {
6585 if (json)
6586 json_object_string_add(json_out, "mpNexthopGlobalIn",
6587 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6588 else
6589 vty_out (vty, "%s",
6590 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6591 buf_a, BUFSIZ));
6592 }
6593 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6594 {
6595 if (json)
6596 {
6597 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6598 buf_a, BUFSIZ);
6599 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6600 buf_b, BUFSIZ);
6601 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6602 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6603 }
6604 else
6605 vty_out (vty, "%s(%s)",
6606 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6607 buf_a, BUFSIZ),
6608 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6609 buf_b, BUFSIZ));
6610 }
6611
6612 }
6613 #endif /* HAVE_IPV6 */
6614 }
6615
6616 label = decode_label (binfo->extra->tag);
6617
6618 if (json)
6619 {
6620 if (label)
6621 json_object_int_add(json_out, "notag", label);
6622 json_object_array_add(json, json_out);
6623 }
6624 else
6625 {
6626 vty_out (vty, "notag/%d", label);
6627 vty_out (vty, "%s", VTY_NEWLINE);
6628 }
6629 }
6630
6631 /* dampening route */
6632 static void
6633 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6634 int display, safi_t safi, u_char use_json, json_object *json)
6635 {
6636 struct attr *attr;
6637 int len;
6638 char timebuf[BGP_UPTIME_LEN];
6639
6640 /* short status lead text */
6641 route_vty_short_status_out (vty, binfo, json);
6642
6643 /* print prefix and mask */
6644 if (!use_json)
6645 {
6646 if (! display)
6647 route_vty_out_route (p, vty);
6648 else
6649 vty_out (vty, "%*s", 17, " ");
6650 }
6651
6652 len = vty_out (vty, "%s", binfo->peer->host);
6653 len = 17 - len;
6654 if (len < 1)
6655 {
6656 if (!use_json)
6657 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6658 }
6659 else
6660 {
6661 if (use_json)
6662 json_object_int_add(json, "peerHost", len);
6663 else
6664 vty_out (vty, "%*s", len, " ");
6665 }
6666
6667 if (use_json)
6668 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6669 else
6670 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6671
6672 /* Print attribute */
6673 attr = binfo->attr;
6674 if (attr)
6675 {
6676 /* Print aspath */
6677 if (attr->aspath)
6678 {
6679 if (use_json)
6680 json_object_string_add(json, "asPath", attr->aspath->str);
6681 else
6682 aspath_print_vty (vty, "%s", attr->aspath, " ");
6683 }
6684
6685 /* Print origin */
6686 if (use_json)
6687 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6688 else
6689 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6690 }
6691 if (!use_json)
6692 vty_out (vty, "%s", VTY_NEWLINE);
6693 }
6694
6695 /* flap route */
6696 static void
6697 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6698 int display, safi_t safi, u_char use_json, json_object *json)
6699 {
6700 struct attr *attr;
6701 struct bgp_damp_info *bdi;
6702 char timebuf[BGP_UPTIME_LEN];
6703 int len;
6704
6705 if (!binfo->extra)
6706 return;
6707
6708 bdi = binfo->extra->damp_info;
6709
6710 /* short status lead text */
6711 route_vty_short_status_out (vty, binfo, json);
6712
6713 /* print prefix and mask */
6714 if (!use_json)
6715 {
6716 if (! display)
6717 route_vty_out_route (p, vty);
6718 else
6719 vty_out (vty, "%*s", 17, " ");
6720 }
6721
6722 len = vty_out (vty, "%s", binfo->peer->host);
6723 len = 16 - len;
6724 if (len < 1)
6725 {
6726 if (!use_json)
6727 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6728 }
6729 else
6730 {
6731 if (use_json)
6732 json_object_int_add(json, "peerHost", len);
6733 else
6734 vty_out (vty, "%*s", len, " ");
6735 }
6736
6737 len = vty_out (vty, "%d", bdi->flap);
6738 len = 5 - len;
6739 if (len < 1)
6740 {
6741 if (!use_json)
6742 vty_out (vty, " ");
6743 }
6744 else
6745 {
6746 if (use_json)
6747 json_object_int_add(json, "bdiFlap", len);
6748 else
6749 vty_out (vty, "%*s", len, " ");
6750 }
6751
6752 if (use_json)
6753 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6754 else
6755 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6756 timebuf, BGP_UPTIME_LEN, 0, NULL));
6757
6758 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6759 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6760 {
6761 if (use_json)
6762 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6763 else
6764 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6765 }
6766 else
6767 {
6768 if (!use_json)
6769 vty_out (vty, "%*s ", 8, " ");
6770 }
6771
6772 /* Print attribute */
6773 attr = binfo->attr;
6774 if (attr)
6775 {
6776 /* Print aspath */
6777 if (attr->aspath)
6778 {
6779 if (use_json)
6780 json_object_string_add(json, "asPath", attr->aspath->str);
6781 else
6782 aspath_print_vty (vty, "%s", attr->aspath, " ");
6783 }
6784
6785 /* Print origin */
6786 if (use_json)
6787 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6788 else
6789 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6790 }
6791 if (!use_json)
6792 vty_out (vty, "%s", VTY_NEWLINE);
6793 }
6794
6795 static void
6796 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6797 const char *header, json_object *json_adv_to)
6798 {
6799 char buf1[INET6_ADDRSTRLEN];
6800 json_object *json_peer = NULL;
6801
6802 if (json_adv_to)
6803 {
6804 /* 'advertised-to' is a dictionary of peers we have advertised this
6805 * prefix too. The key is the peer's IP or swpX, the value is the
6806 * hostname if we know it and "" if not.
6807 */
6808 json_peer = json_object_new_object();
6809
6810 if (peer->hostname)
6811 json_object_string_add(json_peer, "hostname", peer->hostname);
6812
6813 if (peer->conf_if)
6814 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6815 else
6816 json_object_object_add(json_adv_to,
6817 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6818 json_peer);
6819 }
6820 else
6821 {
6822 if (*first)
6823 {
6824 vty_out (vty, "%s", header);
6825 *first = 0;
6826 }
6827
6828 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6829 {
6830 if (peer->conf_if)
6831 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6832 else
6833 vty_out (vty, " %s(%s)", peer->hostname,
6834 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6835 }
6836 else
6837 {
6838 if (peer->conf_if)
6839 vty_out (vty, " %s", peer->conf_if);
6840 else
6841 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6842 }
6843 }
6844 }
6845
6846 static void
6847 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6848 struct bgp_info *binfo, afi_t afi, safi_t safi,
6849 json_object *json_paths)
6850 {
6851 char buf[INET6_ADDRSTRLEN];
6852 char buf1[BUFSIZ];
6853 struct attr *attr;
6854 int sockunion_vty_out (struct vty *, union sockunion *);
6855 #ifdef HAVE_CLOCK_MONOTONIC
6856 time_t tbuf;
6857 #endif
6858 json_object *json_bestpath = NULL;
6859 json_object *json_cluster_list = NULL;
6860 json_object *json_cluster_list_list = NULL;
6861 json_object *json_ext_community = NULL;
6862 json_object *json_last_update = NULL;
6863 json_object *json_nexthop_global = NULL;
6864 json_object *json_nexthop_ll = NULL;
6865 json_object *json_nexthops = NULL;
6866 json_object *json_path = NULL;
6867 json_object *json_peer = NULL;
6868 json_object *json_string = NULL;
6869 json_object *json_adv_to = NULL;
6870 int first = 0;
6871 struct listnode *node, *nnode;
6872 struct peer *peer;
6873 int addpath_capable;
6874 int has_adj;
6875 unsigned int first_as;
6876
6877 if (json_paths)
6878 {
6879 json_path = json_object_new_object();
6880 json_peer = json_object_new_object();
6881 json_nexthop_global = json_object_new_object();
6882 }
6883
6884 attr = binfo->attr;
6885
6886 if (attr)
6887 {
6888 /* Line1 display AS-path, Aggregator */
6889 if (attr->aspath)
6890 {
6891 if (json_paths)
6892 {
6893 json_object_lock(attr->aspath->json);
6894 json_object_object_add(json_path, "aspath", attr->aspath->json);
6895 }
6896 else
6897 {
6898 if (attr->aspath->segments)
6899 aspath_print_vty (vty, " %s", attr->aspath, "");
6900 else
6901 vty_out (vty, " Local");
6902 }
6903 }
6904
6905 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6906 {
6907 if (json_paths)
6908 json_object_boolean_true_add(json_path, "removed");
6909 else
6910 vty_out (vty, ", (removed)");
6911 }
6912
6913 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6914 {
6915 if (json_paths)
6916 json_object_boolean_true_add(json_path, "stale");
6917 else
6918 vty_out (vty, ", (stale)");
6919 }
6920
6921 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6922 {
6923 if (json_paths)
6924 {
6925 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6926 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6927 }
6928 else
6929 {
6930 vty_out (vty, ", (aggregated by %u %s)",
6931 attr->extra->aggregator_as,
6932 inet_ntoa (attr->extra->aggregator_addr));
6933 }
6934 }
6935
6936 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6937 {
6938 if (json_paths)
6939 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6940 else
6941 vty_out (vty, ", (Received from a RR-client)");
6942 }
6943
6944 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6945 {
6946 if (json_paths)
6947 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6948 else
6949 vty_out (vty, ", (Received from a RS-client)");
6950 }
6951
6952 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6953 {
6954 if (json_paths)
6955 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6956 else
6957 vty_out (vty, ", (history entry)");
6958 }
6959 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6960 {
6961 if (json_paths)
6962 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6963 else
6964 vty_out (vty, ", (suppressed due to dampening)");
6965 }
6966
6967 if (!json_paths)
6968 vty_out (vty, "%s", VTY_NEWLINE);
6969
6970 /* Line2 display Next-hop, Neighbor, Router-id */
6971 /* Display the nexthop */
6972 if (p->family == AF_INET &&
6973 (safi == SAFI_MPLS_VPN ||
6974 safi == SAFI_ENCAP ||
6975 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6976 {
6977 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6978 {
6979 if (json_paths)
6980 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6981 else
6982 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6983 }
6984 else
6985 {
6986 if (json_paths)
6987 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6988 else
6989 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6990 }
6991
6992 if (json_paths)
6993 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6994 }
6995 else
6996 {
6997 assert (attr->extra);
6998 if (json_paths)
6999 {
7000 json_object_string_add(json_nexthop_global, "ip",
7001 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7002 buf, INET6_ADDRSTRLEN));
7003 json_object_string_add(json_nexthop_global, "afi", "ipv6");
7004 json_object_string_add(json_nexthop_global, "scope", "global");
7005 }
7006 else
7007 {
7008 vty_out (vty, " %s",
7009 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7010 buf, INET6_ADDRSTRLEN));
7011 }
7012 }
7013
7014 /* Display the IGP cost or 'inaccessible' */
7015 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7016 {
7017 if (json_paths)
7018 json_object_boolean_false_add(json_nexthop_global, "accessible");
7019 else
7020 vty_out (vty, " (inaccessible)");
7021 }
7022 else
7023 {
7024 if (binfo->extra && binfo->extra->igpmetric)
7025 {
7026 if (json_paths)
7027 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
7028 else
7029 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7030 }
7031
7032 /* IGP cost is 0, display this only for json */
7033 else
7034 {
7035 if (json_paths)
7036 json_object_int_add(json_nexthop_global, "metric", 0);
7037 }
7038
7039 if (json_paths)
7040 json_object_boolean_true_add(json_nexthop_global, "accessible");
7041 }
7042
7043 /* Display peer "from" output */
7044 /* This path was originated locally */
7045 if (binfo->peer == bgp->peer_self)
7046 {
7047
7048 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
7049 {
7050 if (json_paths)
7051 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7052 else
7053 vty_out (vty, " from 0.0.0.0 ");
7054 }
7055 else
7056 {
7057 if (json_paths)
7058 json_object_string_add(json_peer, "peerId", "::");
7059 else
7060 vty_out (vty, " from :: ");
7061 }
7062
7063 if (json_paths)
7064 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7065 else
7066 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7067 }
7068
7069 /* We RXed this path from one of our peers */
7070 else
7071 {
7072
7073 if (json_paths)
7074 {
7075 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7076 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7077
7078 if (binfo->peer->hostname)
7079 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7080
7081 if (binfo->peer->domainname)
7082 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7083
7084 if (binfo->peer->conf_if)
7085 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7086 }
7087 else
7088 {
7089 if (binfo->peer->conf_if)
7090 {
7091 if (binfo->peer->hostname &&
7092 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7093 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7094 binfo->peer->conf_if);
7095 else
7096 vty_out (vty, " from %s", binfo->peer->conf_if);
7097 }
7098 else
7099 {
7100 if (binfo->peer->hostname &&
7101 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7102 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7103 binfo->peer->host);
7104 else
7105 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7106 }
7107
7108 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7109 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7110 else
7111 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7112 }
7113 }
7114
7115 if (!json_paths)
7116 vty_out (vty, "%s", VTY_NEWLINE);
7117
7118 /* display the link-local nexthop */
7119 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7120 {
7121 if (json_paths)
7122 {
7123 json_nexthop_ll = json_object_new_object();
7124 json_object_string_add(json_nexthop_ll, "ip",
7125 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7126 buf, INET6_ADDRSTRLEN));
7127 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7128 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7129
7130 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7131
7132 if (!attr->extra->mp_nexthop_prefer_global)
7133 json_object_boolean_true_add(json_nexthop_ll, "used");
7134 else
7135 json_object_boolean_true_add(json_nexthop_global, "used");
7136 }
7137 else
7138 {
7139 vty_out (vty, " (%s) %s%s",
7140 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7141 buf, INET6_ADDRSTRLEN),
7142 attr->extra->mp_nexthop_prefer_global ?
7143 "(prefer-global)" : "(used)",
7144 VTY_NEWLINE);
7145 }
7146 }
7147 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7148 else
7149 {
7150 if (json_paths)
7151 json_object_boolean_true_add(json_nexthop_global, "used");
7152 }
7153
7154 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7155 if (json_paths)
7156 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7157 else
7158 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7159
7160 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7161 {
7162 if (json_paths)
7163 json_object_int_add(json_path, "med", attr->med);
7164 else
7165 vty_out (vty, ", metric %u", attr->med);
7166 }
7167
7168 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7169 {
7170 if (json_paths)
7171 json_object_int_add(json_path, "localpref", attr->local_pref);
7172 else
7173 vty_out (vty, ", localpref %u", attr->local_pref);
7174 }
7175 else
7176 {
7177 if (json_paths)
7178 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7179 else
7180 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7181 }
7182
7183 if (attr->extra && attr->extra->weight != 0)
7184 {
7185 if (json_paths)
7186 json_object_int_add(json_path, "weight", attr->extra->weight);
7187 else
7188 vty_out (vty, ", weight %u", attr->extra->weight);
7189 }
7190
7191 if (attr->extra && attr->extra->tag != 0)
7192 {
7193 if (json_paths)
7194 json_object_int_add(json_path, "tag", attr->extra->tag);
7195 else
7196 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
7197 }
7198
7199 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7200 {
7201 if (json_paths)
7202 json_object_boolean_false_add(json_path, "valid");
7203 else
7204 vty_out (vty, ", invalid");
7205 }
7206 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7207 {
7208 if (json_paths)
7209 json_object_boolean_true_add(json_path, "valid");
7210 else
7211 vty_out (vty, ", valid");
7212 }
7213
7214 if (binfo->peer != bgp->peer_self)
7215 {
7216 if (binfo->peer->as == binfo->peer->local_as)
7217 {
7218 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7219 {
7220 if (json_paths)
7221 json_object_string_add(json_peer, "type", "confed-internal");
7222 else
7223 vty_out (vty, ", confed-internal");
7224 }
7225 else
7226 {
7227 if (json_paths)
7228 json_object_string_add(json_peer, "type", "internal");
7229 else
7230 vty_out (vty, ", internal");
7231 }
7232 }
7233 else
7234 {
7235 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7236 {
7237 if (json_paths)
7238 json_object_string_add(json_peer, "type", "confed-external");
7239 else
7240 vty_out (vty, ", confed-external");
7241 }
7242 else
7243 {
7244 if (json_paths)
7245 json_object_string_add(json_peer, "type", "external");
7246 else
7247 vty_out (vty, ", external");
7248 }
7249 }
7250 }
7251 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7252 {
7253 if (json_paths)
7254 {
7255 json_object_boolean_true_add(json_path, "aggregated");
7256 json_object_boolean_true_add(json_path, "local");
7257 }
7258 else
7259 {
7260 vty_out (vty, ", aggregated, local");
7261 }
7262 }
7263 else if (binfo->type != ZEBRA_ROUTE_BGP)
7264 {
7265 if (json_paths)
7266 json_object_boolean_true_add(json_path, "sourced");
7267 else
7268 vty_out (vty, ", sourced");
7269 }
7270 else
7271 {
7272 if (json_paths)
7273 {
7274 json_object_boolean_true_add(json_path, "sourced");
7275 json_object_boolean_true_add(json_path, "local");
7276 }
7277 else
7278 {
7279 vty_out (vty, ", sourced, local");
7280 }
7281 }
7282
7283 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7284 {
7285 if (json_paths)
7286 json_object_boolean_true_add(json_path, "atomicAggregate");
7287 else
7288 vty_out (vty, ", atomic-aggregate");
7289 }
7290
7291 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7292 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7293 bgp_info_mpath_count (binfo)))
7294 {
7295 if (json_paths)
7296 json_object_boolean_true_add(json_path, "multipath");
7297 else
7298 vty_out (vty, ", multipath");
7299 }
7300
7301 // Mark the bestpath(s)
7302 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7303 {
7304 first_as = aspath_get_first_as(attr->aspath);
7305
7306 if (json_paths)
7307 {
7308 if (!json_bestpath)
7309 json_bestpath = json_object_new_object();
7310 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7311 }
7312 else
7313 {
7314 if (first_as)
7315 vty_out (vty, ", bestpath-from-AS %d", first_as);
7316 else
7317 vty_out (vty, ", bestpath-from-AS Local");
7318 }
7319 }
7320
7321 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7322 {
7323 if (json_paths)
7324 {
7325 if (!json_bestpath)
7326 json_bestpath = json_object_new_object();
7327 json_object_boolean_true_add(json_bestpath, "overall");
7328 }
7329 else
7330 vty_out (vty, ", best");
7331 }
7332
7333 if (json_bestpath)
7334 json_object_object_add(json_path, "bestpath", json_bestpath);
7335
7336 if (!json_paths)
7337 vty_out (vty, "%s", VTY_NEWLINE);
7338
7339 /* Line 4 display Community */
7340 if (attr->community)
7341 {
7342 if (json_paths)
7343 {
7344 json_object_lock(attr->community->json);
7345 json_object_object_add(json_path, "community", attr->community->json);
7346 }
7347 else
7348 {
7349 vty_out (vty, " Community: %s%s", attr->community->str,
7350 VTY_NEWLINE);
7351 }
7352 }
7353
7354 /* Line 5 display Extended-community */
7355 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7356 {
7357 if (json_paths)
7358 {
7359 json_ext_community = json_object_new_object();
7360 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7361 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7362 }
7363 else
7364 {
7365 vty_out (vty, " Extended Community: %s%s",
7366 attr->extra->ecommunity->str, VTY_NEWLINE);
7367 }
7368 }
7369
7370 /* Line 6 display Originator, Cluster-id */
7371 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7372 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7373 {
7374 assert (attr->extra);
7375 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7376 {
7377 if (json_paths)
7378 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7379 else
7380 vty_out (vty, " Originator: %s",
7381 inet_ntoa (attr->extra->originator_id));
7382 }
7383
7384 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7385 {
7386 int i;
7387
7388 if (json_paths)
7389 {
7390 json_cluster_list = json_object_new_object();
7391 json_cluster_list_list = json_object_new_array();
7392
7393 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7394 {
7395 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7396 json_object_array_add(json_cluster_list_list, json_string);
7397 }
7398
7399 /* struct cluster_list does not have "str" variable like
7400 * aspath and community do. Add this someday if someone
7401 * asks for it.
7402 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7403 */
7404 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7405 json_object_object_add(json_path, "clusterList", json_cluster_list);
7406 }
7407 else
7408 {
7409 vty_out (vty, ", Cluster list: ");
7410
7411 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7412 {
7413 vty_out (vty, "%s ",
7414 inet_ntoa (attr->extra->cluster->list[i]));
7415 }
7416 }
7417 }
7418
7419 if (!json_paths)
7420 vty_out (vty, "%s", VTY_NEWLINE);
7421 }
7422
7423 if (binfo->extra && binfo->extra->damp_info)
7424 bgp_damp_info_vty (vty, binfo, json_path);
7425
7426 /* Line 7 display Addpath IDs */
7427 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7428 {
7429 if (json_paths)
7430 {
7431 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7432 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7433 }
7434 else
7435 {
7436 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7437 binfo->addpath_rx_id, binfo->addpath_tx_id,
7438 VTY_NEWLINE);
7439 }
7440 }
7441
7442 /* If we used addpath to TX a non-bestpath we need to display
7443 * "Advertised to" on a path-by-path basis */
7444 if (bgp->addpath_tx_used[afi][safi])
7445 {
7446 first = 1;
7447
7448 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7449 {
7450 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7451 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7452
7453 if ((addpath_capable && has_adj) ||
7454 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7455 {
7456 if (json_path && !json_adv_to)
7457 json_adv_to = json_object_new_object();
7458
7459 route_vty_out_advertised_to(vty, peer, &first,
7460 " Advertised to:",
7461 json_adv_to);
7462 }
7463 }
7464
7465 if (json_path)
7466 {
7467 if (json_adv_to)
7468 {
7469 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7470 }
7471 }
7472 else
7473 {
7474 if (!first)
7475 {
7476 vty_out (vty, "%s", VTY_NEWLINE);
7477 }
7478 }
7479 }
7480
7481 /* Line 8 display Uptime */
7482 #ifdef HAVE_CLOCK_MONOTONIC
7483 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7484 if (json_paths)
7485 {
7486 json_last_update = json_object_new_object();
7487 json_object_int_add(json_last_update, "epoch", tbuf);
7488 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7489 json_object_object_add(json_path, "lastUpdate", json_last_update);
7490 }
7491 else
7492 vty_out (vty, " Last update: %s", ctime(&tbuf));
7493 #else
7494 if (json_paths)
7495 {
7496 json_last_update = json_object_new_object();
7497 json_object_int_add(json_last_update, "epoch", tbuf);
7498 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7499 json_object_object_add(json_path, "lastUpdate", json_last_update);
7500 }
7501 else
7502 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7503 #endif /* HAVE_CLOCK_MONOTONIC */
7504 }
7505
7506 /* We've constructed the json object for this path, add it to the json
7507 * array of paths
7508 */
7509 if (json_paths)
7510 {
7511 if (json_nexthop_global || json_nexthop_ll)
7512 {
7513 json_nexthops = json_object_new_array();
7514
7515 if (json_nexthop_global)
7516 json_object_array_add(json_nexthops, json_nexthop_global);
7517
7518 if (json_nexthop_ll)
7519 json_object_array_add(json_nexthops, json_nexthop_ll);
7520
7521 json_object_object_add(json_path, "nexthops", json_nexthops);
7522 }
7523
7524 json_object_object_add(json_path, "peer", json_peer);
7525 json_object_array_add(json_paths, json_path);
7526 }
7527 else
7528 vty_out (vty, "%s", VTY_NEWLINE);
7529 }
7530
7531 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7532 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7533 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7534
7535 enum bgp_show_type
7536 {
7537 bgp_show_type_normal,
7538 bgp_show_type_regexp,
7539 bgp_show_type_prefix_list,
7540 bgp_show_type_filter_list,
7541 bgp_show_type_route_map,
7542 bgp_show_type_neighbor,
7543 bgp_show_type_cidr_only,
7544 bgp_show_type_prefix_longer,
7545 bgp_show_type_community_all,
7546 bgp_show_type_community,
7547 bgp_show_type_community_exact,
7548 bgp_show_type_community_list,
7549 bgp_show_type_community_list_exact,
7550 bgp_show_type_flap_statistics,
7551 bgp_show_type_flap_address,
7552 bgp_show_type_flap_prefix,
7553 bgp_show_type_flap_cidr_only,
7554 bgp_show_type_flap_regexp,
7555 bgp_show_type_flap_filter_list,
7556 bgp_show_type_flap_prefix_list,
7557 bgp_show_type_flap_prefix_longer,
7558 bgp_show_type_flap_route_map,
7559 bgp_show_type_flap_neighbor,
7560 bgp_show_type_dampend_paths,
7561 bgp_show_type_damp_neighbor
7562 };
7563
7564 static int
7565 bgp_show_prefix_list (struct vty *vty, const char *name,
7566 const char *prefix_list_str, afi_t afi,
7567 safi_t safi, enum bgp_show_type type);
7568 static int
7569 bgp_show_filter_list (struct vty *vty, const char *name,
7570 const char *filter, afi_t afi,
7571 safi_t safi, enum bgp_show_type type);
7572 static int
7573 bgp_show_route_map (struct vty *vty, const char *name,
7574 const char *rmap_str, afi_t afi,
7575 safi_t safi, enum bgp_show_type type);
7576 static int
7577 bgp_show_community_list (struct vty *vty, const char *name,
7578 const char *com, int exact,
7579 afi_t afi, safi_t safi);
7580 static int
7581 bgp_show_prefix_longer (struct vty *vty, const char *name,
7582 const char *prefix, afi_t afi,
7583 safi_t safi, enum bgp_show_type type);
7584
7585 static int
7586 bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table,
7587 enum bgp_show_type type, void *output_arg, u_char use_json)
7588 {
7589 struct bgp_info *ri;
7590 struct bgp_node *rn;
7591 int header = 1;
7592 int display;
7593 unsigned long output_count;
7594 unsigned long total_count;
7595 struct prefix *p;
7596 char buf[BUFSIZ];
7597 char buf2[BUFSIZ];
7598 json_object *json_paths = NULL;
7599 int first = 1;
7600
7601 if (use_json)
7602 {
7603 vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ",
7604 bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id,
7605 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name,
7606 table->version, inet_ntoa (bgp->router_id));
7607 json_paths = json_object_new_object();
7608 }
7609
7610 /* This is first entry point, so reset total line. */
7611 output_count = 0;
7612 total_count = 0;
7613
7614 /* Start processing of routes. */
7615 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7616 if (rn->info != NULL)
7617 {
7618 display = 0;
7619 if (!first && use_json)
7620 {
7621 vty_out (vty, ",");
7622 }
7623 if (use_json)
7624 json_paths = json_object_new_array();
7625 else
7626 json_paths = NULL;
7627
7628 for (ri = rn->info; ri; ri = ri->next)
7629 {
7630 total_count++;
7631 if (type == bgp_show_type_flap_statistics
7632 || type == bgp_show_type_flap_address
7633 || type == bgp_show_type_flap_prefix
7634 || type == bgp_show_type_flap_cidr_only
7635 || type == bgp_show_type_flap_regexp
7636 || type == bgp_show_type_flap_filter_list
7637 || type == bgp_show_type_flap_prefix_list
7638 || type == bgp_show_type_flap_prefix_longer
7639 || type == bgp_show_type_flap_route_map
7640 || type == bgp_show_type_flap_neighbor
7641 || type == bgp_show_type_dampend_paths
7642 || type == bgp_show_type_damp_neighbor)
7643 {
7644 if (!(ri->extra && ri->extra->damp_info))
7645 continue;
7646 }
7647 if (type == bgp_show_type_regexp
7648 || type == bgp_show_type_flap_regexp)
7649 {
7650 regex_t *regex = output_arg;
7651
7652 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7653 continue;
7654 }
7655 if (type == bgp_show_type_prefix_list
7656 || type == bgp_show_type_flap_prefix_list)
7657 {
7658 struct prefix_list *plist = output_arg;
7659
7660 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7661 continue;
7662 }
7663 if (type == bgp_show_type_filter_list
7664 || type == bgp_show_type_flap_filter_list)
7665 {
7666 struct as_list *as_list = output_arg;
7667
7668 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7669 continue;
7670 }
7671 if (type == bgp_show_type_route_map
7672 || type == bgp_show_type_flap_route_map)
7673 {
7674 struct route_map *rmap = output_arg;
7675 struct bgp_info binfo;
7676 struct attr dummy_attr;
7677 struct attr_extra dummy_extra;
7678 int ret;
7679
7680 dummy_attr.extra = &dummy_extra;
7681 bgp_attr_dup (&dummy_attr, ri->attr);
7682
7683 binfo.peer = ri->peer;
7684 binfo.attr = &dummy_attr;
7685
7686 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7687 if (ret == RMAP_DENYMATCH)
7688 continue;
7689 }
7690 if (type == bgp_show_type_neighbor
7691 || type == bgp_show_type_flap_neighbor
7692 || type == bgp_show_type_damp_neighbor)
7693 {
7694 union sockunion *su = output_arg;
7695
7696 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7697 continue;
7698 }
7699 if (type == bgp_show_type_cidr_only
7700 || type == bgp_show_type_flap_cidr_only)
7701 {
7702 u_int32_t destination;
7703
7704 destination = ntohl (rn->p.u.prefix4.s_addr);
7705 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7706 continue;
7707 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7708 continue;
7709 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7710 continue;
7711 }
7712 if (type == bgp_show_type_prefix_longer
7713 || type == bgp_show_type_flap_prefix_longer)
7714 {
7715 struct prefix *p = output_arg;
7716
7717 if (! prefix_match (p, &rn->p))
7718 continue;
7719 }
7720 if (type == bgp_show_type_community_all)
7721 {
7722 if (! ri->attr->community)
7723 continue;
7724 }
7725 if (type == bgp_show_type_community)
7726 {
7727 struct community *com = output_arg;
7728
7729 if (! ri->attr->community ||
7730 ! community_match (ri->attr->community, com))
7731 continue;
7732 }
7733 if (type == bgp_show_type_community_exact)
7734 {
7735 struct community *com = output_arg;
7736
7737 if (! ri->attr->community ||
7738 ! community_cmp (ri->attr->community, com))
7739 continue;
7740 }
7741 if (type == bgp_show_type_community_list)
7742 {
7743 struct community_list *list = output_arg;
7744
7745 if (! community_list_match (ri->attr->community, list))
7746 continue;
7747 }
7748 if (type == bgp_show_type_community_list_exact)
7749 {
7750 struct community_list *list = output_arg;
7751
7752 if (! community_list_exact_match (ri->attr->community, list))
7753 continue;
7754 }
7755 if (type == bgp_show_type_flap_address
7756 || type == bgp_show_type_flap_prefix)
7757 {
7758 struct prefix *p = output_arg;
7759
7760 if (! prefix_match (&rn->p, p))
7761 continue;
7762
7763 if (type == bgp_show_type_flap_prefix)
7764 if (p->prefixlen != rn->p.prefixlen)
7765 continue;
7766 }
7767 if (type == bgp_show_type_dampend_paths
7768 || type == bgp_show_type_damp_neighbor)
7769 {
7770 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7771 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7772 continue;
7773 }
7774
7775 if (!use_json && header)
7776 {
7777 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
7778 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7779 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7780 if (type == bgp_show_type_dampend_paths
7781 || type == bgp_show_type_damp_neighbor)
7782 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7783 else if (type == bgp_show_type_flap_statistics
7784 || type == bgp_show_type_flap_address
7785 || type == bgp_show_type_flap_prefix
7786 || type == bgp_show_type_flap_cidr_only
7787 || type == bgp_show_type_flap_regexp
7788 || type == bgp_show_type_flap_filter_list
7789 || type == bgp_show_type_flap_prefix_list
7790 || type == bgp_show_type_flap_prefix_longer
7791 || type == bgp_show_type_flap_route_map
7792 || type == bgp_show_type_flap_neighbor)
7793 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7794 else
7795 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7796 header = 0;
7797 }
7798
7799 if (type == bgp_show_type_dampend_paths
7800 || type == bgp_show_type_damp_neighbor)
7801 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7802 else if (type == bgp_show_type_flap_statistics
7803 || type == bgp_show_type_flap_address
7804 || type == bgp_show_type_flap_prefix
7805 || type == bgp_show_type_flap_cidr_only
7806 || type == bgp_show_type_flap_regexp
7807 || type == bgp_show_type_flap_filter_list
7808 || type == bgp_show_type_flap_prefix_list
7809 || type == bgp_show_type_flap_prefix_longer
7810 || type == bgp_show_type_flap_route_map
7811 || type == bgp_show_type_flap_neighbor)
7812 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7813 else
7814 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7815 display++;
7816 }
7817
7818 if (display)
7819 {
7820 output_count++;
7821 if (use_json)
7822 {
7823 p = &rn->p;
7824 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7825 vty_out (vty, "\"%s\": ", buf2);
7826 vty_out (vty, "%s", json_object_to_json_string (json_paths));
7827 json_object_free (json_paths);
7828 first = 0;
7829
7830 }
7831 }
7832 }
7833
7834 if (use_json)
7835 {
7836 json_object_free (json_paths);
7837 vty_out (vty, " } }%s", VTY_NEWLINE);
7838 }
7839 else
7840 {
7841 /* No route is displayed */
7842 if (output_count == 0)
7843 {
7844 if (type == bgp_show_type_normal)
7845 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7846 }
7847 else
7848 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
7849 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7850 }
7851
7852 return CMD_SUCCESS;
7853 }
7854
7855 static int
7856 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7857 enum bgp_show_type type, void *output_arg, u_char use_json)
7858 {
7859 struct bgp_table *table;
7860
7861 if (bgp == NULL)
7862 {
7863 bgp = bgp_get_default ();
7864 }
7865
7866 if (bgp == NULL)
7867 {
7868 if (!use_json)
7869 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7870 return CMD_WARNING;
7871 }
7872
7873 table = bgp->rib[afi][safi];
7874
7875 return bgp_show_table (vty, bgp, table, type, output_arg,
7876 use_json);
7877 }
7878
7879 static void
7880 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7881 u_char use_json)
7882 {
7883 struct listnode *node, *nnode;
7884 struct bgp *bgp;
7885 struct bgp_table *table;
7886 int is_first = 1;
7887
7888 if (use_json)
7889 vty_out (vty, "{%s", VTY_NEWLINE);
7890
7891 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7892 {
7893 if (use_json)
7894 {
7895 if (! is_first)
7896 vty_out (vty, ",%s", VTY_NEWLINE);
7897 else
7898 is_first = 0;
7899
7900 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7901 ? "Default" : bgp->name);
7902 }
7903 else
7904 {
7905 vty_out (vty, "%sInstance %s:%s",
7906 VTY_NEWLINE,
7907 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7908 ? "Default" : bgp->name,
7909 VTY_NEWLINE);
7910 }
7911 table = bgp->rib[afi][safi];
7912 bgp_show_table (vty, bgp, table,
7913 bgp_show_type_normal, NULL, use_json);
7914
7915 }
7916
7917 if (use_json)
7918 vty_out (vty, "}%s", VTY_NEWLINE);
7919 }
7920
7921 /* Header of detailed BGP route information */
7922 static void
7923 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7924 struct bgp_node *rn,
7925 struct prefix_rd *prd, afi_t afi, safi_t safi,
7926 json_object *json)
7927 {
7928 struct bgp_info *ri;
7929 struct prefix *p;
7930 struct peer *peer;
7931 struct listnode *node, *nnode;
7932 char buf1[INET6_ADDRSTRLEN];
7933 char buf2[INET6_ADDRSTRLEN];
7934 int count = 0;
7935 int best = 0;
7936 int suppress = 0;
7937 int no_export = 0;
7938 int no_advertise = 0;
7939 int local_as = 0;
7940 int first = 1;
7941 json_object *json_adv_to = NULL;
7942
7943 p = &rn->p;
7944
7945 if (json)
7946 {
7947 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7948 json_object_int_add(json, "prefixlen", p->prefixlen);
7949 }
7950 else
7951 {
7952 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7953 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7954 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7955 safi == SAFI_MPLS_VPN ? ":" : "",
7956 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7957 p->prefixlen, VTY_NEWLINE);
7958 }
7959
7960 for (ri = rn->info; ri; ri = ri->next)
7961 {
7962 count++;
7963 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7964 {
7965 best = count;
7966 if (ri->extra && ri->extra->suppress)
7967 suppress = 1;
7968 if (ri->attr->community != NULL)
7969 {
7970 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7971 no_advertise = 1;
7972 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7973 no_export = 1;
7974 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7975 local_as = 1;
7976 }
7977 }
7978 }
7979
7980 if (!json)
7981 {
7982 vty_out (vty, "Paths: (%d available", count);
7983 if (best)
7984 {
7985 vty_out (vty, ", best #%d", best);
7986 if (safi == SAFI_UNICAST)
7987 vty_out (vty, ", table %s",
7988 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7989 ? "Default-IP-Routing-Table" : bgp->name);
7990 }
7991 else
7992 vty_out (vty, ", no best path");
7993
7994 if (no_advertise)
7995 vty_out (vty, ", not advertised to any peer");
7996 else if (no_export)
7997 vty_out (vty, ", not advertised to EBGP peer");
7998 else if (local_as)
7999 vty_out (vty, ", not advertised outside local AS");
8000
8001 if (suppress)
8002 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8003 vty_out (vty, ")%s", VTY_NEWLINE);
8004 }
8005
8006 /* If we are not using addpath then we can display Advertised to and that will
8007 * show what peers we advertised the bestpath to. If we are using addpath
8008 * though then we must display Advertised to on a path-by-path basis. */
8009 if (!bgp->addpath_tx_used[afi][safi])
8010 {
8011 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8012 {
8013 if (bgp_adj_out_lookup (peer, rn, 0))
8014 {
8015 if (json && !json_adv_to)
8016 json_adv_to = json_object_new_object();
8017
8018 route_vty_out_advertised_to(vty, peer, &first,
8019 " Advertised to non peer-group peers:\n ",
8020 json_adv_to);
8021 }
8022 }
8023
8024 if (json)
8025 {
8026 if (json_adv_to)
8027 {
8028 json_object_object_add(json, "advertisedTo", json_adv_to);
8029 }
8030 }
8031 else
8032 {
8033 if (first)
8034 vty_out (vty, " Not advertised to any peer");
8035 vty_out (vty, "%s", VTY_NEWLINE);
8036 }
8037 }
8038 }
8039
8040 /* Display specified route of BGP table. */
8041 static int
8042 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
8043 struct bgp_table *rib, const char *ip_str,
8044 afi_t afi, safi_t safi, struct prefix_rd *prd,
8045 int prefix_check, enum bgp_path_type pathtype,
8046 u_char use_json)
8047 {
8048 int ret;
8049 int header;
8050 int display = 0;
8051 struct prefix match;
8052 struct bgp_node *rn;
8053 struct bgp_node *rm;
8054 struct bgp_info *ri;
8055 struct bgp_table *table;
8056 json_object *json = NULL;
8057 json_object *json_paths = NULL;
8058
8059 /* Check IP address argument. */
8060 ret = str2prefix (ip_str, &match);
8061 if (! ret)
8062 {
8063 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8064 return CMD_WARNING;
8065 }
8066
8067 match.family = afi2family (afi);
8068
8069 if (use_json)
8070 {
8071 json = json_object_new_object();
8072 json_paths = json_object_new_array();
8073 }
8074
8075 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8076 {
8077 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8078 {
8079 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8080 continue;
8081
8082 if ((table = rn->info) != NULL)
8083 {
8084 header = 1;
8085
8086 if ((rm = bgp_node_match (table, &match)) != NULL)
8087 {
8088 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8089 {
8090 bgp_unlock_node (rm);
8091 continue;
8092 }
8093
8094 for (ri = rm->info; ri; ri = ri->next)
8095 {
8096 if (header)
8097 {
8098 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8099 AFI_IP, safi, json);
8100 header = 0;
8101 }
8102 display++;
8103
8104 if (pathtype == BGP_PATH_ALL ||
8105 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8106 (pathtype == BGP_PATH_MULTIPATH &&
8107 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8108 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8109 }
8110
8111 bgp_unlock_node (rm);
8112 }
8113 }
8114 }
8115 }
8116 else
8117 {
8118 header = 1;
8119
8120 if ((rn = bgp_node_match (rib, &match)) != NULL)
8121 {
8122 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8123 {
8124 for (ri = rn->info; ri; ri = ri->next)
8125 {
8126 if (header)
8127 {
8128 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8129 header = 0;
8130 }
8131 display++;
8132
8133 if (pathtype == BGP_PATH_ALL ||
8134 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8135 (pathtype == BGP_PATH_MULTIPATH &&
8136 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8137 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8138 }
8139 }
8140
8141 bgp_unlock_node (rn);
8142 }
8143 }
8144
8145 if (use_json)
8146 {
8147 if (display)
8148 json_object_object_add(json, "paths", json_paths);
8149
8150 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8151 json_object_free(json);
8152 }
8153 else
8154 {
8155 if (!display)
8156 {
8157 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8158 return CMD_WARNING;
8159 }
8160 }
8161
8162 return CMD_SUCCESS;
8163 }
8164
8165 /* Display specified route of Main RIB */
8166 static int
8167 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8168 afi_t afi, safi_t safi, struct prefix_rd *prd,
8169 int prefix_check, enum bgp_path_type pathtype,
8170 u_char use_json)
8171 {
8172 struct bgp *bgp;
8173
8174 /* BGP structure lookup. */
8175 if (view_name)
8176 {
8177 bgp = bgp_lookup_by_name (view_name);
8178 if (bgp == NULL)
8179 {
8180 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8181 return CMD_WARNING;
8182 }
8183 }
8184 else
8185 {
8186 bgp = bgp_get_default ();
8187 if (bgp == NULL)
8188 {
8189 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8190 return CMD_WARNING;
8191 }
8192 }
8193
8194 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8195 afi, safi, prd, prefix_check, pathtype,
8196 use_json);
8197 }
8198
8199 /* BGP route print out function. */
8200 DEFUN (show_ip_bgp,
8201 show_ip_bgp_cmd,
8202 "show ip bgp {json}",
8203 SHOW_STR
8204 IP_STR
8205 BGP_STR
8206 "JavaScript Object Notation\n")
8207 {
8208 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8209 }
8210
8211 DEFUN (show_ip_bgp_ipv4,
8212 show_ip_bgp_ipv4_cmd,
8213 "show ip bgp ipv4 (unicast|multicast) {json}",
8214 SHOW_STR
8215 IP_STR
8216 BGP_STR
8217 "Address family\n"
8218 "Address Family modifier\n"
8219 "Address Family modifier\n"
8220 "JavaScript Object Notation\n")
8221 {
8222 u_char uj = use_json(argc, argv);
8223
8224 return bgp_show (vty, NULL, AFI_IP,
8225 bgp_vty_safi_from_arg(argv[0]),
8226 bgp_show_type_normal, NULL, uj);
8227 }
8228
8229 ALIAS (show_ip_bgp_ipv4,
8230 show_bgp_ipv4_safi_cmd,
8231 "show bgp ipv4 (unicast|multicast) {json}",
8232 SHOW_STR
8233 BGP_STR
8234 "Address family\n"
8235 "Address Family modifier\n"
8236 "Address Family modifier\n"
8237 "JavaScript Object Notation\n")
8238
8239 DEFUN (show_ip_bgp_route,
8240 show_ip_bgp_route_cmd,
8241 "show ip bgp A.B.C.D {json}",
8242 SHOW_STR
8243 IP_STR
8244 BGP_STR
8245 "Network in the BGP routing table to display\n"
8246 "JavaScript Object Notation\n")
8247 {
8248 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8249 }
8250
8251 DEFUN (show_ip_bgp_route_pathtype,
8252 show_ip_bgp_route_pathtype_cmd,
8253 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8254 SHOW_STR
8255 IP_STR
8256 BGP_STR
8257 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8258 "Display only the bestpath\n"
8259 "Display only multipaths\n"
8260 "JavaScript Object Notation\n")
8261 {
8262 u_char uj = use_json(argc, argv);
8263
8264 if (strncmp (argv[1], "b", 1) == 0)
8265 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8266 else
8267 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8268 }
8269
8270 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8271 show_bgp_ipv4_safi_route_pathtype_cmd,
8272 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}",
8273 SHOW_STR
8274 BGP_STR
8275 BGP_AFI_SAFI_HELP_STR
8276 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8277 "Display only the bestpath\n"
8278 "Display only multipaths\n"
8279 "JavaScript Object Notation\n")
8280 {
8281 u_char uj = use_json(argc, argv);
8282
8283 if (strncmp (argv[2], "b", 1) == 0)
8284 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8285 bgp_vty_safi_from_arg(argv[0]),
8286 NULL, 0, BGP_PATH_BESTPATH, uj);
8287 else
8288 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8289 bgp_vty_safi_from_arg(argv[0]),
8290 NULL, 0, BGP_PATH_MULTIPATH, uj);
8291 }
8292
8293 DEFUN (show_bgp_ipv4_prefix,
8294 show_bgp_ipv4_prefix_cmd,
8295 "show bgp ipv4 A.B.C.D/M {json}",
8296 SHOW_STR
8297 BGP_STR
8298 IP_STR
8299 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8300 JSON_STR)
8301 {
8302 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8303 }
8304
8305 DEFUN (show_bgp_ipv6_route,
8306 show_bgp_ipv6_route_cmd,
8307 "show bgp ipv6 X:X::X:X {json}",
8308 SHOW_STR
8309 BGP_STR
8310 "Address family\n"
8311 "Network in the BGP routing table to display\n"
8312 JSON_STR)
8313 {
8314 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8315 }
8316
8317 DEFUN (show_bgp_ipv6_prefix,
8318 show_bgp_ipv6_prefix_cmd,
8319 "show bgp ipv6 X:X::X:X/M {json}",
8320 SHOW_STR
8321 BGP_STR
8322 IP_STR
8323 "IPv6 prefix <network>/<length>\n"
8324 JSON_STR)
8325 {
8326 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8327 }
8328
8329 DEFUN (show_ip_bgp_ipv4_route,
8330 show_ip_bgp_ipv4_route_cmd,
8331 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8332 SHOW_STR
8333 IP_STR
8334 BGP_STR
8335 BGP_AFI_SAFI_HELP_STR
8336 "Network in the BGP routing table to display\n"
8337 "JavaScript Object Notation\n")
8338 {
8339 u_char uj = use_json(argc, argv);
8340
8341 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8342 bgp_vty_safi_from_arg(argv[0]),
8343 NULL, 0, BGP_PATH_ALL, uj);
8344 }
8345
8346 ALIAS (show_ip_bgp_ipv4_route,
8347 show_bgp_ipv4_safi_route_cmd,
8348 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8349 SHOW_STR
8350 BGP_STR
8351 BGP_AFI_SAFI_HELP_STR
8352 "Network in the BGP routing table to display\n"
8353 "JavaScript Object Notation\n")
8354
8355 DEFUN (show_bgp_ipv4_safi_rd_route,
8356 show_bgp_ipv4_safi_rd_route_cmd,
8357 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8358 SHOW_STR
8359 BGP_STR
8360 "Address Family\n"
8361 "Address Family Modifier\n"
8362 "Address Family Modifier\n"
8363 "Display information for a route distinguisher\n"
8364 "ENCAP Route Distinguisher\n"
8365 "Network in the BGP routing table to display\n")
8366 {
8367 int ret;
8368 struct prefix_rd prd;
8369 safi_t safi;
8370
8371 if (bgp_parse_safi(argv[0], &safi)) {
8372 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8373 return CMD_WARNING;
8374 }
8375 ret = str2prefix_rd (argv[1], &prd);
8376 if (! ret)
8377 {
8378 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8379 return CMD_WARNING;
8380 }
8381 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8382 }
8383
8384 DEFUN (show_bgp_ipv6_safi_rd_route,
8385 show_bgp_ipv6_safi_rd_route_cmd,
8386 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8387 SHOW_STR
8388 BGP_STR
8389 "Address Family\n"
8390 "Address Family Modifier\n"
8391 "Address Family Modifier\n"
8392 "Display information for a route distinguisher\n"
8393 "ENCAP Route Distinguisher\n"
8394 "Network in the BGP routing table to display\n")
8395 {
8396 int ret;
8397 struct prefix_rd prd;
8398 safi_t safi;
8399
8400 if (bgp_parse_safi(argv[0], &safi)) {
8401 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8402 return CMD_WARNING;
8403 }
8404 ret = str2prefix_rd (argv[1], &prd);
8405 if (! ret)
8406 {
8407 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8408 return CMD_WARNING;
8409 }
8410 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8411 }
8412
8413
8414 DEFUN (show_bgp_ipv4_safi_rd_prefix,
8415 show_bgp_ipv4_safi_rd_prefix_cmd,
8416 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8417 SHOW_STR
8418 BGP_STR
8419 "Address Family\n"
8420 "Address Family Modifier\n"
8421 "Address Family Modifier\n"
8422 "Display information for a route distinguisher\n"
8423 "ENCAP Route Distinguisher\n"
8424 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8425 {
8426 int ret;
8427 struct prefix_rd prd;
8428 safi_t safi;
8429
8430 if (bgp_parse_safi(argv[0], &safi)) {
8431 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8432 return CMD_WARNING;
8433 }
8434
8435 ret = str2prefix_rd (argv[1], &prd);
8436 if (! ret)
8437 {
8438 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8439 return CMD_WARNING;
8440 }
8441 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8442 }
8443
8444 DEFUN (show_bgp_ipv6_safi_rd_prefix,
8445 show_bgp_ipv6_safi_rd_prefix_cmd,
8446 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}",
8447 SHOW_STR
8448 BGP_STR
8449 "Address Family\n"
8450 "Address Family Modifier\n"
8451 "Address Family Modifier\n"
8452 "Display information for a route distinguisher\n"
8453 "ENCAP Route Distinguisher\n"
8454 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8455 {
8456 int ret;
8457 struct prefix_rd prd;
8458 safi_t safi;
8459
8460 if (bgp_parse_safi(argv[0], &safi)) {
8461 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8462 return CMD_WARNING;
8463 }
8464
8465 ret = str2prefix_rd (argv[1], &prd);
8466 if (! ret)
8467 {
8468 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8469 return CMD_WARNING;
8470 }
8471 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8472 }
8473
8474 DEFUN (show_ip_bgp_prefix,
8475 show_ip_bgp_prefix_cmd,
8476 "show ip bgp A.B.C.D/M {json}",
8477 SHOW_STR
8478 IP_STR
8479 BGP_STR
8480 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8481 "JavaScript Object Notation\n")
8482 {
8483 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8484 }
8485
8486 DEFUN (show_ip_bgp_prefix_pathtype,
8487 show_ip_bgp_prefix_pathtype_cmd,
8488 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8489 SHOW_STR
8490 IP_STR
8491 BGP_STR
8492 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8493 "Display only the bestpath\n"
8494 "Display only multipaths\n"
8495 "JavaScript Object Notation\n")
8496 {
8497 u_char uj = use_json(argc, argv);
8498 if (strncmp (argv[1], "b", 1) == 0)
8499 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8500 else
8501 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8502 }
8503
8504 DEFUN (show_ip_bgp_ipv4_prefix,
8505 show_ip_bgp_ipv4_prefix_cmd,
8506 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8507 SHOW_STR
8508 IP_STR
8509 BGP_STR
8510 BGP_AFI_SAFI_HELP_STR
8511 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8512 "JavaScript Object Notation\n")
8513 {
8514 u_char uj = use_json(argc, argv);
8515
8516 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8517 bgp_vty_safi_from_arg(argv[0]),
8518 NULL, 1, BGP_PATH_ALL, uj);
8519 }
8520
8521 ALIAS (show_ip_bgp_ipv4_prefix,
8522 show_bgp_ipv4_safi_prefix_cmd,
8523 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8524 SHOW_STR
8525 BGP_STR
8526 BGP_AFI_SAFI_HELP_STR
8527 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8528 "JavaScript Object Notation\n")
8529
8530 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8531 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8532 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8533 SHOW_STR
8534 IP_STR
8535 BGP_STR
8536 BGP_AFI_SAFI_HELP_STR
8537 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8538 "Display only the bestpath\n"
8539 "Display only multipaths\n"
8540 "JavaScript Object Notation\n")
8541 {
8542 u_char uj = use_json(argc, argv);
8543
8544 if (strncmp (argv[2], "b", 1) == 0)
8545 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8546 bgp_vty_safi_from_arg(argv[0]),
8547 NULL, 1, BGP_PATH_BESTPATH, uj);
8548 else
8549 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8550 bgp_vty_safi_from_arg(argv[0]),
8551 NULL, 1, BGP_PATH_MULTIPATH, uj);
8552 }
8553
8554 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8555 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8556 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8557 SHOW_STR
8558 BGP_STR
8559 BGP_AFI_SAFI_HELP_STR
8560 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8561 "Display only the bestpath\n"
8562 "Display only multipaths\n"
8563 "JavaScript Object Notation\n")
8564
8565
8566 DEFUN (show_ip_bgp_view,
8567 show_ip_bgp_instance_cmd,
8568 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8569 SHOW_STR
8570 IP_STR
8571 BGP_STR
8572 BGP_INSTANCE_HELP_STR
8573 "JavaScript Object Notation\n")
8574 {
8575 struct bgp *bgp;
8576
8577 /* BGP structure lookup. */
8578 bgp = bgp_lookup_by_name (argv[1]);
8579 if (bgp == NULL)
8580 {
8581 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8582 return CMD_WARNING;
8583 }
8584
8585 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8586 }
8587
8588 DEFUN (show_ip_bgp_instance_all,
8589 show_ip_bgp_instance_all_cmd,
8590 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8591 SHOW_STR
8592 IP_STR
8593 BGP_STR
8594 BGP_INSTANCE_ALL_HELP_STR
8595 "JavaScript Object Notation\n")
8596 {
8597 u_char uj = use_json(argc, argv);
8598
8599 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8600 return CMD_SUCCESS;
8601 }
8602
8603 DEFUN (show_ip_bgp_instance_route,
8604 show_ip_bgp_instance_route_cmd,
8605 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8606 SHOW_STR
8607 IP_STR
8608 BGP_STR
8609 BGP_INSTANCE_HELP_STR
8610 "Network in the BGP routing table to display\n"
8611 "JavaScript Object Notation\n")
8612 {
8613 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8614 }
8615
8616 DEFUN (show_ip_bgp_instance_route_pathtype,
8617 show_ip_bgp_instance_route_pathtype_cmd,
8618 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8619 SHOW_STR
8620 IP_STR
8621 BGP_STR
8622 BGP_INSTANCE_HELP_STR
8623 "Network in the BGP routing table to display\n"
8624 "Display only the bestpath\n"
8625 "Display only multipaths\n"
8626 "JavaScript Object Notation\n")
8627 {
8628 u_char uj = use_json(argc, argv);
8629
8630 if (strncmp (argv[3], "b", 1) == 0)
8631 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8632 else
8633 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8634 }
8635
8636 DEFUN (show_ip_bgp_instance_prefix,
8637 show_ip_bgp_instance_prefix_cmd,
8638 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8639 SHOW_STR
8640 IP_STR
8641 BGP_STR
8642 BGP_INSTANCE_HELP_STR
8643 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8644 "JavaScript Object Notation\n")
8645 {
8646 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8647 }
8648
8649 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8650 show_ip_bgp_instance_prefix_pathtype_cmd,
8651 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8652 SHOW_STR
8653 IP_STR
8654 BGP_STR
8655 BGP_INSTANCE_HELP_STR
8656 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8657 "Display only the bestpath\n"
8658 "Display only multipaths\n"
8659 "JavaScript Object Notation\n")
8660 {
8661 u_char uj = use_json(argc, argv);
8662 if (strncmp (argv[3], "b", 1) == 0)
8663 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8664 else
8665 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8666 }
8667
8668 #ifdef HAVE_IPV6
8669 DEFUN (show_bgp,
8670 show_bgp_cmd,
8671 "show bgp {json}",
8672 SHOW_STR
8673 BGP_STR
8674 "JavaScript Object Notation\n")
8675 {
8676 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8677 NULL, use_json(argc, argv));
8678 }
8679
8680 ALIAS (show_bgp,
8681 show_bgp_ipv6_cmd,
8682 "show bgp ipv6 {json}",
8683 SHOW_STR
8684 BGP_STR
8685 "Address family\n"
8686 "JavaScript Object Notation\n")
8687
8688 DEFUN (show_bgp_ipv6_safi,
8689 show_bgp_ipv6_safi_cmd,
8690 "show bgp ipv6 (unicast|multicast) {json}",
8691 SHOW_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Address Family modifier\n"
8695 "Address Family modifier\n"
8696 "JavaScript Object Notation\n")
8697 {
8698 u_char uj = use_json(argc, argv);
8699
8700 return bgp_show (vty, NULL, AFI_IP6,
8701 bgp_vty_safi_from_arg(argv[0]),
8702 bgp_show_type_normal, NULL, uj);
8703 }
8704
8705 static void
8706 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8707 {
8708 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8709 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8710 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8711 }
8712
8713 /* old command */
8714 DEFUN (show_ipv6_bgp,
8715 show_ipv6_bgp_cmd,
8716 "show ipv6 bgp {json}",
8717 SHOW_STR
8718 IP_STR
8719 BGP_STR
8720 "JavaScript Object Notation\n")
8721 {
8722 bgp_show_ipv6_bgp_deprecate_warning(vty);
8723 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8724 NULL, use_json(argc, argv));
8725 }
8726
8727 DEFUN (show_bgp_route,
8728 show_bgp_route_cmd,
8729 "show bgp X:X::X:X {json}",
8730 SHOW_STR
8731 BGP_STR
8732 "Network in the BGP routing table to display\n"
8733 "JavaScript Object Notation\n")
8734 {
8735 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8736 }
8737
8738 DEFUN (show_bgp_ipv6_safi_route,
8739 show_bgp_ipv6_safi_route_cmd,
8740 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}",
8741 SHOW_STR
8742 BGP_STR
8743 BGP_AFI_SAFI_HELP_STR
8744 "Network in the BGP routing table to display\n"
8745 "JavaScript Object Notation\n")
8746 {
8747 u_char uj = use_json(argc, argv);
8748
8749 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8750 bgp_vty_safi_from_arg(argv[0]),
8751 NULL, 0, BGP_PATH_ALL, uj);
8752 }
8753
8754 DEFUN (show_bgp_route_pathtype,
8755 show_bgp_route_pathtype_cmd,
8756 "show bgp X:X::X:X (bestpath|multipath) {json}",
8757 SHOW_STR
8758 BGP_STR
8759 "Network in the BGP routing table to display\n"
8760 "Display only the bestpath\n"
8761 "Display only multipaths\n"
8762 "JavaScript Object Notation\n")
8763 {
8764 u_char uj = use_json(argc, argv);
8765 if (strncmp (argv[1], "b", 1) == 0)
8766 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8767 else
8768 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8769 }
8770
8771 ALIAS (show_bgp_route_pathtype,
8772 show_bgp_ipv6_route_pathtype_cmd,
8773 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8774 SHOW_STR
8775 BGP_STR
8776 "Address family\n"
8777 "Network in the BGP routing table to display\n"
8778 "Display only the bestpath\n"
8779 "Display only multipaths\n"
8780 "JavaScript Object Notation\n")
8781
8782 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8783 show_bgp_ipv6_safi_route_pathtype_cmd,
8784 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}",
8785 SHOW_STR
8786 BGP_STR
8787 BGP_AFI_SAFI_HELP_STR
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 u_char uj = use_json(argc, argv);
8794 if (strncmp (argv[2], "b", 1) == 0)
8795 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8796 bgp_vty_safi_from_arg(argv[0]),
8797 NULL, 0, BGP_PATH_BESTPATH, uj);
8798 else
8799 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8800 bgp_vty_safi_from_arg(argv[0]),
8801 NULL, 0, BGP_PATH_MULTIPATH, uj);
8802 }
8803
8804 /* old command */
8805 DEFUN (show_ipv6_bgp_route,
8806 show_ipv6_bgp_route_cmd,
8807 "show ipv6 bgp X:X::X:X {json}",
8808 SHOW_STR
8809 IP_STR
8810 BGP_STR
8811 "Network in the BGP routing table to display\n"
8812 "JavaScript Object Notation\n")
8813 {
8814 bgp_show_ipv6_bgp_deprecate_warning(vty);
8815 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8816 }
8817
8818 DEFUN (show_bgp_prefix,
8819 show_bgp_prefix_cmd,
8820 "show bgp X:X::X:X/M {json}",
8821 SHOW_STR
8822 BGP_STR
8823 "IPv6 prefix <network>/<length>\n"
8824 "JavaScript Object Notation\n")
8825 {
8826 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8827 }
8828
8829 DEFUN (show_bgp_ipv6_safi_prefix,
8830 show_bgp_ipv6_safi_prefix_cmd,
8831 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}",
8832 SHOW_STR
8833 BGP_STR
8834 BGP_AFI_SAFI_HELP_STR
8835 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8836 "JavaScript Object Notation\n")
8837 {
8838 u_char uj = use_json(argc, argv);
8839
8840 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8841 bgp_vty_safi_from_arg(argv[0]),
8842 NULL, 1, BGP_PATH_ALL, uj);
8843 }
8844
8845 DEFUN (show_bgp_prefix_pathtype,
8846 show_bgp_prefix_pathtype_cmd,
8847 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8848 SHOW_STR
8849 BGP_STR
8850 "IPv6 prefix <network>/<length>\n"
8851 "Display only the bestpath\n"
8852 "Display only multipaths\n"
8853 "JavaScript Object Notation\n")
8854 {
8855 u_char uj = use_json(argc, argv);
8856 if (strncmp (argv[1], "b", 1) == 0)
8857 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8858 else
8859 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8860 }
8861
8862 ALIAS (show_bgp_prefix_pathtype,
8863 show_bgp_ipv6_prefix_pathtype_cmd,
8864 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8865 SHOW_STR
8866 BGP_STR
8867 "Address family\n"
8868 "IPv6 prefix <network>/<length>\n"
8869 "Display only the bestpath\n"
8870 "Display only multipaths\n"
8871 "JavaScript Object Notation\n")
8872
8873 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8874 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8875 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}",
8876 SHOW_STR
8877 BGP_STR
8878 BGP_AFI_SAFI_HELP_STR
8879 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8880 "Display only the bestpath\n"
8881 "Display only multipaths\n"
8882 "JavaScript Object Notation\n")
8883 {
8884 u_char uj = use_json(argc, argv);
8885 if (strncmp (argv[2], "b", 1) == 0)
8886 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8887 bgp_vty_safi_from_arg(argv[0]),
8888 NULL, 1, BGP_PATH_BESTPATH, uj);
8889 else
8890 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8891 bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj);
8892 }
8893
8894 /* old command */
8895 DEFUN (show_ipv6_bgp_prefix,
8896 show_ipv6_bgp_prefix_cmd,
8897 "show ipv6 bgp X:X::X:X/M {json}",
8898 SHOW_STR
8899 IP_STR
8900 BGP_STR
8901 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8902 "JavaScript Object Notation\n")
8903 {
8904 bgp_show_ipv6_bgp_deprecate_warning(vty);
8905 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8906 }
8907
8908 DEFUN (show_bgp_view,
8909 show_bgp_instance_cmd,
8910 "show bgp " BGP_INSTANCE_CMD " {json}",
8911 SHOW_STR
8912 BGP_STR
8913 BGP_INSTANCE_HELP_STR
8914 "JavaScript Object Notation\n")
8915 {
8916 struct bgp *bgp;
8917
8918 /* BGP structure lookup. */
8919 bgp = bgp_lookup_by_name (argv[1]);
8920 if (bgp == NULL)
8921 {
8922 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8923 return CMD_WARNING;
8924 }
8925
8926 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8927 }
8928
8929 DEFUN (show_bgp_instance_all,
8930 show_bgp_instance_all_cmd,
8931 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8932 SHOW_STR
8933 BGP_STR
8934 BGP_INSTANCE_ALL_HELP_STR
8935 "JavaScript Object Notation\n")
8936 {
8937 u_char uj = use_json(argc, argv);
8938
8939 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8940 return CMD_SUCCESS;
8941 }
8942
8943 ALIAS (show_bgp_view,
8944 show_bgp_instance_ipv6_cmd,
8945 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8946 SHOW_STR
8947 BGP_STR
8948 BGP_INSTANCE_HELP_STR
8949 "Address family\n"
8950 "JavaScript Object Notation\n")
8951
8952 DEFUN (show_bgp_instance_route,
8953 show_bgp_instance_route_cmd,
8954 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8955 SHOW_STR
8956 BGP_STR
8957 BGP_INSTANCE_HELP_STR
8958 "Network in the BGP routing table to display\n"
8959 "JavaScript Object Notation\n")
8960 {
8961 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8962 }
8963
8964 ALIAS (show_bgp_instance_route,
8965 show_bgp_instance_ipv6_route_cmd,
8966 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8967 SHOW_STR
8968 BGP_STR
8969 BGP_INSTANCE_HELP_STR
8970 "Address family\n"
8971 "Network in the BGP routing table to display\n"
8972 "JavaScript Object Notation\n")
8973
8974 DEFUN (show_bgp_instance_route_pathtype,
8975 show_bgp_instance_route_pathtype_cmd,
8976 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8977 SHOW_STR
8978 BGP_STR
8979 BGP_INSTANCE_HELP_STR
8980 "Network in the BGP routing table to display\n"
8981 "Display only the bestpath\n"
8982 "Display only multipaths\n"
8983 "JavaScript Object Notation\n")
8984 {
8985 u_char uj = use_json(argc, argv);
8986 if (strncmp (argv[3], "b", 1) == 0)
8987 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8988 else
8989 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8990 }
8991
8992 ALIAS (show_bgp_instance_route_pathtype,
8993 show_bgp_instance_ipv6_route_pathtype_cmd,
8994 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8995 SHOW_STR
8996 BGP_STR
8997 BGP_INSTANCE_HELP_STR
8998 "Address family\n"
8999 "Network in the BGP routing table to display\n"
9000 "Display only the bestpath\n"
9001 "Display only multipaths\n"
9002 "JavaScript Object Notation\n")
9003
9004 DEFUN (show_bgp_instance_prefix,
9005 show_bgp_instance_prefix_cmd,
9006 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
9007 SHOW_STR
9008 BGP_STR
9009 BGP_INSTANCE_HELP_STR
9010 "IPv6 prefix <network>/<length>\n"
9011 "JavaScript Object Notation\n")
9012 {
9013 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9014 }
9015
9016 ALIAS (show_bgp_instance_prefix,
9017 show_bgp_instance_ipv6_prefix_cmd,
9018 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
9019 SHOW_STR
9020 BGP_STR
9021 BGP_INSTANCE_HELP_STR
9022 "Address family\n"
9023 "IPv6 prefix <network>/<length>\n"
9024 "JavaScript Object Notation\n")
9025
9026 DEFUN (show_bgp_instance_prefix_pathtype,
9027 show_bgp_instance_prefix_pathtype_cmd,
9028 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
9029 SHOW_STR
9030 BGP_STR
9031 BGP_INSTANCE_HELP_STR
9032 "IPv6 prefix <network>/<length>\n"
9033 "Display only the bestpath\n"
9034 "Display only multipaths\n"
9035 "JavaScript Object Notation\n")
9036 {
9037 u_char uj = use_json(argc, argv);
9038 if (strncmp (argv[3], "b", 1) == 0)
9039 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9040 else
9041 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9042 }
9043
9044 ALIAS (show_bgp_instance_prefix_pathtype,
9045 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9046 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
9047 SHOW_STR
9048 BGP_STR
9049 BGP_INSTANCE_HELP_STR
9050 "Address family\n"
9051 "IPv6 prefix <network>/<length>\n"
9052 "Display only the bestpath\n"
9053 "Display only multipaths\n"
9054 "JavaScript Object Notation\n")
9055
9056 DEFUN (show_bgp_instance_prefix_list,
9057 show_bgp_instance_prefix_list_cmd,
9058 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9059 SHOW_STR
9060 BGP_STR
9061 BGP_INSTANCE_HELP_STR
9062 "Display routes conforming to the prefix-list\n"
9063 "IPv6 prefix-list name\n")
9064 {
9065 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9066 bgp_show_type_prefix_list);
9067 }
9068
9069 ALIAS (show_bgp_instance_prefix_list,
9070 show_bgp_instance_ipv6_prefix_list_cmd,
9071 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9072 SHOW_STR
9073 BGP_STR
9074 BGP_INSTANCE_HELP_STR
9075 "Address family\n"
9076 "Display routes conforming to the prefix-list\n"
9077 "IPv6 prefix-list name\n")
9078
9079 DEFUN (show_bgp_instance_filter_list,
9080 show_bgp_instance_filter_list_cmd,
9081 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9082 SHOW_STR
9083 BGP_STR
9084 BGP_INSTANCE_HELP_STR
9085 "Display routes conforming to the filter-list\n"
9086 "Regular expression access list name\n")
9087 {
9088 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9089 bgp_show_type_filter_list);
9090 }
9091
9092 ALIAS (show_bgp_instance_filter_list,
9093 show_bgp_instance_ipv6_filter_list_cmd,
9094 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9095 SHOW_STR
9096 BGP_STR
9097 BGP_INSTANCE_HELP_STR
9098 "Address family\n"
9099 "Display routes conforming to the filter-list\n"
9100 "Regular expression access list name\n")
9101
9102 DEFUN (show_bgp_instance_route_map,
9103 show_bgp_instance_route_map_cmd,
9104 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9105 SHOW_STR
9106 BGP_STR
9107 BGP_INSTANCE_HELP_STR
9108 "Display routes matching the route-map\n"
9109 "A route-map to match on\n")
9110 {
9111 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9112 bgp_show_type_route_map);
9113 }
9114
9115 ALIAS (show_bgp_instance_route_map,
9116 show_bgp_instance_ipv6_route_map_cmd,
9117 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9118 SHOW_STR
9119 BGP_STR
9120 BGP_INSTANCE_HELP_STR
9121 "Address family\n"
9122 "Display routes matching the route-map\n"
9123 "A route-map to match on\n")
9124
9125 DEFUN (show_bgp_instance_community_list,
9126 show_bgp_instance_community_list_cmd,
9127 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9128 SHOW_STR
9129 BGP_STR
9130 BGP_INSTANCE_HELP_STR
9131 "Display routes matching the community-list\n"
9132 "community-list number\n"
9133 "community-list name\n")
9134 {
9135 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9136 }
9137
9138 ALIAS (show_bgp_instance_community_list,
9139 show_bgp_instance_ipv6_community_list_cmd,
9140 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9141 SHOW_STR
9142 BGP_STR
9143 BGP_INSTANCE_HELP_STR
9144 "Address family\n"
9145 "Display routes matching the community-list\n"
9146 "community-list number\n"
9147 "community-list name\n")
9148
9149 DEFUN (show_bgp_instance_prefix_longer,
9150 show_bgp_instance_prefix_longer_cmd,
9151 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9152 SHOW_STR
9153 BGP_STR
9154 BGP_INSTANCE_HELP_STR
9155 "IPv6 prefix <network>/<length>\n"
9156 "Display route and more specific routes\n")
9157 {
9158 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9159 bgp_show_type_prefix_longer);
9160 }
9161
9162 ALIAS (show_bgp_instance_prefix_longer,
9163 show_bgp_instance_ipv6_prefix_longer_cmd,
9164 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9165 SHOW_STR
9166 BGP_STR
9167 BGP_INSTANCE_HELP_STR
9168 "Address family\n"
9169 "IPv6 prefix <network>/<length>\n"
9170 "Display route and more specific routes\n")
9171
9172 /* old command */
9173 DEFUN (show_ipv6_mbgp,
9174 show_ipv6_mbgp_cmd,
9175 "show ipv6 mbgp {json}",
9176 SHOW_STR
9177 IP_STR
9178 MBGP_STR
9179 "JavaScript Object Notation\n")
9180 {
9181 bgp_show_ipv6_bgp_deprecate_warning(vty);
9182 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9183 NULL, use_json(argc, argv));
9184 }
9185
9186 /* old command */
9187 DEFUN (show_ipv6_mbgp_route,
9188 show_ipv6_mbgp_route_cmd,
9189 "show ipv6 mbgp X:X::X:X {json}",
9190 SHOW_STR
9191 IP_STR
9192 MBGP_STR
9193 "Network in the MBGP routing table to display\n"
9194 "JavaScript Object Notation\n")
9195 {
9196 bgp_show_ipv6_bgp_deprecate_warning(vty);
9197 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9198 }
9199
9200 /* old command */
9201 DEFUN (show_ipv6_mbgp_prefix,
9202 show_ipv6_mbgp_prefix_cmd,
9203 "show ipv6 mbgp X:X::X:X/M {json}",
9204 SHOW_STR
9205 IP_STR
9206 MBGP_STR
9207 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9208 "JavaScript Object Notation\n")
9209 {
9210 bgp_show_ipv6_bgp_deprecate_warning(vty);
9211 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9212 }
9213 #endif
9214
9215
9216 static int
9217 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9218 safi_t safi, enum bgp_show_type type)
9219 {
9220 int i;
9221 struct buffer *b;
9222 char *regstr;
9223 int first;
9224 regex_t *regex;
9225 int rc;
9226
9227 first = 0;
9228 b = buffer_new (1024);
9229 for (i = 0; i < argc; i++)
9230 {
9231 if (first)
9232 buffer_putc (b, ' ');
9233 else
9234 {
9235 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9236 continue;
9237 first = 1;
9238 }
9239
9240 buffer_putstr (b, argv[i]);
9241 }
9242 buffer_putc (b, '\0');
9243
9244 regstr = buffer_getstr (b);
9245 buffer_free (b);
9246
9247 regex = bgp_regcomp (regstr);
9248 XFREE(MTYPE_TMP, regstr);
9249 if (! regex)
9250 {
9251 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9252 VTY_NEWLINE);
9253 return CMD_WARNING;
9254 }
9255
9256 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9257 bgp_regex_free (regex);
9258 return rc;
9259 }
9260
9261 DEFUN (show_ip_bgp_regexp,
9262 show_ip_bgp_regexp_cmd,
9263 "show ip bgp regexp .LINE",
9264 SHOW_STR
9265 IP_STR
9266 BGP_STR
9267 "Display routes matching the AS path regular expression\n"
9268 "A regular-expression to match the BGP AS paths\n")
9269 {
9270 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9271 bgp_show_type_regexp);
9272 }
9273
9274 DEFUN (show_ip_bgp_flap_regexp,
9275 show_ip_bgp_flap_regexp_cmd,
9276 "show ip bgp flap-statistics regexp .LINE",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Display flap statistics of routes\n"
9281 "Display routes matching the AS path regular expression\n"
9282 "A regular-expression to match the BGP AS paths\n")
9283 {
9284 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9285 bgp_show_type_flap_regexp);
9286 }
9287
9288 ALIAS (show_ip_bgp_flap_regexp,
9289 show_ip_bgp_damp_flap_regexp_cmd,
9290 "show ip bgp dampening flap-statistics regexp .LINE",
9291 SHOW_STR
9292 IP_STR
9293 BGP_STR
9294 "Display detailed information about dampening\n"
9295 "Display flap statistics of routes\n"
9296 "Display routes matching the AS path regular expression\n"
9297 "A regular-expression to match the BGP AS paths\n")
9298
9299 DEFUN (show_ip_bgp_ipv4_regexp,
9300 show_ip_bgp_ipv4_regexp_cmd,
9301 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Address family\n"
9306 "Address Family modifier\n"
9307 "Address Family modifier\n"
9308 "Display routes matching the AS path regular expression\n"
9309 "A regular-expression to match the BGP AS paths\n")
9310 {
9311 safi_t safi;
9312 safi = bgp_vty_safi_from_arg(argv[0]);
9313 return bgp_show_regexp (vty, argc, argv, AFI_IP, safi,
9314 bgp_show_type_regexp);
9315 }
9316
9317 #ifdef HAVE_IPV6
9318 DEFUN (show_bgp_regexp,
9319 show_bgp_regexp_cmd,
9320 "show bgp regexp .LINE",
9321 SHOW_STR
9322 BGP_STR
9323 "Display routes matching the AS path regular expression\n"
9324 "A regular-expression to match the BGP AS paths\n")
9325 {
9326 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9327 bgp_show_type_regexp);
9328 }
9329
9330 ALIAS (show_bgp_regexp,
9331 show_bgp_ipv6_regexp_cmd,
9332 "show bgp ipv6 regexp .LINE",
9333 SHOW_STR
9334 BGP_STR
9335 "Address family\n"
9336 "Display routes matching the AS path regular expression\n"
9337 "A regular-expression to match the BGP AS paths\n")
9338
9339 /* old command */
9340 DEFUN (show_ipv6_bgp_regexp,
9341 show_ipv6_bgp_regexp_cmd,
9342 "show ipv6 bgp regexp .LINE",
9343 SHOW_STR
9344 IP_STR
9345 BGP_STR
9346 "Display routes matching the AS path regular expression\n"
9347 "A regular-expression to match the BGP AS paths\n")
9348 {
9349 bgp_show_ipv6_bgp_deprecate_warning(vty);
9350 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9351 bgp_show_type_regexp);
9352 }
9353
9354 /* old command */
9355 DEFUN (show_ipv6_mbgp_regexp,
9356 show_ipv6_mbgp_regexp_cmd,
9357 "show ipv6 mbgp regexp .LINE",
9358 SHOW_STR
9359 IP_STR
9360 BGP_STR
9361 "Display routes matching the AS path regular expression\n"
9362 "A regular-expression to match the MBGP AS paths\n")
9363 {
9364 bgp_show_ipv6_bgp_deprecate_warning(vty);
9365 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9366 bgp_show_type_regexp);
9367 }
9368 #endif /* HAVE_IPV6 */
9369
9370 static int
9371 bgp_show_prefix_list (struct vty *vty, const char *name,
9372 const char *prefix_list_str, afi_t afi,
9373 safi_t safi, enum bgp_show_type type)
9374 {
9375 struct prefix_list *plist;
9376 struct bgp *bgp = NULL;
9377
9378 if (name && !(bgp = bgp_lookup_by_name(name)))
9379 {
9380 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9381 return CMD_WARNING;
9382 }
9383
9384 plist = prefix_list_lookup (afi, prefix_list_str);
9385 if (plist == NULL)
9386 {
9387 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9388 prefix_list_str, VTY_NEWLINE);
9389 return CMD_WARNING;
9390 }
9391
9392 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9393 }
9394
9395 DEFUN (show_ip_bgp_prefix_list,
9396 show_ip_bgp_prefix_list_cmd,
9397 "show ip bgp prefix-list WORD",
9398 SHOW_STR
9399 IP_STR
9400 BGP_STR
9401 "Display routes conforming to the prefix-list\n"
9402 "IP prefix-list name\n")
9403 {
9404 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9405 bgp_show_type_prefix_list);
9406 }
9407
9408 DEFUN (show_ip_bgp_instance_prefix_list,
9409 show_ip_bgp_instance_prefix_list_cmd,
9410 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9411 SHOW_STR
9412 IP_STR
9413 BGP_STR
9414 BGP_INSTANCE_HELP_STR
9415 "Display routes conforming to the prefix-list\n"
9416 "IP prefix-list name\n")
9417 {
9418 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9419 bgp_show_type_prefix_list);
9420 }
9421
9422 DEFUN (show_ip_bgp_flap_prefix_list,
9423 show_ip_bgp_flap_prefix_list_cmd,
9424 "show ip bgp flap-statistics prefix-list WORD",
9425 SHOW_STR
9426 IP_STR
9427 BGP_STR
9428 "Display flap statistics of routes\n"
9429 "Display routes conforming to the prefix-list\n"
9430 "IP prefix-list name\n")
9431 {
9432 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9433 bgp_show_type_flap_prefix_list);
9434 }
9435
9436 ALIAS (show_ip_bgp_flap_prefix_list,
9437 show_ip_bgp_damp_flap_prefix_list_cmd,
9438 "show ip bgp dampening flap-statistics prefix-list WORD",
9439 SHOW_STR
9440 IP_STR
9441 BGP_STR
9442 "Display detailed information about dampening\n"
9443 "Display flap statistics of routes\n"
9444 "Display routes conforming to the prefix-list\n"
9445 "IP prefix-list name\n")
9446
9447 DEFUN (show_ip_bgp_ipv4_prefix_list,
9448 show_ip_bgp_ipv4_prefix_list_cmd,
9449 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9450 SHOW_STR
9451 IP_STR
9452 BGP_STR
9453 "Address family\n"
9454 "Address Family modifier\n"
9455 "Address Family modifier\n"
9456 "Display routes conforming to the prefix-list\n"
9457 "IP prefix-list name\n")
9458 {
9459 safi_t safi;
9460 safi = bgp_vty_safi_from_arg(argv[0]);
9461 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi,
9462 bgp_show_type_prefix_list);
9463 }
9464
9465 #ifdef HAVE_IPV6
9466 DEFUN (show_bgp_prefix_list,
9467 show_bgp_prefix_list_cmd,
9468 "show bgp prefix-list WORD",
9469 SHOW_STR
9470 BGP_STR
9471 "Display routes conforming to the prefix-list\n"
9472 "IPv6 prefix-list name\n")
9473 {
9474 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9475 bgp_show_type_prefix_list);
9476 }
9477
9478 ALIAS (show_bgp_prefix_list,
9479 show_bgp_ipv6_prefix_list_cmd,
9480 "show bgp ipv6 prefix-list WORD",
9481 SHOW_STR
9482 BGP_STR
9483 "Address family\n"
9484 "Display routes conforming to the prefix-list\n"
9485 "IPv6 prefix-list name\n")
9486
9487 /* old command */
9488 DEFUN (show_ipv6_bgp_prefix_list,
9489 show_ipv6_bgp_prefix_list_cmd,
9490 "show ipv6 bgp prefix-list WORD",
9491 SHOW_STR
9492 IPV6_STR
9493 BGP_STR
9494 "Display routes matching the prefix-list\n"
9495 "IPv6 prefix-list name\n")
9496 {
9497 bgp_show_ipv6_bgp_deprecate_warning(vty);
9498 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9499 bgp_show_type_prefix_list);
9500 }
9501
9502 /* old command */
9503 DEFUN (show_ipv6_mbgp_prefix_list,
9504 show_ipv6_mbgp_prefix_list_cmd,
9505 "show ipv6 mbgp prefix-list WORD",
9506 SHOW_STR
9507 IPV6_STR
9508 MBGP_STR
9509 "Display routes matching the prefix-list\n"
9510 "IPv6 prefix-list name\n")
9511 {
9512 bgp_show_ipv6_bgp_deprecate_warning(vty);
9513 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9514 bgp_show_type_prefix_list);
9515 }
9516 #endif /* HAVE_IPV6 */
9517
9518 static int
9519 bgp_show_filter_list (struct vty *vty, const char *name,
9520 const char *filter, afi_t afi,
9521 safi_t safi, enum bgp_show_type type)
9522 {
9523 struct as_list *as_list;
9524 struct bgp *bgp = NULL;
9525
9526 if (name && !(bgp = bgp_lookup_by_name(name)))
9527 {
9528 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9529 return CMD_WARNING;
9530 }
9531
9532 as_list = as_list_lookup (filter);
9533 if (as_list == NULL)
9534 {
9535 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9536 return CMD_WARNING;
9537 }
9538
9539 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9540 }
9541
9542 DEFUN (show_ip_bgp_filter_list,
9543 show_ip_bgp_filter_list_cmd,
9544 "show ip bgp filter-list WORD",
9545 SHOW_STR
9546 IP_STR
9547 BGP_STR
9548 "Display routes conforming to the filter-list\n"
9549 "Regular expression access list name\n")
9550 {
9551 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9552 bgp_show_type_filter_list);
9553 }
9554
9555 DEFUN (show_ip_bgp_instance_filter_list,
9556 show_ip_bgp_instance_filter_list_cmd,
9557 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9558 SHOW_STR
9559 IP_STR
9560 BGP_STR
9561 BGP_INSTANCE_HELP_STR
9562 "Display routes conforming to the filter-list\n"
9563 "Regular expression access list name\n")
9564 {
9565 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9566 bgp_show_type_filter_list);
9567 }
9568
9569 DEFUN (show_ip_bgp_flap_filter_list,
9570 show_ip_bgp_flap_filter_list_cmd,
9571 "show ip bgp flap-statistics filter-list WORD",
9572 SHOW_STR
9573 IP_STR
9574 BGP_STR
9575 "Display flap statistics of routes\n"
9576 "Display routes conforming to the filter-list\n"
9577 "Regular expression access list name\n")
9578 {
9579 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9580 bgp_show_type_flap_filter_list);
9581 }
9582
9583 ALIAS (show_ip_bgp_flap_filter_list,
9584 show_ip_bgp_damp_flap_filter_list_cmd,
9585 "show ip bgp dampening flap-statistics filter-list WORD",
9586 SHOW_STR
9587 IP_STR
9588 BGP_STR
9589 "Display detailed information about dampening\n"
9590 "Display flap statistics of routes\n"
9591 "Display routes conforming to the filter-list\n"
9592 "Regular expression access list name\n")
9593
9594 DEFUN (show_ip_bgp_ipv4_filter_list,
9595 show_ip_bgp_ipv4_filter_list_cmd,
9596 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9597 SHOW_STR
9598 IP_STR
9599 BGP_STR
9600 "Address family\n"
9601 "Address Family modifier\n"
9602 "Address Family modifier\n"
9603 "Display routes conforming to the filter-list\n"
9604 "Regular expression access list name\n")
9605 {
9606 safi_t safi;
9607 safi = bgp_vty_safi_from_arg(argv[0]);
9608 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi,
9609 bgp_show_type_filter_list);
9610 }
9611
9612 #ifdef HAVE_IPV6
9613 DEFUN (show_bgp_filter_list,
9614 show_bgp_filter_list_cmd,
9615 "show bgp filter-list WORD",
9616 SHOW_STR
9617 BGP_STR
9618 "Display routes conforming to the filter-list\n"
9619 "Regular expression access list name\n")
9620 {
9621 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9622 bgp_show_type_filter_list);
9623 }
9624
9625 ALIAS (show_bgp_filter_list,
9626 show_bgp_ipv6_filter_list_cmd,
9627 "show bgp ipv6 filter-list WORD",
9628 SHOW_STR
9629 BGP_STR
9630 "Address family\n"
9631 "Display routes conforming to the filter-list\n"
9632 "Regular expression access list name\n")
9633
9634 /* old command */
9635 DEFUN (show_ipv6_bgp_filter_list,
9636 show_ipv6_bgp_filter_list_cmd,
9637 "show ipv6 bgp filter-list WORD",
9638 SHOW_STR
9639 IPV6_STR
9640 BGP_STR
9641 "Display routes conforming to the filter-list\n"
9642 "Regular expression access list name\n")
9643 {
9644 bgp_show_ipv6_bgp_deprecate_warning(vty);
9645 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9646 bgp_show_type_filter_list);
9647 }
9648
9649 /* old command */
9650 DEFUN (show_ipv6_mbgp_filter_list,
9651 show_ipv6_mbgp_filter_list_cmd,
9652 "show ipv6 mbgp filter-list WORD",
9653 SHOW_STR
9654 IPV6_STR
9655 MBGP_STR
9656 "Display routes conforming to the filter-list\n"
9657 "Regular expression access list name\n")
9658 {
9659 bgp_show_ipv6_bgp_deprecate_warning(vty);
9660 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9661 bgp_show_type_filter_list);
9662 }
9663 #endif /* HAVE_IPV6 */
9664
9665 DEFUN (show_ip_bgp_dampening_info,
9666 show_ip_bgp_dampening_params_cmd,
9667 "show ip bgp dampening parameters",
9668 SHOW_STR
9669 IP_STR
9670 BGP_STR
9671 "Display detailed information about dampening\n"
9672 "Display detail of configured dampening parameters\n")
9673 {
9674 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9675 }
9676
9677
9678 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9679 show_ip_bgp_ipv4_dampening_parameters_cmd,
9680 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
9681 SHOW_STR
9682 IP_STR
9683 BGP_STR
9684 "Address family\n"
9685 "Address Family modifier\n"
9686 "Address Family modifier\n"
9687 "Display detailed information about dampening\n"
9688 "Display detail of configured dampening parameters\n")
9689 {
9690 safi_t safi;
9691 safi = bgp_vty_safi_from_arg(argv[0]);
9692 return bgp_show_dampening_parameters (vty, AFI_IP, safi);
9693 }
9694
9695
9696 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9697 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9698 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
9699 SHOW_STR
9700 IP_STR
9701 BGP_STR
9702 "Address family\n"
9703 "Address Family modifier\n"
9704 "Address Family modifier\n"
9705 "Display detailed information about dampening\n"
9706 "Display flap statistics of routes\n")
9707 {
9708 safi_t safi;
9709 safi = bgp_vty_safi_from_arg(argv[0]);
9710 return bgp_show (vty, NULL, AFI_IP, safi,
9711 bgp_show_type_flap_statistics, NULL, 0);
9712 }
9713
9714 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9715 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9716 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
9717 SHOW_STR
9718 IP_STR
9719 BGP_STR
9720 "Address family\n"
9721 "Address Family modifier\n"
9722 "Address Family modifier\n"
9723 "Display detailed information about dampening\n"
9724 "Display paths suppressed due to dampening\n")
9725 {
9726 safi_t safi;
9727 safi = bgp_vty_safi_from_arg(argv[0]);
9728 return bgp_show (vty, NULL, AFI_IP, safi,
9729 bgp_show_type_dampend_paths, NULL, 0);
9730 }
9731
9732 static int
9733 bgp_show_route_map (struct vty *vty, const char *name,
9734 const char *rmap_str, afi_t afi,
9735 safi_t safi, enum bgp_show_type type)
9736 {
9737 struct route_map *rmap;
9738 struct bgp *bgp = NULL;
9739
9740 if (name && !(bgp = bgp_lookup_by_name(name)))
9741 {
9742 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9743 return CMD_WARNING;
9744 }
9745
9746 rmap = route_map_lookup_by_name (rmap_str);
9747 if (! rmap)
9748 {
9749 vty_out (vty, "%% %s is not a valid route-map name%s",
9750 rmap_str, VTY_NEWLINE);
9751 return CMD_WARNING;
9752 }
9753
9754 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9755 }
9756
9757 DEFUN (show_ip_bgp_route_map,
9758 show_ip_bgp_route_map_cmd,
9759 "show ip bgp route-map WORD",
9760 SHOW_STR
9761 IP_STR
9762 BGP_STR
9763 "Display routes matching the route-map\n"
9764 "A route-map to match on\n")
9765 {
9766 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9767 bgp_show_type_route_map);
9768 }
9769
9770 DEFUN (show_ip_bgp_instance_route_map,
9771 show_ip_bgp_instance_route_map_cmd,
9772 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9773 SHOW_STR
9774 IP_STR
9775 BGP_STR
9776 BGP_INSTANCE_HELP_STR
9777 "Display routes matching the route-map\n"
9778 "A route-map to match on\n")
9779 {
9780 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9781 bgp_show_type_route_map);
9782 }
9783
9784 DEFUN (show_ip_bgp_flap_route_map,
9785 show_ip_bgp_flap_route_map_cmd,
9786 "show ip bgp flap-statistics route-map WORD",
9787 SHOW_STR
9788 IP_STR
9789 BGP_STR
9790 "Display flap statistics of routes\n"
9791 "Display routes matching the route-map\n"
9792 "A route-map to match on\n")
9793 {
9794 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9795 bgp_show_type_flap_route_map);
9796 }
9797
9798 ALIAS (show_ip_bgp_flap_route_map,
9799 show_ip_bgp_damp_flap_route_map_cmd,
9800 "show ip bgp dampening flap-statistics route-map WORD",
9801 SHOW_STR
9802 IP_STR
9803 BGP_STR
9804 "Display detailed information about dampening\n"
9805 "Display flap statistics of routes\n"
9806 "Display routes matching the route-map\n"
9807 "A route-map to match on\n")
9808
9809 DEFUN (show_ip_bgp_ipv4_route_map,
9810 show_ip_bgp_ipv4_route_map_cmd,
9811 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9812 SHOW_STR
9813 IP_STR
9814 BGP_STR
9815 "Address family\n"
9816 "Address Family modifier\n"
9817 "Address Family modifier\n"
9818 "Display routes matching the route-map\n"
9819 "A route-map to match on\n")
9820 {
9821 safi_t safi;
9822 safi = bgp_vty_safi_from_arg(argv[0]);
9823 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi,
9824 bgp_show_type_route_map);
9825 }
9826
9827 DEFUN (show_bgp_route_map,
9828 show_bgp_route_map_cmd,
9829 "show bgp route-map WORD",
9830 SHOW_STR
9831 BGP_STR
9832 "Display routes matching the route-map\n"
9833 "A route-map to match on\n")
9834 {
9835 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9836 bgp_show_type_route_map);
9837 }
9838
9839 ALIAS (show_bgp_route_map,
9840 show_bgp_ipv6_route_map_cmd,
9841 "show bgp ipv6 route-map WORD",
9842 SHOW_STR
9843 BGP_STR
9844 "Address family\n"
9845 "Display routes matching the route-map\n"
9846 "A route-map to match on\n")
9847
9848 DEFUN (show_ip_bgp_cidr_only,
9849 show_ip_bgp_cidr_only_cmd,
9850 "show ip bgp cidr-only",
9851 SHOW_STR
9852 IP_STR
9853 BGP_STR
9854 "Display only routes with non-natural netmasks\n")
9855 {
9856 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9857 bgp_show_type_cidr_only, NULL, 0);
9858 }
9859
9860 DEFUN (show_ip_bgp_flap_cidr_only,
9861 show_ip_bgp_flap_cidr_only_cmd,
9862 "show ip bgp flap-statistics cidr-only",
9863 SHOW_STR
9864 IP_STR
9865 BGP_STR
9866 "Display flap statistics of routes\n"
9867 "Display only routes with non-natural netmasks\n")
9868 {
9869 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9870 bgp_show_type_flap_cidr_only, NULL, 0);
9871 }
9872
9873 ALIAS (show_ip_bgp_flap_cidr_only,
9874 show_ip_bgp_damp_flap_cidr_only_cmd,
9875 "show ip bgp dampening flap-statistics cidr-only",
9876 SHOW_STR
9877 IP_STR
9878 BGP_STR
9879 "Display detailed information about dampening\n"
9880 "Display flap statistics of routes\n"
9881 "Display only routes with non-natural netmasks\n")
9882
9883 DEFUN (show_ip_bgp_ipv4_cidr_only,
9884 show_ip_bgp_ipv4_cidr_only_cmd,
9885 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9886 SHOW_STR
9887 IP_STR
9888 BGP_STR
9889 "Address family\n"
9890 "Address Family modifier\n"
9891 "Address Family modifier\n"
9892 "Display only routes with non-natural netmasks\n")
9893 {
9894 safi_t safi;
9895 safi = bgp_vty_safi_from_arg(argv[0]);
9896 return bgp_show (vty, NULL, AFI_IP, safi,
9897 bgp_show_type_cidr_only, NULL, 0);
9898 }
9899
9900 DEFUN (show_ip_bgp_community_all,
9901 show_ip_bgp_community_all_cmd,
9902 "show ip bgp community",
9903 SHOW_STR
9904 IP_STR
9905 BGP_STR
9906 "Display routes matching the communities\n")
9907 {
9908 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9909 bgp_show_type_community_all, NULL, 0);
9910 }
9911
9912 DEFUN (show_ip_bgp_ipv4_community_all,
9913 show_ip_bgp_ipv4_community_all_cmd,
9914 "show ip bgp ipv4 (unicast|multicast) community",
9915 SHOW_STR
9916 IP_STR
9917 BGP_STR
9918 "Address family\n"
9919 "Address Family modifier\n"
9920 "Address Family modifier\n"
9921 "Display routes matching the communities\n")
9922 {
9923 safi_t safi;
9924 safi = bgp_vty_safi_from_arg(argv[0]);
9925 return bgp_show (vty, NULL, AFI_IP, safi,
9926 bgp_show_type_community_all, NULL, 0);
9927 }
9928
9929 #ifdef HAVE_IPV6
9930 DEFUN (show_bgp_community_all,
9931 show_bgp_community_all_cmd,
9932 "show bgp community",
9933 SHOW_STR
9934 BGP_STR
9935 "Display routes matching the communities\n")
9936 {
9937 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9938 bgp_show_type_community_all, NULL, 0);
9939 }
9940
9941 ALIAS (show_bgp_community_all,
9942 show_bgp_ipv6_community_all_cmd,
9943 "show bgp ipv6 community",
9944 SHOW_STR
9945 BGP_STR
9946 "Address family\n"
9947 "Display routes matching the communities\n")
9948
9949 /* old command */
9950 DEFUN (show_ipv6_bgp_community_all,
9951 show_ipv6_bgp_community_all_cmd,
9952 "show ipv6 bgp community",
9953 SHOW_STR
9954 IPV6_STR
9955 BGP_STR
9956 "Display routes matching the communities\n")
9957 {
9958 bgp_show_ipv6_bgp_deprecate_warning(vty);
9959 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9960 bgp_show_type_community_all, NULL, 0);
9961 }
9962
9963 /* old command */
9964 DEFUN (show_ipv6_mbgp_community_all,
9965 show_ipv6_mbgp_community_all_cmd,
9966 "show ipv6 mbgp community",
9967 SHOW_STR
9968 IPV6_STR
9969 MBGP_STR
9970 "Display routes matching the communities\n")
9971 {
9972 bgp_show_ipv6_bgp_deprecate_warning(vty);
9973 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9974 bgp_show_type_community_all, NULL, 0);
9975 }
9976 #endif /* HAVE_IPV6 */
9977
9978 static int
9979 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9980 const char **argv, int exact, afi_t afi, safi_t safi)
9981 {
9982 struct community *com;
9983 struct buffer *b;
9984 struct bgp *bgp;
9985 int i;
9986 char *str;
9987 int first = 0;
9988
9989 /* BGP structure lookup */
9990 if (view_name)
9991 {
9992 bgp = bgp_lookup_by_name (view_name);
9993 if (bgp == NULL)
9994 {
9995 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9996 return CMD_WARNING;
9997 }
9998 }
9999 else
10000 {
10001 bgp = bgp_get_default ();
10002 if (bgp == NULL)
10003 {
10004 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10005 return CMD_WARNING;
10006 }
10007 }
10008
10009 b = buffer_new (1024);
10010 for (i = 0; i < argc; i++)
10011 {
10012 if (first)
10013 buffer_putc (b, ' ');
10014 else
10015 {
10016 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10017 continue;
10018 first = 1;
10019 }
10020
10021 buffer_putstr (b, argv[i]);
10022 }
10023 buffer_putc (b, '\0');
10024
10025 str = buffer_getstr (b);
10026 buffer_free (b);
10027
10028 com = community_str2com (str);
10029 XFREE (MTYPE_TMP, str);
10030 if (! com)
10031 {
10032 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10033 return CMD_WARNING;
10034 }
10035
10036 return bgp_show (vty, bgp, afi, safi,
10037 (exact ? bgp_show_type_community_exact :
10038 bgp_show_type_community), com, 0);
10039 }
10040
10041 DEFUN (show_ip_bgp_community,
10042 show_ip_bgp_community_cmd,
10043 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
10044 SHOW_STR
10045 IP_STR
10046 BGP_STR
10047 "Display routes matching the communities\n"
10048 COMMUNITY_AANN_STR
10049 "Do not send outside local AS (well-known community)\n"
10050 "Do not advertise to any peer (well-known community)\n"
10051 "Do not export to next AS (well-known community)\n")
10052 {
10053 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10054 }
10055
10056 ALIAS (show_ip_bgp_community,
10057 show_ip_bgp_community2_cmd,
10058 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10059 SHOW_STR
10060 IP_STR
10061 BGP_STR
10062 "Display routes matching the communities\n"
10063 COMMUNITY_AANN_STR
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n"
10067 COMMUNITY_AANN_STR
10068 "Do not send outside local AS (well-known community)\n"
10069 "Do not advertise to any peer (well-known community)\n"
10070 "Do not export to next AS (well-known community)\n")
10071
10072 ALIAS (show_ip_bgp_community,
10073 show_ip_bgp_community3_cmd,
10074 "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)",
10075 SHOW_STR
10076 IP_STR
10077 BGP_STR
10078 "Display routes matching the communities\n"
10079 COMMUNITY_AANN_STR
10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 COMMUNITY_AANN_STR
10084 "Do not send outside local AS (well-known community)\n"
10085 "Do not advertise to any peer (well-known community)\n"
10086 "Do not export to next AS (well-known community)\n"
10087 COMMUNITY_AANN_STR
10088 "Do not send outside local AS (well-known community)\n"
10089 "Do not advertise to any peer (well-known community)\n"
10090 "Do not export to next AS (well-known community)\n")
10091
10092 ALIAS (show_ip_bgp_community,
10093 show_ip_bgp_community4_cmd,
10094 "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)",
10095 SHOW_STR
10096 IP_STR
10097 BGP_STR
10098 "Display routes matching the communities\n"
10099 COMMUNITY_AANN_STR
10100 "Do not send outside local AS (well-known community)\n"
10101 "Do not advertise to any peer (well-known community)\n"
10102 "Do not export to next AS (well-known community)\n"
10103 COMMUNITY_AANN_STR
10104 "Do not send outside local AS (well-known community)\n"
10105 "Do not advertise to any peer (well-known community)\n"
10106 "Do not export to next AS (well-known community)\n"
10107 COMMUNITY_AANN_STR
10108 "Do not send outside local AS (well-known community)\n"
10109 "Do not advertise to any peer (well-known community)\n"
10110 "Do not export to next AS (well-known community)\n"
10111 COMMUNITY_AANN_STR
10112 "Do not send outside local AS (well-known community)\n"
10113 "Do not advertise to any peer (well-known community)\n"
10114 "Do not export to next AS (well-known community)\n")
10115
10116 DEFUN (show_ip_bgp_ipv4_community,
10117 show_ip_bgp_ipv4_community_cmd,
10118 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10119 SHOW_STR
10120 IP_STR
10121 BGP_STR
10122 "Address family\n"
10123 "Address Family modifier\n"
10124 "Address Family modifier\n"
10125 "Display routes matching the communities\n"
10126 COMMUNITY_AANN_STR
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n")
10130 {
10131 safi_t safi;
10132 safi = bgp_vty_safi_from_arg(argv[0]);
10133 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi);
10134 }
10135
10136 ALIAS (show_ip_bgp_ipv4_community,
10137 show_ip_bgp_ipv4_community2_cmd,
10138 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10139 SHOW_STR
10140 IP_STR
10141 BGP_STR
10142 "Address family\n"
10143 "Address Family modifier\n"
10144 "Address Family modifier\n"
10145 "Display routes matching the communities\n"
10146 COMMUNITY_AANN_STR
10147 "Do not send outside local AS (well-known community)\n"
10148 "Do not advertise to any peer (well-known community)\n"
10149 "Do not export to next AS (well-known community)\n"
10150 COMMUNITY_AANN_STR
10151 "Do not send outside local AS (well-known community)\n"
10152 "Do not advertise to any peer (well-known community)\n"
10153 "Do not export to next AS (well-known community)\n")
10154
10155 ALIAS (show_ip_bgp_ipv4_community,
10156 show_ip_bgp_ipv4_community3_cmd,
10157 "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)",
10158 SHOW_STR
10159 IP_STR
10160 BGP_STR
10161 "Address family\n"
10162 "Address Family modifier\n"
10163 "Address Family modifier\n"
10164 "Display routes matching the communities\n"
10165 COMMUNITY_AANN_STR
10166 "Do not send outside local AS (well-known community)\n"
10167 "Do not advertise to any peer (well-known community)\n"
10168 "Do not export to next AS (well-known community)\n"
10169 COMMUNITY_AANN_STR
10170 "Do not send outside local AS (well-known community)\n"
10171 "Do not advertise to any peer (well-known community)\n"
10172 "Do not export to next AS (well-known community)\n"
10173 COMMUNITY_AANN_STR
10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n")
10177
10178 ALIAS (show_ip_bgp_ipv4_community,
10179 show_ip_bgp_ipv4_community4_cmd,
10180 "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)",
10181 SHOW_STR
10182 IP_STR
10183 BGP_STR
10184 "Address family\n"
10185 "Address Family modifier\n"
10186 "Address Family modifier\n"
10187 "Display routes matching the communities\n"
10188 COMMUNITY_AANN_STR
10189 "Do not send outside local AS (well-known community)\n"
10190 "Do not advertise to any peer (well-known community)\n"
10191 "Do not export to next AS (well-known community)\n"
10192 COMMUNITY_AANN_STR
10193 "Do not send outside local AS (well-known community)\n"
10194 "Do not advertise to any peer (well-known community)\n"
10195 "Do not export to next AS (well-known community)\n"
10196 COMMUNITY_AANN_STR
10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n"
10200 COMMUNITY_AANN_STR
10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n")
10204
10205 DEFUN (show_bgp_instance_afi_safi_community_all,
10206 show_bgp_instance_afi_safi_community_all_cmd,
10207 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
10208 SHOW_STR
10209 BGP_STR
10210 BGP_INSTANCE_HELP_STR
10211 "Address family\n"
10212 "Address family\n"
10213 "Address Family modifier\n"
10214 "Address Family modifier\n"
10215 "Display routes matching the communities\n")
10216 {
10217 int afi;
10218 int safi;
10219 struct bgp *bgp;
10220
10221 /* BGP structure lookup. */
10222 bgp = bgp_lookup_by_name (argv[1]);
10223 if (bgp == NULL)
10224 {
10225 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10226 return CMD_WARNING;
10227 }
10228
10229 afi = bgp_vty_safi_from_arg(argv[2]);
10230 safi = bgp_vty_safi_from_arg(argv[3]);
10231 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10232 }
10233
10234 DEFUN (show_bgp_instance_afi_safi_community,
10235 show_bgp_instance_afi_safi_community_cmd,
10236 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10237 SHOW_STR
10238 BGP_STR
10239 BGP_INSTANCE_HELP_STR
10240 "Address family\n"
10241 "Address family\n"
10242 "Address family modifier\n"
10243 "Address family modifier\n"
10244 "Display routes matching the communities\n"
10245 COMMUNITY_AANN_STR
10246 "Do not send outside local AS (well-known community)\n"
10247 "Do not advertise to any peer (well-known community)\n"
10248 "Do not export to next AS (well-known community)\n")
10249 {
10250 int afi;
10251 int safi;
10252
10253 afi = bgp_vty_safi_from_arg(argv[2]);
10254 safi = bgp_vty_safi_from_arg(argv[3]);
10255 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10256 }
10257
10258 ALIAS (show_bgp_instance_afi_safi_community,
10259 show_bgp_instance_afi_safi_community2_cmd,
10260 "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)",
10261 SHOW_STR
10262 BGP_STR
10263 BGP_INSTANCE_HELP_STR
10264 "Address family\n"
10265 "Address family\n"
10266 "Address family modifier\n"
10267 "Address family modifier\n"
10268 "Display routes matching the communities\n"
10269 COMMUNITY_AANN_STR
10270 "Do not send outside local AS (well-known community)\n"
10271 "Do not advertise to any peer (well-known community)\n"
10272 "Do not export to next AS (well-known community)\n"
10273 COMMUNITY_AANN_STR
10274 "Do not send outside local AS (well-known community)\n"
10275 "Do not advertise to any peer (well-known community)\n"
10276 "Do not export to next AS (well-known community)\n")
10277
10278 ALIAS (show_bgp_instance_afi_safi_community,
10279 show_bgp_instance_afi_safi_community3_cmd,
10280 "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)",
10281 SHOW_STR
10282 BGP_STR
10283 BGP_INSTANCE_HELP_STR
10284 "Address family\n"
10285 "Address family\n"
10286 "Address family modifier\n"
10287 "Address family modifier\n"
10288 "Display routes matching the communities\n"
10289 COMMUNITY_AANN_STR
10290 "Do not send outside local AS (well-known community)\n"
10291 "Do not advertise to any peer (well-known community)\n"
10292 "Do not export to next AS (well-known community)\n"
10293 COMMUNITY_AANN_STR
10294 "Do not send outside local AS (well-known community)\n"
10295 "Do not advertise to any peer (well-known community)\n"
10296 "Do not export to next AS (well-known community)\n"
10297 COMMUNITY_AANN_STR
10298 "Do not send outside local AS (well-known community)\n"
10299 "Do not advertise to any peer (well-known community)\n"
10300 "Do not export to next AS (well-known community)\n")
10301
10302 ALIAS (show_bgp_instance_afi_safi_community,
10303 show_bgp_instance_afi_safi_community4_cmd,
10304 "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)",
10305 SHOW_STR
10306 BGP_STR
10307 BGP_INSTANCE_HELP_STR
10308 "Address family\n"
10309 "Address family\n"
10310 "Address family modifier\n"
10311 "Address family modifier\n"
10312 "Display routes matching the communities\n"
10313 COMMUNITY_AANN_STR
10314 "Do not send outside local AS (well-known community)\n"
10315 "Do not advertise to any peer (well-known community)\n"
10316 "Do not export to next AS (well-known community)\n"
10317 COMMUNITY_AANN_STR
10318 "Do not send outside local AS (well-known community)\n"
10319 "Do not advertise to any peer (well-known community)\n"
10320 "Do not export to next AS (well-known community)\n"
10321 COMMUNITY_AANN_STR
10322 "Do not send outside local AS (well-known community)\n"
10323 "Do not advertise to any peer (well-known community)\n"
10324 "Do not export to next AS (well-known community)\n"
10325 COMMUNITY_AANN_STR
10326 "Do not send outside local AS (well-known community)\n"
10327 "Do not advertise to any peer (well-known community)\n"
10328 "Do not export to next AS (well-known community)\n")
10329
10330 DEFUN (show_ip_bgp_community_exact,
10331 show_ip_bgp_community_exact_cmd,
10332 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10333 SHOW_STR
10334 IP_STR
10335 BGP_STR
10336 "Display routes matching the communities\n"
10337 COMMUNITY_AANN_STR
10338 "Do not send outside local AS (well-known community)\n"
10339 "Do not advertise to any peer (well-known community)\n"
10340 "Do not export to next AS (well-known community)\n"
10341 "Exact match of the communities")
10342 {
10343 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10344 }
10345
10346 ALIAS (show_ip_bgp_community_exact,
10347 show_ip_bgp_community2_exact_cmd,
10348 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10349 SHOW_STR
10350 IP_STR
10351 BGP_STR
10352 "Display routes matching the communities\n"
10353 COMMUNITY_AANN_STR
10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 COMMUNITY_AANN_STR
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n"
10361 "Exact match of the communities")
10362
10363 ALIAS (show_ip_bgp_community_exact,
10364 show_ip_bgp_community3_exact_cmd,
10365 "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",
10366 SHOW_STR
10367 IP_STR
10368 BGP_STR
10369 "Display routes matching the communities\n"
10370 COMMUNITY_AANN_STR
10371 "Do not send outside local AS (well-known community)\n"
10372 "Do not advertise to any peer (well-known community)\n"
10373 "Do not export to next AS (well-known community)\n"
10374 COMMUNITY_AANN_STR
10375 "Do not send outside local AS (well-known community)\n"
10376 "Do not advertise to any peer (well-known community)\n"
10377 "Do not export to next AS (well-known community)\n"
10378 COMMUNITY_AANN_STR
10379 "Do not send outside local AS (well-known community)\n"
10380 "Do not advertise to any peer (well-known community)\n"
10381 "Do not export to next AS (well-known community)\n"
10382 "Exact match of the communities")
10383
10384 ALIAS (show_ip_bgp_community_exact,
10385 show_ip_bgp_community4_exact_cmd,
10386 "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",
10387 SHOW_STR
10388 IP_STR
10389 BGP_STR
10390 "Display routes matching the communities\n"
10391 COMMUNITY_AANN_STR
10392 "Do not send outside local AS (well-known community)\n"
10393 "Do not advertise to any peer (well-known community)\n"
10394 "Do not export to next AS (well-known community)\n"
10395 COMMUNITY_AANN_STR
10396 "Do not send outside local AS (well-known community)\n"
10397 "Do not advertise to any peer (well-known community)\n"
10398 "Do not export to next AS (well-known community)\n"
10399 COMMUNITY_AANN_STR
10400 "Do not send outside local AS (well-known community)\n"
10401 "Do not advertise to any peer (well-known community)\n"
10402 "Do not export to next AS (well-known community)\n"
10403 COMMUNITY_AANN_STR
10404 "Do not send outside local AS (well-known community)\n"
10405 "Do not advertise to any peer (well-known community)\n"
10406 "Do not export to next AS (well-known community)\n"
10407 "Exact match of the communities")
10408
10409 DEFUN (show_ip_bgp_ipv4_community_exact,
10410 show_ip_bgp_ipv4_community_exact_cmd,
10411 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10412 SHOW_STR
10413 IP_STR
10414 BGP_STR
10415 "Address family\n"
10416 "Address Family modifier\n"
10417 "Address Family modifier\n"
10418 "Display routes matching the communities\n"
10419 COMMUNITY_AANN_STR
10420 "Do not send outside local AS (well-known community)\n"
10421 "Do not advertise to any peer (well-known community)\n"
10422 "Do not export to next AS (well-known community)\n"
10423 "Exact match of the communities")
10424 {
10425 safi_t safi;
10426 safi = bgp_vty_safi_from_arg(argv[0]);
10427 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi);
10428 }
10429
10430 ALIAS (show_ip_bgp_ipv4_community_exact,
10431 show_ip_bgp_ipv4_community2_exact_cmd,
10432 "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",
10433 SHOW_STR
10434 IP_STR
10435 BGP_STR
10436 "Address family\n"
10437 "Address Family modifier\n"
10438 "Address Family modifier\n"
10439 "Display routes matching the communities\n"
10440 COMMUNITY_AANN_STR
10441 "Do not send outside local AS (well-known community)\n"
10442 "Do not advertise to any peer (well-known community)\n"
10443 "Do not export to next AS (well-known community)\n"
10444 COMMUNITY_AANN_STR
10445 "Do not send outside local AS (well-known community)\n"
10446 "Do not advertise to any peer (well-known community)\n"
10447 "Do not export to next AS (well-known community)\n"
10448 "Exact match of the communities")
10449
10450 ALIAS (show_ip_bgp_ipv4_community_exact,
10451 show_ip_bgp_ipv4_community3_exact_cmd,
10452 "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",
10453 SHOW_STR
10454 IP_STR
10455 BGP_STR
10456 "Address family\n"
10457 "Address Family modifier\n"
10458 "Address Family modifier\n"
10459 "Display routes matching the communities\n"
10460 COMMUNITY_AANN_STR
10461 "Do not send outside local AS (well-known community)\n"
10462 "Do not advertise to any peer (well-known community)\n"
10463 "Do not export to next AS (well-known community)\n"
10464 COMMUNITY_AANN_STR
10465 "Do not send outside local AS (well-known community)\n"
10466 "Do not advertise to any peer (well-known community)\n"
10467 "Do not export to next AS (well-known community)\n"
10468 COMMUNITY_AANN_STR
10469 "Do not send outside local AS (well-known community)\n"
10470 "Do not advertise to any peer (well-known community)\n"
10471 "Do not export to next AS (well-known community)\n"
10472 "Exact match of the communities")
10473
10474 ALIAS (show_ip_bgp_ipv4_community_exact,
10475 show_ip_bgp_ipv4_community4_exact_cmd,
10476 "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",
10477 SHOW_STR
10478 IP_STR
10479 BGP_STR
10480 "Address family\n"
10481 "Address Family modifier\n"
10482 "Address Family modifier\n"
10483 "Display routes matching the communities\n"
10484 COMMUNITY_AANN_STR
10485 "Do not send outside local AS (well-known community)\n"
10486 "Do not advertise to any peer (well-known community)\n"
10487 "Do not export to next AS (well-known community)\n"
10488 COMMUNITY_AANN_STR
10489 "Do not send outside local AS (well-known community)\n"
10490 "Do not advertise to any peer (well-known community)\n"
10491 "Do not export to next AS (well-known community)\n"
10492 COMMUNITY_AANN_STR
10493 "Do not send outside local AS (well-known community)\n"
10494 "Do not advertise to any peer (well-known community)\n"
10495 "Do not export to next AS (well-known community)\n"
10496 COMMUNITY_AANN_STR
10497 "Do not send outside local AS (well-known community)\n"
10498 "Do not advertise to any peer (well-known community)\n"
10499 "Do not export to next AS (well-known community)\n"
10500 "Exact match of the communities")
10501
10502 #ifdef HAVE_IPV6
10503 DEFUN (show_bgp_community,
10504 show_bgp_community_cmd,
10505 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10506 SHOW_STR
10507 BGP_STR
10508 "Display routes matching the communities\n"
10509 COMMUNITY_AANN_STR
10510 "Do not send outside local AS (well-known community)\n"
10511 "Do not advertise to any peer (well-known community)\n"
10512 "Do not export to next AS (well-known community)\n")
10513 {
10514 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10515 }
10516
10517 ALIAS (show_bgp_community,
10518 show_bgp_ipv6_community_cmd,
10519 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10520 SHOW_STR
10521 BGP_STR
10522 "Address family\n"
10523 "Display routes matching the communities\n"
10524 COMMUNITY_AANN_STR
10525 "Do not send outside local AS (well-known community)\n"
10526 "Do not advertise to any peer (well-known community)\n"
10527 "Do not export to next AS (well-known community)\n")
10528
10529 ALIAS (show_bgp_community,
10530 show_bgp_community2_cmd,
10531 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10532 SHOW_STR
10533 BGP_STR
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 COMMUNITY_AANN_STR
10540 "Do not send outside local AS (well-known community)\n"
10541 "Do not advertise to any peer (well-known community)\n"
10542 "Do not export to next AS (well-known community)\n")
10543
10544 ALIAS (show_bgp_community,
10545 show_bgp_ipv6_community2_cmd,
10546 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10547 SHOW_STR
10548 BGP_STR
10549 "Address family\n"
10550 "Display routes matching the communities\n"
10551 COMMUNITY_AANN_STR
10552 "Do not send outside local AS (well-known community)\n"
10553 "Do not advertise to any peer (well-known community)\n"
10554 "Do not export to next AS (well-known community)\n"
10555 COMMUNITY_AANN_STR
10556 "Do not send outside local AS (well-known community)\n"
10557 "Do not advertise to any peer (well-known community)\n"
10558 "Do not export to next AS (well-known community)\n")
10559
10560 ALIAS (show_bgp_community,
10561 show_bgp_community3_cmd,
10562 "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)",
10563 SHOW_STR
10564 BGP_STR
10565 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10571 "Do not send outside local AS (well-known community)\n"
10572 "Do not advertise to any peer (well-known community)\n"
10573 "Do not export to next AS (well-known community)\n"
10574 COMMUNITY_AANN_STR
10575 "Do not send outside local AS (well-known community)\n"
10576 "Do not advertise to any peer (well-known community)\n"
10577 "Do not export to next AS (well-known community)\n")
10578
10579 ALIAS (show_bgp_community,
10580 show_bgp_ipv6_community3_cmd,
10581 "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)",
10582 SHOW_STR
10583 BGP_STR
10584 "Address family\n"
10585 "Display routes matching the communities\n"
10586 COMMUNITY_AANN_STR
10587 "Do not send outside local AS (well-known community)\n"
10588 "Do not advertise to any peer (well-known community)\n"
10589 "Do not export to next AS (well-known community)\n"
10590 COMMUNITY_AANN_STR
10591 "Do not send outside local AS (well-known community)\n"
10592 "Do not advertise to any peer (well-known community)\n"
10593 "Do not export to next AS (well-known community)\n"
10594 COMMUNITY_AANN_STR
10595 "Do not send outside local AS (well-known community)\n"
10596 "Do not advertise to any peer (well-known community)\n"
10597 "Do not export to next AS (well-known community)\n")
10598
10599 ALIAS (show_bgp_community,
10600 show_bgp_community4_cmd,
10601 "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)",
10602 SHOW_STR
10603 BGP_STR
10604 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10610 "Do not send outside local AS (well-known community)\n"
10611 "Do not advertise to any peer (well-known community)\n"
10612 "Do not export to next AS (well-known community)\n"
10613 COMMUNITY_AANN_STR
10614 "Do not send outside local AS (well-known community)\n"
10615 "Do not advertise to any peer (well-known community)\n"
10616 "Do not export to next AS (well-known community)\n"
10617 COMMUNITY_AANN_STR
10618 "Do not send outside local AS (well-known community)\n"
10619 "Do not advertise to any peer (well-known community)\n"
10620 "Do not export to next AS (well-known community)\n")
10621
10622 ALIAS (show_bgp_community,
10623 show_bgp_ipv6_community4_cmd,
10624 "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)",
10625 SHOW_STR
10626 BGP_STR
10627 "Address family\n"
10628 "Display routes matching the communities\n"
10629 COMMUNITY_AANN_STR
10630 "Do not send outside local AS (well-known community)\n"
10631 "Do not advertise to any peer (well-known community)\n"
10632 "Do not export to next AS (well-known community)\n"
10633 COMMUNITY_AANN_STR
10634 "Do not send outside local AS (well-known community)\n"
10635 "Do not advertise to any peer (well-known community)\n"
10636 "Do not export to next AS (well-known community)\n"
10637 COMMUNITY_AANN_STR
10638 "Do not send outside local AS (well-known community)\n"
10639 "Do not advertise to any peer (well-known community)\n"
10640 "Do not export to next AS (well-known community)\n"
10641 COMMUNITY_AANN_STR
10642 "Do not send outside local AS (well-known community)\n"
10643 "Do not advertise to any peer (well-known community)\n"
10644 "Do not export to next AS (well-known community)\n")
10645
10646 /* old command */
10647 DEFUN (show_ipv6_bgp_community,
10648 show_ipv6_bgp_community_cmd,
10649 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10650 SHOW_STR
10651 IPV6_STR
10652 BGP_STR
10653 "Display routes matching the communities\n"
10654 COMMUNITY_AANN_STR
10655 "Do not send outside local AS (well-known community)\n"
10656 "Do not advertise to any peer (well-known community)\n"
10657 "Do not export to next AS (well-known community)\n")
10658 {
10659 bgp_show_ipv6_bgp_deprecate_warning(vty);
10660 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10661 }
10662
10663 /* old command */
10664 ALIAS (show_ipv6_bgp_community,
10665 show_ipv6_bgp_community2_cmd,
10666 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10667 SHOW_STR
10668 IPV6_STR
10669 BGP_STR
10670 "Display routes matching the communities\n"
10671 COMMUNITY_AANN_STR
10672 "Do not send outside local AS (well-known community)\n"
10673 "Do not advertise to any peer (well-known community)\n"
10674 "Do not export to next AS (well-known community)\n"
10675 COMMUNITY_AANN_STR
10676 "Do not send outside local AS (well-known community)\n"
10677 "Do not advertise to any peer (well-known community)\n"
10678 "Do not export to next AS (well-known community)\n")
10679
10680 /* old command */
10681 ALIAS (show_ipv6_bgp_community,
10682 show_ipv6_bgp_community3_cmd,
10683 "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)",
10684 SHOW_STR
10685 IPV6_STR
10686 BGP_STR
10687 "Display routes matching the communities\n"
10688 COMMUNITY_AANN_STR
10689 "Do not send outside local AS (well-known community)\n"
10690 "Do not advertise to any peer (well-known community)\n"
10691 "Do not export to next AS (well-known community)\n"
10692 COMMUNITY_AANN_STR
10693 "Do not send outside local AS (well-known community)\n"
10694 "Do not advertise to any peer (well-known community)\n"
10695 "Do not export to next AS (well-known community)\n"
10696 COMMUNITY_AANN_STR
10697 "Do not send outside local AS (well-known community)\n"
10698 "Do not advertise to any peer (well-known community)\n"
10699 "Do not export to next AS (well-known community)\n")
10700
10701 /* old command */
10702 ALIAS (show_ipv6_bgp_community,
10703 show_ipv6_bgp_community4_cmd,
10704 "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)",
10705 SHOW_STR
10706 IPV6_STR
10707 BGP_STR
10708 "Display routes matching the communities\n"
10709 COMMUNITY_AANN_STR
10710 "Do not send outside local AS (well-known community)\n"
10711 "Do not advertise to any peer (well-known community)\n"
10712 "Do not export to next AS (well-known community)\n"
10713 COMMUNITY_AANN_STR
10714 "Do not send outside local AS (well-known community)\n"
10715 "Do not advertise to any peer (well-known community)\n"
10716 "Do not export to next AS (well-known community)\n"
10717 COMMUNITY_AANN_STR
10718 "Do not send outside local AS (well-known community)\n"
10719 "Do not advertise to any peer (well-known community)\n"
10720 "Do not export to next AS (well-known community)\n"
10721 COMMUNITY_AANN_STR
10722 "Do not send outside local AS (well-known community)\n"
10723 "Do not advertise to any peer (well-known community)\n"
10724 "Do not export to next AS (well-known community)\n")
10725
10726 DEFUN (show_bgp_community_exact,
10727 show_bgp_community_exact_cmd,
10728 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10729 SHOW_STR
10730 BGP_STR
10731 "Display routes matching the communities\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 "Exact match of the communities")
10737 {
10738 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10739 }
10740
10741 ALIAS (show_bgp_community_exact,
10742 show_bgp_ipv6_community_exact_cmd,
10743 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10744 SHOW_STR
10745 BGP_STR
10746 "Address family\n"
10747 "Display routes matching the communities\n"
10748 COMMUNITY_AANN_STR
10749 "Do not send outside local AS (well-known community)\n"
10750 "Do not advertise to any peer (well-known community)\n"
10751 "Do not export to next AS (well-known community)\n"
10752 "Exact match of the communities")
10753
10754 ALIAS (show_bgp_community_exact,
10755 show_bgp_community2_exact_cmd,
10756 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10757 SHOW_STR
10758 BGP_STR
10759 "Display routes matching the communities\n"
10760 COMMUNITY_AANN_STR
10761 "Do not send outside local AS (well-known community)\n"
10762 "Do not advertise to any peer (well-known community)\n"
10763 "Do not export to next AS (well-known community)\n"
10764 COMMUNITY_AANN_STR
10765 "Do not send outside local AS (well-known community)\n"
10766 "Do not advertise to any peer (well-known community)\n"
10767 "Do not export to next AS (well-known community)\n"
10768 "Exact match of the communities")
10769
10770 ALIAS (show_bgp_community_exact,
10771 show_bgp_ipv6_community2_exact_cmd,
10772 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10773 SHOW_STR
10774 BGP_STR
10775 "Address family\n"
10776 "Display routes matching the communities\n"
10777 COMMUNITY_AANN_STR
10778 "Do not send outside local AS (well-known community)\n"
10779 "Do not advertise to any peer (well-known community)\n"
10780 "Do not export to next AS (well-known community)\n"
10781 COMMUNITY_AANN_STR
10782 "Do not send outside local AS (well-known community)\n"
10783 "Do not advertise to any peer (well-known community)\n"
10784 "Do not export to next AS (well-known community)\n"
10785 "Exact match of the communities")
10786
10787 ALIAS (show_bgp_community_exact,
10788 show_bgp_community3_exact_cmd,
10789 "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",
10790 SHOW_STR
10791 BGP_STR
10792 "Display routes matching the communities\n"
10793 COMMUNITY_AANN_STR
10794 "Do not send outside local AS (well-known community)\n"
10795 "Do not advertise to any peer (well-known community)\n"
10796 "Do not export to next AS (well-known community)\n"
10797 COMMUNITY_AANN_STR
10798 "Do not send outside local AS (well-known community)\n"
10799 "Do not advertise to any peer (well-known community)\n"
10800 "Do not export to next AS (well-known community)\n"
10801 COMMUNITY_AANN_STR
10802 "Do not send outside local AS (well-known community)\n"
10803 "Do not advertise to any peer (well-known community)\n"
10804 "Do not export to next AS (well-known community)\n"
10805 "Exact match of the communities")
10806
10807 ALIAS (show_bgp_community_exact,
10808 show_bgp_ipv6_community3_exact_cmd,
10809 "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",
10810 SHOW_STR
10811 BGP_STR
10812 "Address family\n"
10813 "Display routes matching the communities\n"
10814 COMMUNITY_AANN_STR
10815 "Do not send outside local AS (well-known community)\n"
10816 "Do not advertise to any peer (well-known community)\n"
10817 "Do not export to next AS (well-known community)\n"
10818 COMMUNITY_AANN_STR
10819 "Do not send outside local AS (well-known community)\n"
10820 "Do not advertise to any peer (well-known community)\n"
10821 "Do not export to next AS (well-known community)\n"
10822 COMMUNITY_AANN_STR
10823 "Do not send outside local AS (well-known community)\n"
10824 "Do not advertise to any peer (well-known community)\n"
10825 "Do not export to next AS (well-known community)\n"
10826 "Exact match of the communities")
10827
10828 ALIAS (show_bgp_community_exact,
10829 show_bgp_community4_exact_cmd,
10830 "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",
10831 SHOW_STR
10832 BGP_STR
10833 "Display routes matching the communities\n"
10834 COMMUNITY_AANN_STR
10835 "Do not send outside local AS (well-known community)\n"
10836 "Do not advertise to any peer (well-known community)\n"
10837 "Do not export to next AS (well-known community)\n"
10838 COMMUNITY_AANN_STR
10839 "Do not send outside local AS (well-known community)\n"
10840 "Do not advertise to any peer (well-known community)\n"
10841 "Do not export to next AS (well-known community)\n"
10842 COMMUNITY_AANN_STR
10843 "Do not send outside local AS (well-known community)\n"
10844 "Do not advertise to any peer (well-known community)\n"
10845 "Do not export to next AS (well-known community)\n"
10846 COMMUNITY_AANN_STR
10847 "Do not send outside local AS (well-known community)\n"
10848 "Do not advertise to any peer (well-known community)\n"
10849 "Do not export to next AS (well-known community)\n"
10850 "Exact match of the communities")
10851
10852 ALIAS (show_bgp_community_exact,
10853 show_bgp_ipv6_community4_exact_cmd,
10854 "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",
10855 SHOW_STR
10856 BGP_STR
10857 "Address family\n"
10858 "Display routes matching the communities\n"
10859 COMMUNITY_AANN_STR
10860 "Do not send outside local AS (well-known community)\n"
10861 "Do not advertise to any peer (well-known community)\n"
10862 "Do not export to next AS (well-known community)\n"
10863 COMMUNITY_AANN_STR
10864 "Do not send outside local AS (well-known community)\n"
10865 "Do not advertise to any peer (well-known community)\n"
10866 "Do not export to next AS (well-known community)\n"
10867 COMMUNITY_AANN_STR
10868 "Do not send outside local AS (well-known community)\n"
10869 "Do not advertise to any peer (well-known community)\n"
10870 "Do not export to next AS (well-known community)\n"
10871 COMMUNITY_AANN_STR
10872 "Do not send outside local AS (well-known community)\n"
10873 "Do not advertise to any peer (well-known community)\n"
10874 "Do not export to next AS (well-known community)\n"
10875 "Exact match of the communities")
10876
10877 /* old command */
10878 DEFUN (show_ipv6_bgp_community_exact,
10879 show_ipv6_bgp_community_exact_cmd,
10880 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10881 SHOW_STR
10882 IPV6_STR
10883 BGP_STR
10884 "Display routes matching the communities\n"
10885 COMMUNITY_AANN_STR
10886 "Do not send outside local AS (well-known community)\n"
10887 "Do not advertise to any peer (well-known community)\n"
10888 "Do not export to next AS (well-known community)\n"
10889 "Exact match of the communities")
10890 {
10891 bgp_show_ipv6_bgp_deprecate_warning(vty);
10892 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10893 }
10894
10895 /* old command */
10896 ALIAS (show_ipv6_bgp_community_exact,
10897 show_ipv6_bgp_community2_exact_cmd,
10898 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10899 SHOW_STR
10900 IPV6_STR
10901 BGP_STR
10902 "Display routes matching the communities\n"
10903 COMMUNITY_AANN_STR
10904 "Do not send outside local AS (well-known community)\n"
10905 "Do not advertise to any peer (well-known community)\n"
10906 "Do not export to next AS (well-known community)\n"
10907 COMMUNITY_AANN_STR
10908 "Do not send outside local AS (well-known community)\n"
10909 "Do not advertise to any peer (well-known community)\n"
10910 "Do not export to next AS (well-known community)\n"
10911 "Exact match of the communities")
10912
10913 /* old command */
10914 ALIAS (show_ipv6_bgp_community_exact,
10915 show_ipv6_bgp_community3_exact_cmd,
10916 "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",
10917 SHOW_STR
10918 IPV6_STR
10919 BGP_STR
10920 "Display routes matching the communities\n"
10921 COMMUNITY_AANN_STR
10922 "Do not send outside local AS (well-known community)\n"
10923 "Do not advertise to any peer (well-known community)\n"
10924 "Do not export to next AS (well-known community)\n"
10925 COMMUNITY_AANN_STR
10926 "Do not send outside local AS (well-known community)\n"
10927 "Do not advertise to any peer (well-known community)\n"
10928 "Do not export to next AS (well-known community)\n"
10929 COMMUNITY_AANN_STR
10930 "Do not send outside local AS (well-known community)\n"
10931 "Do not advertise to any peer (well-known community)\n"
10932 "Do not export to next AS (well-known community)\n"
10933 "Exact match of the communities")
10934
10935 /* old command */
10936 ALIAS (show_ipv6_bgp_community_exact,
10937 show_ipv6_bgp_community4_exact_cmd,
10938 "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",
10939 SHOW_STR
10940 IPV6_STR
10941 BGP_STR
10942 "Display routes matching the communities\n"
10943 COMMUNITY_AANN_STR
10944 "Do not send outside local AS (well-known community)\n"
10945 "Do not advertise to any peer (well-known community)\n"
10946 "Do not export to next AS (well-known community)\n"
10947 COMMUNITY_AANN_STR
10948 "Do not send outside local AS (well-known community)\n"
10949 "Do not advertise to any peer (well-known community)\n"
10950 "Do not export to next AS (well-known community)\n"
10951 COMMUNITY_AANN_STR
10952 "Do not send outside local AS (well-known community)\n"
10953 "Do not advertise to any peer (well-known community)\n"
10954 "Do not export to next AS (well-known community)\n"
10955 COMMUNITY_AANN_STR
10956 "Do not send outside local AS (well-known community)\n"
10957 "Do not advertise to any peer (well-known community)\n"
10958 "Do not export to next AS (well-known community)\n"
10959 "Exact match of the communities")
10960
10961 /* old command */
10962 DEFUN (show_ipv6_mbgp_community,
10963 show_ipv6_mbgp_community_cmd,
10964 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10965 SHOW_STR
10966 IPV6_STR
10967 MBGP_STR
10968 "Display routes matching the communities\n"
10969 COMMUNITY_AANN_STR
10970 "Do not send outside local AS (well-known community)\n"
10971 "Do not advertise to any peer (well-known community)\n"
10972 "Do not export to next AS (well-known community)\n")
10973 {
10974 bgp_show_ipv6_bgp_deprecate_warning(vty);
10975 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10976 }
10977
10978 /* old command */
10979 ALIAS (show_ipv6_mbgp_community,
10980 show_ipv6_mbgp_community2_cmd,
10981 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10982 SHOW_STR
10983 IPV6_STR
10984 MBGP_STR
10985 "Display routes matching the communities\n"
10986 COMMUNITY_AANN_STR
10987 "Do not send outside local AS (well-known community)\n"
10988 "Do not advertise to any peer (well-known community)\n"
10989 "Do not export to next AS (well-known community)\n"
10990 COMMUNITY_AANN_STR
10991 "Do not send outside local AS (well-known community)\n"
10992 "Do not advertise to any peer (well-known community)\n"
10993 "Do not export to next AS (well-known community)\n")
10994
10995 /* old command */
10996 ALIAS (show_ipv6_mbgp_community,
10997 show_ipv6_mbgp_community3_cmd,
10998 "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)",
10999 SHOW_STR
11000 IPV6_STR
11001 MBGP_STR
11002 "Display routes matching the communities\n"
11003 COMMUNITY_AANN_STR
11004 "Do not send outside local AS (well-known community)\n"
11005 "Do not advertise to any peer (well-known community)\n"
11006 "Do not export to next AS (well-known community)\n"
11007 COMMUNITY_AANN_STR
11008 "Do not send outside local AS (well-known community)\n"
11009 "Do not advertise to any peer (well-known community)\n"
11010 "Do not export to next AS (well-known community)\n"
11011 COMMUNITY_AANN_STR
11012 "Do not send outside local AS (well-known community)\n"
11013 "Do not advertise to any peer (well-known community)\n"
11014 "Do not export to next AS (well-known community)\n")
11015
11016 /* old command */
11017 ALIAS (show_ipv6_mbgp_community,
11018 show_ipv6_mbgp_community4_cmd,
11019 "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)",
11020 SHOW_STR
11021 IPV6_STR
11022 MBGP_STR
11023 "Display routes matching the communities\n"
11024 COMMUNITY_AANN_STR
11025 "Do not send outside local AS (well-known community)\n"
11026 "Do not advertise to any peer (well-known community)\n"
11027 "Do not export to next AS (well-known community)\n"
11028 COMMUNITY_AANN_STR
11029 "Do not send outside local AS (well-known community)\n"
11030 "Do not advertise to any peer (well-known community)\n"
11031 "Do not export to next AS (well-known community)\n"
11032 COMMUNITY_AANN_STR
11033 "Do not send outside local AS (well-known community)\n"
11034 "Do not advertise to any peer (well-known community)\n"
11035 "Do not export to next AS (well-known community)\n"
11036 COMMUNITY_AANN_STR
11037 "Do not send outside local AS (well-known community)\n"
11038 "Do not advertise to any peer (well-known community)\n"
11039 "Do not export to next AS (well-known community)\n")
11040
11041 /* old command */
11042 DEFUN (show_ipv6_mbgp_community_exact,
11043 show_ipv6_mbgp_community_exact_cmd,
11044 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11045 SHOW_STR
11046 IPV6_STR
11047 MBGP_STR
11048 "Display routes matching the communities\n"
11049 COMMUNITY_AANN_STR
11050 "Do not send outside local AS (well-known community)\n"
11051 "Do not advertise to any peer (well-known community)\n"
11052 "Do not export to next AS (well-known community)\n"
11053 "Exact match of the communities")
11054 {
11055 bgp_show_ipv6_bgp_deprecate_warning(vty);
11056 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
11057 }
11058
11059 /* old command */
11060 ALIAS (show_ipv6_mbgp_community_exact,
11061 show_ipv6_mbgp_community2_exact_cmd,
11062 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11063 SHOW_STR
11064 IPV6_STR
11065 MBGP_STR
11066 "Display routes matching the communities\n"
11067 COMMUNITY_AANN_STR
11068 "Do not send outside local AS (well-known community)\n"
11069 "Do not advertise to any peer (well-known community)\n"
11070 "Do not export to next AS (well-known community)\n"
11071 COMMUNITY_AANN_STR
11072 "Do not send outside local AS (well-known community)\n"
11073 "Do not advertise to any peer (well-known community)\n"
11074 "Do not export to next AS (well-known community)\n"
11075 "Exact match of the communities")
11076
11077 /* old command */
11078 ALIAS (show_ipv6_mbgp_community_exact,
11079 show_ipv6_mbgp_community3_exact_cmd,
11080 "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",
11081 SHOW_STR
11082 IPV6_STR
11083 MBGP_STR
11084 "Display routes matching the communities\n"
11085 COMMUNITY_AANN_STR
11086 "Do not send outside local AS (well-known community)\n"
11087 "Do not advertise to any peer (well-known community)\n"
11088 "Do not export to next AS (well-known community)\n"
11089 COMMUNITY_AANN_STR
11090 "Do not send outside local AS (well-known community)\n"
11091 "Do not advertise to any peer (well-known community)\n"
11092 "Do not export to next AS (well-known community)\n"
11093 COMMUNITY_AANN_STR
11094 "Do not send outside local AS (well-known community)\n"
11095 "Do not advertise to any peer (well-known community)\n"
11096 "Do not export to next AS (well-known community)\n"
11097 "Exact match of the communities")
11098
11099 /* old command */
11100 ALIAS (show_ipv6_mbgp_community_exact,
11101 show_ipv6_mbgp_community4_exact_cmd,
11102 "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",
11103 SHOW_STR
11104 IPV6_STR
11105 MBGP_STR
11106 "Display routes matching the communities\n"
11107 COMMUNITY_AANN_STR
11108 "Do not send outside local AS (well-known community)\n"
11109 "Do not advertise to any peer (well-known community)\n"
11110 "Do not export to next AS (well-known community)\n"
11111 COMMUNITY_AANN_STR
11112 "Do not send outside local AS (well-known community)\n"
11113 "Do not advertise to any peer (well-known community)\n"
11114 "Do not export to next AS (well-known community)\n"
11115 COMMUNITY_AANN_STR
11116 "Do not send outside local AS (well-known community)\n"
11117 "Do not advertise to any peer (well-known community)\n"
11118 "Do not export to next AS (well-known community)\n"
11119 COMMUNITY_AANN_STR
11120 "Do not send outside local AS (well-known community)\n"
11121 "Do not advertise to any peer (well-known community)\n"
11122 "Do not export to next AS (well-known community)\n"
11123 "Exact match of the communities")
11124 #endif /* HAVE_IPV6 */
11125
11126 static int
11127 bgp_show_community_list (struct vty *vty, const char *name,
11128 const char *com, int exact,
11129 afi_t afi, safi_t safi)
11130 {
11131 struct community_list *list;
11132 struct bgp *bgp = NULL;
11133
11134 if (name && !(bgp = bgp_lookup_by_name(name)))
11135 {
11136 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11137 return CMD_WARNING;
11138 }
11139
11140 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11141 if (list == NULL)
11142 {
11143 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11144 VTY_NEWLINE);
11145 return CMD_WARNING;
11146 }
11147
11148 return bgp_show (vty, bgp, afi, safi,
11149 (exact ? bgp_show_type_community_list_exact :
11150 bgp_show_type_community_list), list, 0);
11151 }
11152
11153 DEFUN (show_ip_bgp_community_list,
11154 show_ip_bgp_community_list_cmd,
11155 "show ip bgp community-list (<1-500>|WORD)",
11156 SHOW_STR
11157 IP_STR
11158 BGP_STR
11159 "Display routes matching the community-list\n"
11160 "community-list number\n"
11161 "community-list name\n")
11162 {
11163 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11164 }
11165
11166 DEFUN (show_ip_bgp_instance_community_list,
11167 show_ip_bgp_instance_community_list_cmd,
11168 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11169 SHOW_STR
11170 IP_STR
11171 BGP_STR
11172 BGP_INSTANCE_HELP_STR
11173 "Display routes matching the community-list\n"
11174 "community-list number\n"
11175 "community-list name\n")
11176 {
11177 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11178 }
11179
11180 DEFUN (show_ip_bgp_ipv4_community_list,
11181 show_ip_bgp_ipv4_community_list_cmd,
11182 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11183 SHOW_STR
11184 IP_STR
11185 BGP_STR
11186 "Address family\n"
11187 "Address Family modifier\n"
11188 "Address Family modifier\n"
11189 "Display routes matching the community-list\n"
11190 "community-list number\n"
11191 "community-list name\n")
11192 {
11193 safi_t safi;
11194 safi = bgp_vty_safi_from_arg(argv[0]);
11195 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi);
11196 }
11197
11198 DEFUN (show_ip_bgp_community_list_exact,
11199 show_ip_bgp_community_list_exact_cmd,
11200 "show ip bgp community-list (<1-500>|WORD) exact-match",
11201 SHOW_STR
11202 IP_STR
11203 BGP_STR
11204 "Display routes matching the community-list\n"
11205 "community-list number\n"
11206 "community-list name\n"
11207 "Exact match of the communities\n")
11208 {
11209 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11210 }
11211
11212 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11213 show_ip_bgp_ipv4_community_list_exact_cmd,
11214 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11215 SHOW_STR
11216 IP_STR
11217 BGP_STR
11218 "Address family\n"
11219 "Address Family modifier\n"
11220 "Address Family modifier\n"
11221 "Display routes matching the community-list\n"
11222 "community-list number\n"
11223 "community-list name\n"
11224 "Exact match of the communities\n")
11225 {
11226 safi_t safi;
11227 safi = bgp_vty_safi_from_arg(argv[0]);
11228 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi);
11229 }
11230
11231 #ifdef HAVE_IPV6
11232 DEFUN (show_bgp_community_list,
11233 show_bgp_community_list_cmd,
11234 "show bgp community-list (<1-500>|WORD)",
11235 SHOW_STR
11236 BGP_STR
11237 "Display routes matching the community-list\n"
11238 "community-list number\n"
11239 "community-list name\n")
11240 {
11241 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11242 }
11243
11244 ALIAS (show_bgp_community_list,
11245 show_bgp_ipv6_community_list_cmd,
11246 "show bgp ipv6 community-list (<1-500>|WORD)",
11247 SHOW_STR
11248 BGP_STR
11249 "Address family\n"
11250 "Display routes matching the community-list\n"
11251 "community-list number\n"
11252 "community-list name\n")
11253
11254 /* old command */
11255 DEFUN (show_ipv6_bgp_community_list,
11256 show_ipv6_bgp_community_list_cmd,
11257 "show ipv6 bgp community-list WORD",
11258 SHOW_STR
11259 IPV6_STR
11260 BGP_STR
11261 "Display routes matching the community-list\n"
11262 "community-list name\n")
11263 {
11264 bgp_show_ipv6_bgp_deprecate_warning(vty);
11265 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11266 }
11267
11268 /* old command */
11269 DEFUN (show_ipv6_mbgp_community_list,
11270 show_ipv6_mbgp_community_list_cmd,
11271 "show ipv6 mbgp community-list WORD",
11272 SHOW_STR
11273 IPV6_STR
11274 MBGP_STR
11275 "Display routes matching the community-list\n"
11276 "community-list name\n")
11277 {
11278 bgp_show_ipv6_bgp_deprecate_warning(vty);
11279 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11280 }
11281
11282 DEFUN (show_bgp_community_list_exact,
11283 show_bgp_community_list_exact_cmd,
11284 "show bgp community-list (<1-500>|WORD) exact-match",
11285 SHOW_STR
11286 BGP_STR
11287 "Display routes matching the community-list\n"
11288 "community-list number\n"
11289 "community-list name\n"
11290 "Exact match of the communities\n")
11291 {
11292 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11293 }
11294
11295 ALIAS (show_bgp_community_list_exact,
11296 show_bgp_ipv6_community_list_exact_cmd,
11297 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11298 SHOW_STR
11299 BGP_STR
11300 "Address family\n"
11301 "Display routes matching the community-list\n"
11302 "community-list number\n"
11303 "community-list name\n"
11304 "Exact match of the communities\n")
11305
11306 /* old command */
11307 DEFUN (show_ipv6_bgp_community_list_exact,
11308 show_ipv6_bgp_community_list_exact_cmd,
11309 "show ipv6 bgp community-list WORD exact-match",
11310 SHOW_STR
11311 IPV6_STR
11312 BGP_STR
11313 "Display routes matching the community-list\n"
11314 "community-list name\n"
11315 "Exact match of the communities\n")
11316 {
11317 bgp_show_ipv6_bgp_deprecate_warning(vty);
11318 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11319 }
11320
11321 /* old command */
11322 DEFUN (show_ipv6_mbgp_community_list_exact,
11323 show_ipv6_mbgp_community_list_exact_cmd,
11324 "show ipv6 mbgp community-list WORD exact-match",
11325 SHOW_STR
11326 IPV6_STR
11327 MBGP_STR
11328 "Display routes matching the community-list\n"
11329 "community-list name\n"
11330 "Exact match of the communities\n")
11331 {
11332 bgp_show_ipv6_bgp_deprecate_warning(vty);
11333 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11334 }
11335 #endif /* HAVE_IPV6 */
11336
11337 static int
11338 bgp_show_prefix_longer (struct vty *vty, const char *name,
11339 const char *prefix, afi_t afi,
11340 safi_t safi, enum bgp_show_type type)
11341 {
11342 int ret;
11343 struct prefix *p;
11344 struct bgp *bgp = NULL;
11345
11346 if (name && !(bgp = bgp_lookup_by_name(name)))
11347 {
11348 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11349 return CMD_WARNING;
11350 }
11351
11352 p = prefix_new();
11353
11354 ret = str2prefix (prefix, p);
11355 if (! ret)
11356 {
11357 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360
11361 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11362 prefix_free(p);
11363 return ret;
11364 }
11365
11366 DEFUN (show_ip_bgp_prefix_longer,
11367 show_ip_bgp_prefix_longer_cmd,
11368 "show ip bgp A.B.C.D/M longer-prefixes",
11369 SHOW_STR
11370 IP_STR
11371 BGP_STR
11372 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11373 "Display route and more specific routes\n")
11374 {
11375 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11376 bgp_show_type_prefix_longer);
11377 }
11378
11379 DEFUN (show_ip_bgp_instance_prefix_longer,
11380 show_ip_bgp_instance_prefix_longer_cmd,
11381 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11382 SHOW_STR
11383 IP_STR
11384 BGP_STR
11385 BGP_INSTANCE_HELP_STR
11386 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11387 "Display route and more specific routes\n")
11388 {
11389 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11390 bgp_show_type_prefix_longer);
11391 }
11392
11393 DEFUN (show_ip_bgp_flap_prefix_longer,
11394 show_ip_bgp_flap_prefix_longer_cmd,
11395 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11396 SHOW_STR
11397 IP_STR
11398 BGP_STR
11399 "Display flap statistics of routes\n"
11400 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11401 "Display route and more specific routes\n")
11402 {
11403 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11404 bgp_show_type_flap_prefix_longer);
11405 }
11406
11407 ALIAS (show_ip_bgp_flap_prefix_longer,
11408 show_ip_bgp_damp_flap_prefix_longer_cmd,
11409 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11410 SHOW_STR
11411 IP_STR
11412 BGP_STR
11413 "Display detailed information about dampening\n"
11414 "Display flap statistics of routes\n"
11415 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11416 "Display route and more specific routes\n")
11417
11418 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11419 show_ip_bgp_ipv4_prefix_longer_cmd,
11420 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 "Address family\n"
11425 "Address Family modifier\n"
11426 "Address Family modifier\n"
11427 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11428 "Display route and more specific routes\n")
11429 {
11430 safi_t safi;
11431 safi = bgp_vty_safi_from_arg(argv[0]);
11432 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi,
11433 bgp_show_type_prefix_longer);
11434 }
11435
11436 DEFUN (show_ip_bgp_flap_address,
11437 show_ip_bgp_flap_address_cmd,
11438 "show ip bgp flap-statistics A.B.C.D",
11439 SHOW_STR
11440 IP_STR
11441 BGP_STR
11442 "Display flap statistics of routes\n"
11443 "Network in the BGP routing table to display\n")
11444 {
11445 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11446 bgp_show_type_flap_address);
11447 }
11448
11449 ALIAS (show_ip_bgp_flap_address,
11450 show_ip_bgp_damp_flap_address_cmd,
11451 "show ip bgp dampening flap-statistics A.B.C.D",
11452 SHOW_STR
11453 IP_STR
11454 BGP_STR
11455 "Display detailed information about dampening\n"
11456 "Display flap statistics of routes\n"
11457 "Network in the BGP routing table to display\n")
11458
11459 DEFUN (show_ip_bgp_flap_prefix,
11460 show_ip_bgp_flap_prefix_cmd,
11461 "show ip bgp flap-statistics A.B.C.D/M",
11462 SHOW_STR
11463 IP_STR
11464 BGP_STR
11465 "Display flap statistics of routes\n"
11466 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11467 {
11468 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11469 bgp_show_type_flap_prefix);
11470 }
11471
11472 ALIAS (show_ip_bgp_flap_prefix,
11473 show_ip_bgp_damp_flap_prefix_cmd,
11474 "show ip bgp dampening flap-statistics A.B.C.D/M",
11475 SHOW_STR
11476 IP_STR
11477 BGP_STR
11478 "Display detailed information about dampening\n"
11479 "Display flap statistics of routes\n"
11480 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11481
11482 #ifdef HAVE_IPV6
11483 DEFUN (show_bgp_prefix_longer,
11484 show_bgp_prefix_longer_cmd,
11485 "show bgp X:X::X:X/M longer-prefixes",
11486 SHOW_STR
11487 BGP_STR
11488 "IPv6 prefix <network>/<length>\n"
11489 "Display route and more specific routes\n")
11490 {
11491 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11492 bgp_show_type_prefix_longer);
11493 }
11494
11495 ALIAS (show_bgp_prefix_longer,
11496 show_bgp_ipv6_prefix_longer_cmd,
11497 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11498 SHOW_STR
11499 BGP_STR
11500 "Address family\n"
11501 "IPv6 prefix <network>/<length>\n"
11502 "Display route and more specific routes\n")
11503
11504 /* old command */
11505 DEFUN (show_ipv6_bgp_prefix_longer,
11506 show_ipv6_bgp_prefix_longer_cmd,
11507 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11508 SHOW_STR
11509 IPV6_STR
11510 BGP_STR
11511 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11512 "Display route and more specific routes\n")
11513 {
11514 bgp_show_ipv6_bgp_deprecate_warning(vty);
11515 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11516 bgp_show_type_prefix_longer);
11517 }
11518
11519 /* old command */
11520 DEFUN (show_ipv6_mbgp_prefix_longer,
11521 show_ipv6_mbgp_prefix_longer_cmd,
11522 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11523 SHOW_STR
11524 IPV6_STR
11525 MBGP_STR
11526 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11527 "Display route and more specific routes\n")
11528 {
11529 bgp_show_ipv6_bgp_deprecate_warning(vty);
11530 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11531 bgp_show_type_prefix_longer);
11532 }
11533 #endif /* HAVE_IPV6 */
11534
11535 static struct peer *
11536 peer_lookup_in_view (struct vty *vty, const char *view_name,
11537 const char *ip_str, u_char use_json)
11538 {
11539 int ret;
11540 struct bgp *bgp;
11541 struct peer *peer;
11542 union sockunion su;
11543
11544 /* BGP structure lookup. */
11545 if (view_name)
11546 {
11547 bgp = bgp_lookup_by_name (view_name);
11548 if (! bgp)
11549 {
11550 if (use_json)
11551 {
11552 json_object *json_no = NULL;
11553 json_no = json_object_new_object();
11554 json_object_string_add(json_no, "warning", "Can't find BGP view");
11555 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11556 json_object_free(json_no);
11557 }
11558 else
11559 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11560 return NULL;
11561 }
11562 }
11563 else
11564 {
11565 bgp = bgp_get_default ();
11566 if (! bgp)
11567 {
11568 if (use_json)
11569 {
11570 json_object *json_no = NULL;
11571 json_no = json_object_new_object();
11572 json_object_string_add(json_no, "warning", "No BGP process configured");
11573 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11574 json_object_free(json_no);
11575 }
11576 else
11577 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11578 return NULL;
11579 }
11580 }
11581
11582 /* Get peer sockunion. */
11583 ret = str2sockunion (ip_str, &su);
11584 if (ret < 0)
11585 {
11586 peer = peer_lookup_by_conf_if (bgp, ip_str);
11587 if (!peer)
11588 {
11589 peer = peer_lookup_by_hostname(bgp, ip_str);
11590
11591 if (!peer)
11592 {
11593 if (use_json)
11594 {
11595 json_object *json_no = NULL;
11596 json_no = json_object_new_object();
11597 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11598 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11599 json_object_free(json_no);
11600 }
11601 else
11602 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11603 return NULL;
11604 }
11605 }
11606 return peer;
11607 }
11608
11609 /* Peer structure lookup. */
11610 peer = peer_lookup (bgp, &su);
11611 if (! peer)
11612 {
11613 if (use_json)
11614 {
11615 json_object *json_no = NULL;
11616 json_no = json_object_new_object();
11617 json_object_string_add(json_no, "warning","No such neighbor");
11618 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11619 json_object_free(json_no);
11620 }
11621 else
11622 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11623 return NULL;
11624 }
11625
11626 return peer;
11627 }
11628
11629 enum bgp_stats
11630 {
11631 BGP_STATS_MAXBITLEN = 0,
11632 BGP_STATS_RIB,
11633 BGP_STATS_PREFIXES,
11634 BGP_STATS_TOTPLEN,
11635 BGP_STATS_UNAGGREGATEABLE,
11636 BGP_STATS_MAX_AGGREGATEABLE,
11637 BGP_STATS_AGGREGATES,
11638 BGP_STATS_SPACE,
11639 BGP_STATS_ASPATH_COUNT,
11640 BGP_STATS_ASPATH_MAXHOPS,
11641 BGP_STATS_ASPATH_TOTHOPS,
11642 BGP_STATS_ASPATH_MAXSIZE,
11643 BGP_STATS_ASPATH_TOTSIZE,
11644 BGP_STATS_ASN_HIGHEST,
11645 BGP_STATS_MAX,
11646 };
11647
11648 static const char *table_stats_strs[] =
11649 {
11650 [BGP_STATS_PREFIXES] = "Total Prefixes",
11651 [BGP_STATS_TOTPLEN] = "Average prefix length",
11652 [BGP_STATS_RIB] = "Total Advertisements",
11653 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11654 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11655 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11656 [BGP_STATS_SPACE] = "Address space advertised",
11657 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11658 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11659 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11660 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11661 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11662 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11663 [BGP_STATS_MAX] = NULL,
11664 };
11665
11666 struct bgp_table_stats
11667 {
11668 struct bgp_table *table;
11669 unsigned long long counts[BGP_STATS_MAX];
11670 };
11671
11672 #if 0
11673 #define TALLY_SIGFIG 100000
11674 static unsigned long
11675 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11676 {
11677 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11678 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11679 unsigned long ret = newtot / count;
11680
11681 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11682 return ret + 1;
11683 else
11684 return ret;
11685 }
11686 #endif
11687
11688 static int
11689 bgp_table_stats_walker (struct thread *t)
11690 {
11691 struct bgp_node *rn;
11692 struct bgp_node *top;
11693 struct bgp_table_stats *ts = THREAD_ARG (t);
11694 unsigned int space = 0;
11695
11696 if (!(top = bgp_table_top (ts->table)))
11697 return 0;
11698
11699 switch (top->p.family)
11700 {
11701 case AF_INET:
11702 space = IPV4_MAX_BITLEN;
11703 break;
11704 case AF_INET6:
11705 space = IPV6_MAX_BITLEN;
11706 break;
11707 }
11708
11709 ts->counts[BGP_STATS_MAXBITLEN] = space;
11710
11711 for (rn = top; rn; rn = bgp_route_next (rn))
11712 {
11713 struct bgp_info *ri;
11714 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11715 unsigned int rinum = 0;
11716
11717 if (rn == top)
11718 continue;
11719
11720 if (!rn->info)
11721 continue;
11722
11723 ts->counts[BGP_STATS_PREFIXES]++;
11724 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11725
11726 #if 0
11727 ts->counts[BGP_STATS_AVGPLEN]
11728 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11729 ts->counts[BGP_STATS_AVGPLEN],
11730 rn->p.prefixlen);
11731 #endif
11732
11733 /* check if the prefix is included by any other announcements */
11734 while (prn && !prn->info)
11735 prn = bgp_node_parent_nolock (prn);
11736
11737 if (prn == NULL || prn == top)
11738 {
11739 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11740 /* announced address space */
11741 if (space)
11742 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11743 }
11744 else if (prn->info)
11745 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11746
11747 for (ri = rn->info; ri; ri = ri->next)
11748 {
11749 rinum++;
11750 ts->counts[BGP_STATS_RIB]++;
11751
11752 if (ri->attr &&
11753 (CHECK_FLAG (ri->attr->flag,
11754 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11755 ts->counts[BGP_STATS_AGGREGATES]++;
11756
11757 /* as-path stats */
11758 if (ri->attr && ri->attr->aspath)
11759 {
11760 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11761 unsigned int size = aspath_size (ri->attr->aspath);
11762 as_t highest = aspath_highest (ri->attr->aspath);
11763
11764 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11765
11766 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11767 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11768
11769 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11770 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11771
11772 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11773 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11774 #if 0
11775 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11776 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11777 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11778 hops);
11779 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11780 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11781 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11782 size);
11783 #endif
11784 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11785 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11786 }
11787 }
11788 }
11789 return 0;
11790 }
11791
11792 static int
11793 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11794 {
11795 struct bgp_table_stats ts;
11796 unsigned int i;
11797
11798 if (!bgp->rib[afi][safi])
11799 {
11800 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11801 afi, safi, VTY_NEWLINE);
11802 return CMD_WARNING;
11803 }
11804
11805 memset (&ts, 0, sizeof (ts));
11806 ts.table = bgp->rib[afi][safi];
11807 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11808
11809 vty_out (vty, "BGP %s RIB statistics%s%s",
11810 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11811
11812 for (i = 0; i < BGP_STATS_MAX; i++)
11813 {
11814 if (!table_stats_strs[i])
11815 continue;
11816
11817 switch (i)
11818 {
11819 #if 0
11820 case BGP_STATS_ASPATH_AVGHOPS:
11821 case BGP_STATS_ASPATH_AVGSIZE:
11822 case BGP_STATS_AVGPLEN:
11823 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11824 vty_out (vty, "%12.2f",
11825 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11826 break;
11827 #endif
11828 case BGP_STATS_ASPATH_TOTHOPS:
11829 case BGP_STATS_ASPATH_TOTSIZE:
11830 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11831 vty_out (vty, "%12.2f",
11832 ts.counts[i] ?
11833 (float)ts.counts[i] /
11834 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11835 : 0);
11836 break;
11837 case BGP_STATS_TOTPLEN:
11838 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11839 vty_out (vty, "%12.2f",
11840 ts.counts[i] ?
11841 (float)ts.counts[i] /
11842 (float)ts.counts[BGP_STATS_PREFIXES]
11843 : 0);
11844 break;
11845 case BGP_STATS_SPACE:
11846 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11847 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11848 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11849 break;
11850 vty_out (vty, "%30s: ", "%% announced ");
11851 vty_out (vty, "%12.2f%s",
11852 100 * (float)ts.counts[BGP_STATS_SPACE] /
11853 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11854 VTY_NEWLINE);
11855 vty_out (vty, "%30s: ", "/8 equivalent ");
11856 vty_out (vty, "%12.2f%s",
11857 (float)ts.counts[BGP_STATS_SPACE] /
11858 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11859 VTY_NEWLINE);
11860 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11861 break;
11862 vty_out (vty, "%30s: ", "/24 equivalent ");
11863 vty_out (vty, "%12.2f",
11864 (float)ts.counts[BGP_STATS_SPACE] /
11865 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11866 break;
11867 default:
11868 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11869 vty_out (vty, "%12llu", ts.counts[i]);
11870 }
11871
11872 vty_out (vty, "%s", VTY_NEWLINE);
11873 }
11874 return CMD_SUCCESS;
11875 }
11876
11877 static int
11878 bgp_table_stats_vty (struct vty *vty, const char *name,
11879 const char *afi_str, const char *safi_str)
11880 {
11881 struct bgp *bgp;
11882 afi_t afi;
11883 safi_t safi;
11884
11885 if (name)
11886 bgp = bgp_lookup_by_name (name);
11887 else
11888 bgp = bgp_get_default ();
11889
11890 if (!bgp)
11891 {
11892 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11893 return CMD_WARNING;
11894 }
11895 afi = bgp_vty_afi_from_arg(afi_str);
11896 if (afi == AFI_MAX)
11897 {
11898 vty_out (vty, "%% Invalid address family \"%s\"%s",
11899 afi_str, VTY_NEWLINE);
11900 return CMD_WARNING;
11901 }
11902 safi = bgp_vty_safi_from_arg(safi_str);
11903 if (safi == SAFI_MAX)
11904 {
11905 vty_out (vty, "%% Invalid subsequent address family %s%s",
11906 safi_str, VTY_NEWLINE);
11907 return CMD_WARNING;
11908 }
11909
11910 return bgp_table_stats (vty, bgp, afi, safi);
11911 }
11912
11913 DEFUN (show_bgp_statistics,
11914 show_bgp_statistics_cmd,
11915 "show bgp "BGP_AFI_SAFI_CMD_STR" statistics",
11916 SHOW_STR
11917 BGP_STR
11918 BGP_AFI_SAFI_HELP_STR
11919 "BGP RIB advertisement statistics\n")
11920 {
11921 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11922 }
11923
11924 DEFUN (show_bgp_statistics_view,
11925 show_bgp_statistics_view_cmd,
11926 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics",
11927 SHOW_STR
11928 BGP_STR
11929 BGP_INSTANCE_HELP_STR
11930 BGP_AFI_SAFI_HELP_STR
11931 "BGP RIB advertisement statistics\n")
11932 {
11933 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11934 }
11935
11936 enum bgp_pcounts
11937 {
11938 PCOUNT_ADJ_IN = 0,
11939 PCOUNT_DAMPED,
11940 PCOUNT_REMOVED,
11941 PCOUNT_HISTORY,
11942 PCOUNT_STALE,
11943 PCOUNT_VALID,
11944 PCOUNT_ALL,
11945 PCOUNT_COUNTED,
11946 PCOUNT_PFCNT, /* the figure we display to users */
11947 PCOUNT_MAX,
11948 };
11949
11950 static const char *pcount_strs[] =
11951 {
11952 [PCOUNT_ADJ_IN] = "Adj-in",
11953 [PCOUNT_DAMPED] = "Damped",
11954 [PCOUNT_REMOVED] = "Removed",
11955 [PCOUNT_HISTORY] = "History",
11956 [PCOUNT_STALE] = "Stale",
11957 [PCOUNT_VALID] = "Valid",
11958 [PCOUNT_ALL] = "All RIB",
11959 [PCOUNT_COUNTED] = "PfxCt counted",
11960 [PCOUNT_PFCNT] = "Useable",
11961 [PCOUNT_MAX] = NULL,
11962 };
11963
11964 struct peer_pcounts
11965 {
11966 unsigned int count[PCOUNT_MAX];
11967 const struct peer *peer;
11968 const struct bgp_table *table;
11969 };
11970
11971 static int
11972 bgp_peer_count_walker (struct thread *t)
11973 {
11974 struct bgp_node *rn;
11975 struct peer_pcounts *pc = THREAD_ARG (t);
11976 const struct peer *peer = pc->peer;
11977
11978 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11979 {
11980 struct bgp_adj_in *ain;
11981 struct bgp_info *ri;
11982
11983 for (ain = rn->adj_in; ain; ain = ain->next)
11984 if (ain->peer == peer)
11985 pc->count[PCOUNT_ADJ_IN]++;
11986
11987 for (ri = rn->info; ri; ri = ri->next)
11988 {
11989 char buf[SU_ADDRSTRLEN];
11990
11991 if (ri->peer != peer)
11992 continue;
11993
11994 pc->count[PCOUNT_ALL]++;
11995
11996 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11997 pc->count[PCOUNT_DAMPED]++;
11998 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11999 pc->count[PCOUNT_HISTORY]++;
12000 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
12001 pc->count[PCOUNT_REMOVED]++;
12002 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
12003 pc->count[PCOUNT_STALE]++;
12004 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
12005 pc->count[PCOUNT_VALID]++;
12006 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12007 pc->count[PCOUNT_PFCNT]++;
12008
12009 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12010 {
12011 pc->count[PCOUNT_COUNTED]++;
12012 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12013 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
12014 peer->host,
12015 inet_ntop(rn->p.family, &rn->p.u.prefix,
12016 buf, SU_ADDRSTRLEN),
12017 rn->p.prefixlen,
12018 ri->flags);
12019 }
12020 else
12021 {
12022 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12023 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
12024 peer->host,
12025 inet_ntop(rn->p.family, &rn->p.u.prefix,
12026 buf, SU_ADDRSTRLEN),
12027 rn->p.prefixlen,
12028 ri->flags);
12029 }
12030 }
12031 }
12032 return 0;
12033 }
12034
12035 static int
12036 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
12037 {
12038 struct peer_pcounts pcounts = { .peer = peer };
12039 unsigned int i;
12040 json_object *json = NULL;
12041 json_object *json_loop = NULL;
12042
12043 if (use_json)
12044 {
12045 json = json_object_new_object();
12046 json_loop = json_object_new_object();
12047 }
12048
12049 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12050 || !peer->bgp->rib[afi][safi])
12051 {
12052 if (use_json)
12053 {
12054 json_object_string_add(json, "warning", "No such neighbor or address family");
12055 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12056 json_object_free(json);
12057 }
12058 else
12059 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12060
12061 return CMD_WARNING;
12062 }
12063
12064 memset (&pcounts, 0, sizeof(pcounts));
12065 pcounts.peer = peer;
12066 pcounts.table = peer->bgp->rib[afi][safi];
12067
12068 /* in-place call via thread subsystem so as to record execution time
12069 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12070 * * on just vty_read()).
12071 * */
12072 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12073
12074 if (use_json)
12075 {
12076 json_object_string_add(json, "prefixCountsFor", peer->host);
12077 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12078 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12079
12080 for (i = 0; i < PCOUNT_MAX; i++)
12081 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12082
12083 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12084
12085 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12086 {
12087 json_object_string_add(json, "pfxctDriftFor", peer->host);
12088 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12089 }
12090 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12091 json_object_free(json);
12092 }
12093 else
12094 {
12095
12096 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12097 {
12098 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12099 peer->hostname, peer->host, afi_safi_print (afi, safi),
12100 VTY_NEWLINE);
12101 }
12102 else
12103 {
12104 vty_out (vty, "Prefix counts for %s, %s%s",
12105 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12106 }
12107
12108 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12109 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12110 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12111
12112 for (i = 0; i < PCOUNT_MAX; i++)
12113 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12114
12115 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12116 {
12117 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12118 peer->host, VTY_NEWLINE);
12119 vty_out (vty, "Please report this bug, with the above command output%s",
12120 VTY_NEWLINE);
12121 }
12122 }
12123
12124 return CMD_SUCCESS;
12125 }
12126
12127 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12128 show_ip_bgp_neighbor_prefix_counts_cmd,
12129 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12130 SHOW_STR
12131 IP_STR
12132 BGP_STR
12133 "Detailed information on TCP and BGP neighbor connections\n"
12134 "Neighbor to display information about\n"
12135 "Neighbor to display information about\n"
12136 "Neighbor on bgp configured interface\n"
12137 "Display detailed prefix count information\n"
12138 "JavaScript Object Notation\n")
12139 {
12140 struct peer *peer;
12141 u_char uj = use_json(argc, argv);
12142
12143 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12144 if (! peer)
12145 return CMD_WARNING;
12146
12147 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12148 }
12149
12150 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12151 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12152 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12153 SHOW_STR
12154 IP_STR
12155 BGP_STR
12156 BGP_INSTANCE_HELP_STR
12157 "Detailed information on TCP and BGP neighbor connections\n"
12158 "Neighbor to display information about\n"
12159 "Neighbor to display information about\n"
12160 "Neighbor on bgp configured interface\n"
12161 "Display detailed prefix count information\n"
12162 "JavaScript Object Notation\n")
12163 {
12164 struct peer *peer;
12165 u_char uj = use_json(argc, argv);
12166
12167 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12168 if (! peer)
12169 return CMD_WARNING;
12170
12171 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12172 }
12173
12174 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12175 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12176 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12177 SHOW_STR
12178 BGP_STR
12179 "Address family\n"
12180 "Detailed information on TCP and BGP neighbor connections\n"
12181 "Neighbor to display information about\n"
12182 "Neighbor to display information about\n"
12183 "Neighbor on bgp configured interface\n"
12184 "Display detailed prefix count information\n"
12185 "JavaScript Object Notation\n")
12186 {
12187 struct peer *peer;
12188 u_char uj = use_json(argc, argv);
12189
12190 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12191 if (! peer)
12192 return CMD_WARNING;
12193
12194 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12195 }
12196
12197 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12198 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12199 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12200 SHOW_STR
12201 BGP_STR
12202 BGP_INSTANCE_HELP_STR
12203 "Address family\n"
12204 "Detailed information on TCP and BGP neighbor connections\n"
12205 "Neighbor to display information about\n"
12206 "Neighbor to display information about\n"
12207 "Neighbor on bgp configured interface\n"
12208 "Display detailed prefix count information\n"
12209 "JavaScript Object Notation\n")
12210 {
12211 struct peer *peer;
12212 u_char uj = use_json(argc, argv);
12213
12214 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12215 if (! peer)
12216 return CMD_WARNING;
12217
12218 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12219 }
12220
12221 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12222 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12223 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12224 SHOW_STR
12225 IP_STR
12226 BGP_STR
12227 "Address family\n"
12228 "Address Family modifier\n"
12229 "Address Family modifier\n"
12230 "Detailed information on TCP and BGP neighbor connections\n"
12231 "Neighbor to display information about\n"
12232 "Neighbor to display information about\n"
12233 "Neighbor on bgp configured interface\n"
12234 "Display detailed prefix count information\n"
12235 "JavaScript Object Notation\n")
12236 {
12237 struct peer *peer;
12238 u_char uj = use_json(argc, argv);
12239
12240 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12241 if (! peer)
12242 return CMD_WARNING;
12243
12244 safi_t safi;
12245 safi = bgp_vty_safi_from_arg(argv[0]);
12246 return bgp_peer_counts (vty, peer, AFI_IP, safi, uj);
12247 }
12248
12249 static void
12250 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12251 int in, const char *rmap_name, u_char use_json, json_object *json)
12252 {
12253 struct bgp_table *table;
12254 struct bgp_adj_in *ain;
12255 struct bgp_adj_out *adj;
12256 unsigned long output_count;
12257 unsigned long filtered_count;
12258 struct bgp_node *rn;
12259 int header1 = 1;
12260 struct bgp *bgp;
12261 int header2 = 1;
12262 struct attr attr;
12263 struct attr_extra extra;
12264 int ret;
12265 struct update_subgroup *subgrp;
12266 json_object *json_scode = NULL;
12267 json_object *json_ocode = NULL;
12268 json_object *json_ar = NULL;
12269 struct peer_af *paf;
12270
12271 if (use_json)
12272 {
12273 json_scode = json_object_new_object();
12274 json_ocode = json_object_new_object();
12275 json_ar = json_object_new_object();
12276
12277 json_object_string_add(json_scode, "suppressed", "s");
12278 json_object_string_add(json_scode, "damped", "d");
12279 json_object_string_add(json_scode, "history", "h");
12280 json_object_string_add(json_scode, "valid", "*");
12281 json_object_string_add(json_scode, "best", ">");
12282 json_object_string_add(json_scode, "multipath", "=");
12283 json_object_string_add(json_scode, "internal", "i");
12284 json_object_string_add(json_scode, "ribFailure", "r");
12285 json_object_string_add(json_scode, "stale", "S");
12286 json_object_string_add(json_scode, "removed", "R");
12287
12288 json_object_string_add(json_ocode, "igp", "i");
12289 json_object_string_add(json_ocode, "egp", "e");
12290 json_object_string_add(json_ocode, "incomplete", "?");
12291 }
12292
12293 bgp = peer->bgp;
12294
12295 if (! bgp)
12296 {
12297 if (use_json)
12298 {
12299 json_object_string_add(json, "alert", "no BGP");
12300 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12301 json_object_free(json);
12302 }
12303 else
12304 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12305 return;
12306 }
12307
12308 table = bgp->rib[afi][safi];
12309
12310 output_count = filtered_count = 0;
12311 subgrp = peer_subgroup(peer, afi, safi);
12312
12313 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12314 {
12315 if (use_json)
12316 {
12317 json_object_int_add(json, "bgpTableVersion", table->version);
12318 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12319 json_object_object_add(json, "bgpStatusCodes", json_scode);
12320 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12321 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12322 }
12323 else
12324 {
12325 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12326 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12327 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12328
12329 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12330 VTY_NEWLINE, VTY_NEWLINE);
12331 }
12332 header1 = 0;
12333 }
12334
12335 attr.extra = &extra;
12336 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12337 {
12338 if (in)
12339 {
12340 for (ain = rn->adj_in; ain; ain = ain->next)
12341 {
12342 if (ain->peer == peer)
12343 {
12344 if (header1)
12345 {
12346 if (use_json)
12347 {
12348 json_object_int_add(json, "bgpTableVersion", 0);
12349 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12350 json_object_object_add(json, "bgpStatusCodes", json_scode);
12351 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12352 }
12353 else
12354 {
12355 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12356 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12357 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12358 }
12359 header1 = 0;
12360 }
12361 if (header2)
12362 {
12363 if (!use_json)
12364 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12365 header2 = 0;
12366 }
12367 if (ain->attr)
12368 {
12369 bgp_attr_dup(&attr, ain->attr);
12370 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12371 {
12372 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12373 output_count++;
12374 }
12375 else
12376 filtered_count++;
12377 }
12378 }
12379 }
12380 }
12381 else
12382 {
12383 for (adj = rn->adj_out; adj; adj = adj->next)
12384 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12385 if (paf->peer == peer)
12386 {
12387 if (header1)
12388 {
12389 if (use_json)
12390 {
12391 json_object_int_add(json, "bgpTableVersion", table->version);
12392 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12393 json_object_object_add(json, "bgpStatusCodes", json_scode);
12394 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12395 }
12396 else
12397 {
12398 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12399 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12400 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12401 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12402 }
12403 header1 = 0;
12404 }
12405
12406 if (header2)
12407 {
12408 if (!use_json)
12409 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12410 header2 = 0;
12411 }
12412
12413 if (adj->attr)
12414 {
12415 bgp_attr_dup(&attr, adj->attr);
12416 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12417 if (ret != RMAP_DENY)
12418 {
12419 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12420 output_count++;
12421 }
12422 else
12423 filtered_count++;
12424 }
12425 }
12426 }
12427 }
12428 if (use_json)
12429 json_object_object_add(json, "advertisedRoutes", json_ar);
12430
12431 if (output_count != 0)
12432 {
12433 if (use_json)
12434 json_object_int_add(json, "totalPrefixCounter", output_count);
12435 else
12436 vty_out (vty, "%sTotal number of prefixes %ld%s",
12437 VTY_NEWLINE, output_count, VTY_NEWLINE);
12438 }
12439 if (use_json)
12440 {
12441 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12442 json_object_free(json);
12443 }
12444
12445 }
12446
12447 static int
12448 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12449 int in, const char *rmap_name, u_char use_json)
12450 {
12451 json_object *json = NULL;
12452
12453 if (use_json)
12454 json = json_object_new_object();
12455
12456 if (!peer || !peer->afc[afi][safi])
12457 {
12458 if (use_json)
12459 {
12460 json_object_string_add(json, "warning", "No such neighbor or address family");
12461 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12462 json_object_free(json);
12463 }
12464 else
12465 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12466
12467 return CMD_WARNING;
12468 }
12469
12470 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12471 {
12472 if (use_json)
12473 {
12474 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12475 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12476 json_object_free(json);
12477 }
12478 else
12479 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12480
12481 return CMD_WARNING;
12482 }
12483
12484 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12485
12486 return CMD_SUCCESS;
12487 }
12488
12489 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12490 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12491 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12492 SHOW_STR
12493 IP_STR
12494 BGP_STR
12495 BGP_INSTANCE_HELP_STR
12496 "Detailed information on TCP and BGP neighbor connections\n"
12497 "Neighbor to display information about\n"
12498 "Neighbor to display information about\n"
12499 "Display the routes advertised to a BGP neighbor\n"
12500 "JavaScript Object Notation\n")
12501 {
12502 struct peer *peer;
12503 u_char uj = use_json(argc, argv);
12504
12505 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12506 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12507 else
12508 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12509
12510 if (! peer)
12511 return CMD_WARNING;
12512
12513 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12514 }
12515
12516 DEFUN (show_ip_bgp_neighbor_advertised_route,
12517 show_ip_bgp_neighbor_advertised_route_cmd,
12518 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12519 SHOW_STR
12520 IP_STR
12521 BGP_STR
12522 "Detailed information on TCP and BGP neighbor connections\n"
12523 "Neighbor to display information about\n"
12524 "Neighbor to display information about\n"
12525 "Neighbor on bgp configured interface\n"
12526 "Display the routes advertised to a BGP neighbor\n"
12527 "JavaScript Object Notation\n")
12528
12529 {
12530 struct peer *peer;
12531 const char *rmap_name = NULL;
12532 u_char uj = use_json(argc, argv);
12533
12534 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12535
12536 if (! peer)
12537 return CMD_WARNING;
12538
12539 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12540 || (argc == 3))
12541 rmap_name = argv[1];
12542
12543 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12544 }
12545
12546 ALIAS (show_ip_bgp_neighbor_advertised_route,
12547 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12548 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12549 SHOW_STR
12550 IP_STR
12551 BGP_STR
12552 "Detailed information on TCP and BGP neighbor connections\n"
12553 "Neighbor to display information about\n"
12554 "Neighbor to display information about\n"
12555 "Neighbor on bgp configured interface\n"
12556 "Display the routes advertised to a BGP neighbor\n"
12557 "JavaScript Object Notation\n")
12558
12559 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12560 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12561 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12562 SHOW_STR
12563 IP_STR
12564 BGP_STR
12565 BGP_INSTANCE_HELP_STR
12566 "Detailed information on TCP and BGP neighbor connections\n"
12567 "Neighbor to display information about\n"
12568 "Neighbor to display information about\n"
12569 "Neighbor on bgp configured interface\n"
12570 "Display the routes advertised to a BGP neighbor\n"
12571 "JavaScript Object Notation\n")
12572 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12573 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12574 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12575 SHOW_STR
12576 IP_STR
12577 BGP_STR
12578 "Address family\n"
12579 "Address Family modifier\n"
12580 "Address Family modifier\n"
12581 "Detailed information on TCP and BGP neighbor connections\n"
12582 "Neighbor to display information about\n"
12583 "Neighbor to display information about\n"
12584 "Neighbor on bgp configured interface\n"
12585 "Display the routes advertised to a BGP neighbor\n"
12586 "JavaScript Object Notation\n")
12587 {
12588 struct peer *peer;
12589 const char *rmap_name = NULL;
12590 safi_t safi;
12591
12592 u_char uj = use_json(argc, argv);
12593
12594 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12595 if (! peer)
12596 return CMD_WARNING;
12597
12598 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12599 rmap_name = argv[2];
12600
12601 safi = bgp_vty_safi_from_arg(argv[0]);
12602 return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj);
12603 }
12604
12605 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12606 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12607 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12608 SHOW_STR
12609 IP_STR
12610 BGP_STR
12611 "Address family\n"
12612 "Address Family modifier\n"
12613 "Address Family modifier\n"
12614 "Detailed information on TCP and BGP neighbor connections\n"
12615 "Neighbor to display information about\n"
12616 "Neighbor to display information about\n"
12617 "Neighbor on bgp configured interface\n"
12618 "Display the routes advertised to a BGP neighbor\n"
12619 "Route-map to control what is displayed\n"
12620 "JavaScript Object Notation\n")
12621
12622 #ifdef HAVE_IPV6
12623 DEFUN (show_bgp_instance_neighbor_advertised_route,
12624 show_bgp_instance_neighbor_advertised_route_cmd,
12625 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12626 SHOW_STR
12627 BGP_STR
12628 BGP_INSTANCE_HELP_STR
12629 "Detailed information on TCP and BGP neighbor connections\n"
12630 "Neighbor to display information about\n"
12631 "Neighbor to display information about\n"
12632 "Neighbor on bgp configured interface\n"
12633 "Display the routes advertised to a BGP neighbor\n"
12634 "JavaScript Object Notation\n")
12635 {
12636 struct peer *peer;
12637 u_char uj = use_json(argc, argv);
12638
12639 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12640 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12641 else
12642 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12643
12644 if (! peer)
12645 return CMD_WARNING;
12646
12647 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12648 }
12649
12650 ALIAS (show_bgp_instance_neighbor_advertised_route,
12651 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12652 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12653 SHOW_STR
12654 BGP_STR
12655 BGP_INSTANCE_HELP_STR
12656 "Address family\n"
12657 "Detailed information on TCP and BGP neighbor connections\n"
12658 "Neighbor to display information about\n"
12659 "Neighbor to display information about\n"
12660 "Neighbor on bgp configured interface\n"
12661 "Display the routes advertised to a BGP neighbor\n"
12662 "JavaScript Object Notation\n")
12663
12664 DEFUN (show_bgp_neighbor_advertised_route,
12665 show_bgp_neighbor_advertised_route_cmd,
12666 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12667 SHOW_STR
12668 BGP_STR
12669 "Detailed information on TCP and BGP neighbor connections\n"
12670 "Neighbor to display information about\n"
12671 "Neighbor to display information about\n"
12672 "Neighbor on bgp configured interface\n"
12673 "Display the routes advertised to a BGP neighbor\n"
12674 "JavaScript Object Notation\n")
12675
12676 {
12677 struct peer *peer;
12678 const char *rmap_name = NULL;
12679 u_char uj = use_json(argc, argv);
12680
12681 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12682
12683 if (!peer)
12684 return CMD_WARNING;
12685
12686 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12687 rmap_name = argv[1];
12688
12689 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12690 }
12691
12692 ALIAS (show_bgp_neighbor_advertised_route,
12693 show_bgp_ipv6_neighbor_advertised_route_cmd,
12694 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12695 SHOW_STR
12696 BGP_STR
12697 "Address family\n"
12698 "Detailed information on TCP and BGP neighbor connections\n"
12699 "Neighbor to display information about\n"
12700 "Neighbor to display information about\n"
12701 "Neighbor on bgp configured interface\n"
12702 "Display the routes advertised to a BGP neighbor\n"
12703 "JavaScript Object Notation\n")
12704
12705 /* old command */
12706 ALIAS (show_bgp_neighbor_advertised_route,
12707 ipv6_bgp_neighbor_advertised_route_cmd,
12708 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12709 SHOW_STR
12710 IPV6_STR
12711 BGP_STR
12712 "Detailed information on TCP and BGP neighbor connections\n"
12713 "Neighbor to display information about\n"
12714 "Neighbor to display information about\n"
12715 "Neighbor on bgp configured interface\n"
12716 "Display the routes advertised to a BGP neighbor\n"
12717 "JavaScript Object Notation\n")
12718
12719 /* old command */
12720 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12721 ipv6_mbgp_neighbor_advertised_route_cmd,
12722 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12723 SHOW_STR
12724 IPV6_STR
12725 MBGP_STR
12726 "Detailed information on TCP and BGP neighbor connections\n"
12727 "Neighbor to display information about\n"
12728 "Neighbor to display information about\n"
12729 "Neighbor on bgp configured interface\n"
12730 "Neighbor on bgp configured interface\n"
12731 "Display the routes advertised to a BGP neighbor\n"
12732 "JavaScript Object Notation\n")
12733 {
12734 struct peer *peer;
12735 u_char uj = use_json(argc, argv);
12736
12737 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12738 if (! peer)
12739 return CMD_WARNING;
12740
12741 bgp_show_ipv6_bgp_deprecate_warning(vty);
12742 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12743 }
12744 #endif /* HAVE_IPV6 */
12745
12746 DEFUN (show_bgp_instance_neighbor_received_routes,
12747 show_bgp_instance_neighbor_received_routes_cmd,
12748 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12749 SHOW_STR
12750 BGP_STR
12751 BGP_INSTANCE_HELP_STR
12752 "Detailed information on TCP and BGP neighbor connections\n"
12753 "Neighbor to display information about\n"
12754 "Neighbor to display information about\n"
12755 "Neighbor on bgp configured interface\n"
12756 "Display the received routes from neighbor\n"
12757 "JavaScript Object Notation\n")
12758 {
12759 struct peer *peer;
12760 u_char uj = use_json(argc, argv);
12761
12762 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12763 if (! peer)
12764 return CMD_WARNING;
12765
12766 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12767 }
12768
12769 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12770 show_ip_bgp_instance_neighbor_received_routes_cmd,
12771 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12772 SHOW_STR
12773 IP_STR
12774 BGP_STR
12775 BGP_INSTANCE_HELP_STR
12776 "Detailed information on TCP and BGP neighbor connections\n"
12777 "Neighbor to display information about\n"
12778 "Neighbor to display information about\n"
12779 "Neighbor on bgp configured interface\n"
12780 "Display the received routes from neighbor\n"
12781 "JavaScript Object Notation\n")
12782 {
12783 struct peer *peer;
12784 u_char uj = use_json(argc, argv);
12785
12786 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12787 if (! peer)
12788 return CMD_WARNING;
12789
12790 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12791 }
12792
12793 ALIAS (show_bgp_instance_neighbor_received_routes,
12794 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12795 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12796 SHOW_STR
12797 BGP_STR
12798 BGP_INSTANCE_HELP_STR
12799 "Address family\n"
12800 "Detailed information on TCP and BGP neighbor connections\n"
12801 "Neighbor to display information about\n"
12802 "Neighbor to display information about\n"
12803 "Neighbor on bgp configured interface\n"
12804 "Display the received routes from neighbor\n"
12805 "JavaScript Object Notation\n")
12806
12807 DEFUN (show_ip_bgp_neighbor_received_routes,
12808 show_ip_bgp_neighbor_received_routes_cmd,
12809 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12810 SHOW_STR
12811 IP_STR
12812 BGP_STR
12813 "Detailed information on TCP and BGP neighbor connections\n"
12814 "Neighbor to display information about\n"
12815 "Neighbor to display information about\n"
12816 "Neighbor on bgp configured interface\n"
12817 "Display the received routes from neighbor\n"
12818 "JavaScript Object Notation\n")
12819
12820 {
12821 struct peer *peer;
12822 const char *rmap_name = NULL;
12823 u_char uj = use_json(argc, argv);
12824
12825 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12826
12827 if (! peer)
12828 return CMD_WARNING;
12829
12830 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12831 rmap_name = argv[1];
12832
12833 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12834 }
12835
12836 ALIAS (show_ip_bgp_neighbor_received_routes,
12837 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12838 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12839 SHOW_STR
12840 IP_STR
12841 BGP_STR
12842 "Detailed information on TCP and BGP neighbor connections\n"
12843 "Neighbor to display information about\n"
12844 "Neighbor to display information about\n"
12845 "Neighbor on bgp configured interface\n"
12846 "Display the received routes from neighbor\n"
12847 "JavaScript Object Notation\n")
12848
12849 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12850 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12851 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12852 SHOW_STR
12853 IP_STR
12854 BGP_STR
12855 BGP_INSTANCE_HELP_STR
12856 "Detailed information on TCP and BGP neighbor connections\n"
12857 "Neighbor to display information about\n"
12858 "Neighbor to display information about\n"
12859 "Neighbor on bgp configured interface\n"
12860 "Display the received routes from neighbor\n"
12861 "JavaScript Object Notation\n")
12862
12863 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12864 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12865 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12866 SHOW_STR
12867 IP_STR
12868 BGP_STR
12869 "Address family\n"
12870 "Address Family modifier\n"
12871 "Address Family modifier\n"
12872 "Detailed information on TCP and BGP neighbor connections\n"
12873 "Neighbor to display information about\n"
12874 "Neighbor to display information about\n"
12875 "Neighbor on bgp configured interface\n"
12876 "Display the received routes from neighbor\n"
12877 "JavaScript Object Notation\n")
12878 {
12879 struct peer *peer;
12880 const char *rmap_name = NULL;
12881 safi_t safi;
12882 u_char uj = use_json(argc, argv);
12883
12884 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12885 if (! peer)
12886 return CMD_WARNING;
12887
12888 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12889 rmap_name = argv[2];
12890
12891 safi = bgp_vty_safi_from_arg(argv[0]);
12892 return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj);
12893 }
12894
12895 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12896 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12897 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12898 SHOW_STR
12899 IP_STR
12900 BGP_STR
12901 "Address family\n"
12902 "Address Family modifier\n"
12903 "Address Family modifier\n"
12904 "Detailed information on TCP and BGP neighbor connections\n"
12905 "Neighbor to display information about\n"
12906 "Neighbor to display information about\n"
12907 "Neighbor on bgp configured interface\n"
12908 "Display the received routes from neighbor\n"
12909 "JavaScript Object Notation\n")
12910
12911 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12912 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12913 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12914 SHOW_STR
12915 BGP_STR
12916 BGP_INSTANCE_HELP_STR
12917 "Address family\n"
12918 "Address family\n"
12919 "Address family modifier\n"
12920 "Address family modifier\n"
12921 "Detailed information on TCP and BGP neighbor connections\n"
12922 "Neighbor to display information about\n"
12923 "Neighbor to display information about\n"
12924 "Neighbor on bgp configured interface\n"
12925 "Display the advertised routes to neighbor\n"
12926 "Display the received routes from neighbor\n"
12927 "JavaScript Object Notation\n")
12928 {
12929 int afi;
12930 int safi;
12931 int in;
12932 struct peer *peer;
12933 u_char uj = use_json(argc, argv);
12934
12935 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12936
12937 if (! peer)
12938 return CMD_WARNING;
12939
12940 afi = bgp_vty_safi_from_arg(argv[2]);
12941 safi = bgp_vty_safi_from_arg(argv[3]);
12942 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12943
12944 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12945 }
12946
12947 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12948 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12949 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12950 SHOW_STR
12951 IP_STR
12952 BGP_STR
12953 "Detailed information on TCP and BGP neighbor connections\n"
12954 "Neighbor to display information about\n"
12955 "Neighbor to display information about\n"
12956 "Neighbor on bgp configured interface\n"
12957 "Display information received from a BGP neighbor\n"
12958 "Display the prefixlist filter\n"
12959 "JavaScript Object Notation\n")
12960 {
12961 char name[BUFSIZ];
12962 union sockunion su;
12963 struct peer *peer;
12964 int count, ret;
12965 u_char uj = use_json(argc, argv);
12966
12967 ret = str2sockunion (argv[0], &su);
12968 if (ret < 0)
12969 {
12970 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12971 if (! peer)
12972 {
12973 if (uj)
12974 {
12975 json_object *json_no = NULL;
12976 json_object *json_sub = NULL;
12977 json_no = json_object_new_object();
12978 json_sub = json_object_new_object();
12979 json_object_string_add(json_no, "warning", "Malformed address or name");
12980 json_object_string_add(json_sub, "warningCause", argv[0]);
12981 json_object_object_add(json_no, "detail", json_sub);
12982 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12983 json_object_free(json_no);
12984 }
12985 else
12986 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12987 return CMD_WARNING;
12988 }
12989 }
12990 else
12991 {
12992 peer = peer_lookup (NULL, &su);
12993 if (! peer)
12994 {
12995 if (uj)
12996 {
12997 json_object *json_no = NULL;
12998 json_no = json_object_new_object();
12999 json_object_string_add(json_no, "warning", "Peer not found");
13000 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13001 json_object_free(json_no);
13002 }
13003 else
13004 vty_out (vty, "No peer%s", VTY_NEWLINE);
13005 return CMD_WARNING;
13006 }
13007 }
13008
13009 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13010 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13011 if (count)
13012 {
13013 if (!uj)
13014 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13015 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13016 }
13017 else
13018 {
13019 if (uj)
13020 {
13021 json_object *json_no = NULL;
13022 json_no = json_object_new_object();
13023 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13024 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13025 json_object_free(json_no);
13026 }
13027 else
13028 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13029 }
13030
13031 return CMD_SUCCESS;
13032 }
13033
13034 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13035 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13036 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13037 SHOW_STR
13038 IP_STR
13039 BGP_STR
13040 "Address family\n"
13041 "Address Family modifier\n"
13042 "Address Family modifier\n"
13043 "Detailed information on TCP and BGP neighbor connections\n"
13044 "Neighbor to display information about\n"
13045 "Neighbor to display information about\n"
13046 "Neighbor on bgp configured interface\n"
13047 "Display information received from a BGP neighbor\n"
13048 "Display the prefixlist filter\n"
13049 "JavaScript Object Notation\n")
13050 {
13051 char name[BUFSIZ];
13052 union sockunion su;
13053 struct peer *peer;
13054 int count, ret;
13055 u_char uj = use_json(argc, argv);
13056
13057 ret = str2sockunion (argv[1], &su);
13058 if (ret < 0)
13059 {
13060 peer = peer_lookup_by_conf_if (NULL, argv[1]);
13061 if (! peer)
13062 {
13063 if (uj)
13064 {
13065 json_object *json_no = NULL;
13066 json_object *json_sub = NULL;
13067 json_no = json_object_new_object();
13068 json_sub = json_object_new_object();
13069 json_object_string_add(json_no, "warning", "Malformed address or name");
13070 json_object_string_add(json_sub, "warningCause", argv[1]);
13071 json_object_object_add(json_no, "detail", json_sub);
13072 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13073 json_object_free(json_no);
13074 }
13075 else
13076 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
13077 return CMD_WARNING;
13078 }
13079 }
13080 else
13081 {
13082 peer = peer_lookup (NULL, &su);
13083 if (! peer)
13084 {
13085 if (uj)
13086 {
13087 json_object *json_no = NULL;
13088 json_no = json_object_new_object();
13089 json_object_string_add(json_no, "warning", "Peer not found");
13090 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13091 json_object_free(json_no);
13092 }
13093 else
13094 vty_out (vty, "No peer%s", VTY_NEWLINE);
13095 return CMD_WARNING;
13096 }
13097 }
13098
13099 {
13100 safi_t safi;
13101 safi = bgp_vty_safi_from_arg(argv[0]);
13102 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13103 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13104 if (count)
13105 {
13106 if (!uj)
13107 vty_out (vty, "Address family: %s%s",
13108 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
13109 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13110 }
13111 else
13112 {
13113 if (uj)
13114 {
13115 json_object *json_no = NULL;
13116 json_no = json_object_new_object();
13117 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13118 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13119 json_object_free(json_no);
13120 }
13121 else
13122 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13123 }
13124 }
13125
13126 return CMD_SUCCESS;
13127 }
13128 #ifdef HAVE_IPV6
13129 DEFUN (show_bgp_neighbor_received_routes,
13130 show_bgp_neighbor_received_routes_cmd,
13131 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13132 SHOW_STR
13133 BGP_STR
13134 "Detailed information on TCP and BGP neighbor connections\n"
13135 "Neighbor to display information about\n"
13136 "Neighbor to display information about\n"
13137 "Neighbor on bgp configured interface\n"
13138 "Display the received routes from neighbor\n"
13139 "JavaScript Object Notation\n")
13140 {
13141 struct peer *peer;
13142 const char *rmap_name = NULL;
13143 u_char uj = use_json(argc, argv);
13144
13145 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13146
13147 if (! peer)
13148 return CMD_WARNING;
13149
13150 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13151 rmap_name = argv[1];
13152
13153 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13154 }
13155
13156 ALIAS (show_bgp_neighbor_received_routes,
13157 show_bgp_ipv6_neighbor_received_routes_cmd,
13158 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13159 SHOW_STR
13160 BGP_STR
13161 "Address family\n"
13162 "Detailed information on TCP and BGP neighbor connections\n"
13163 "Neighbor to display information about\n"
13164 "Neighbor to display information about\n"
13165 "Neighbor on bgp configured interface\n"
13166 "Display the received routes from neighbor\n"
13167 "JavaScript Object Notation\n")
13168
13169 DEFUN (show_bgp_neighbor_received_prefix_filter,
13170 show_bgp_neighbor_received_prefix_filter_cmd,
13171 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13172 SHOW_STR
13173 BGP_STR
13174 "Detailed information on TCP and BGP neighbor connections\n"
13175 "Neighbor to display information about\n"
13176 "Neighbor to display information about\n"
13177 "Neighbor on bgp configured interface\n"
13178 "Display information received from a BGP neighbor\n"
13179 "Display the prefixlist filter\n"
13180 "JavaScript Object Notation\n")
13181 {
13182 char name[BUFSIZ];
13183 union sockunion su;
13184 struct peer *peer;
13185 int count, ret;
13186 u_char uj = use_json(argc, argv);
13187
13188 ret = str2sockunion (argv[0], &su);
13189 if (ret < 0)
13190 {
13191 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13192 if (! peer)
13193 {
13194 if (uj)
13195 {
13196 json_object *json_no = NULL;
13197 json_object *json_sub = NULL;
13198 json_no = json_object_new_object();
13199 json_sub = json_object_new_object();
13200 json_object_string_add(json_no, "warning", "Malformed address or name");
13201 json_object_string_add(json_sub, "warningCause", argv[0]);
13202 json_object_object_add(json_no, "detail", json_sub);
13203 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13204 json_object_free(json_no);
13205 }
13206 else
13207 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13208 return CMD_WARNING;
13209 }
13210 }
13211 else
13212 {
13213 peer = peer_lookup (NULL, &su);
13214 if (! peer)
13215 {
13216 if (uj)
13217 {
13218 json_object *json_no = NULL;
13219 json_no = json_object_new_object();
13220 json_object_string_add(json_no, "warning", "No Peer");
13221 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13222 json_object_free(json_no);
13223 }
13224 else
13225 vty_out (vty, "No peer%s", VTY_NEWLINE);
13226 return CMD_WARNING;
13227 }
13228 }
13229
13230 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13231 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13232 if (count)
13233 {
13234 if (!uj)
13235 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13236 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13237 }
13238 else
13239 {
13240 if (uj)
13241 {
13242 json_object *json_no = NULL;
13243 json_no = json_object_new_object();
13244 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13245 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13246 json_object_free(json_no);
13247 }
13248 else
13249 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13250 }
13251
13252 return CMD_SUCCESS;
13253 }
13254
13255 ALIAS (show_bgp_neighbor_received_prefix_filter,
13256 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13257 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13258 SHOW_STR
13259 BGP_STR
13260 "Address family\n"
13261 "Detailed information on TCP and BGP neighbor connections\n"
13262 "Neighbor to display information about\n"
13263 "Neighbor to display information about\n"
13264 "Neighbor on bgp configured interface\n"
13265 "Display information received from a BGP neighbor\n"
13266 "Display the prefixlist filter\n"
13267 "JavaScript Object Notation\n")
13268
13269 /* old command */
13270 ALIAS (show_bgp_neighbor_received_routes,
13271 ipv6_bgp_neighbor_received_routes_cmd,
13272 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13273 SHOW_STR
13274 IPV6_STR
13275 BGP_STR
13276 "Detailed information on TCP and BGP neighbor connections\n"
13277 "Neighbor to display information about\n"
13278 "Neighbor to display information about\n"
13279 "Neighbor on bgp configured interface\n"
13280 "Display the received routes from neighbor\n"
13281 "JavaScript Object Notation\n")
13282
13283 /* old command */
13284 DEFUN (ipv6_mbgp_neighbor_received_routes,
13285 ipv6_mbgp_neighbor_received_routes_cmd,
13286 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13287 SHOW_STR
13288 IPV6_STR
13289 MBGP_STR
13290 "Detailed information on TCP and BGP neighbor connections\n"
13291 "Neighbor to display information about\n"
13292 "Neighbor to display information about\n"
13293 "Neighbor on bgp configured interface\n"
13294 "Display the received routes from neighbor\n"
13295 "JavaScript Object Notation\n")
13296 {
13297 struct peer *peer;
13298 u_char uj = use_json(argc, argv);
13299
13300 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13301 if (! peer)
13302 return CMD_WARNING;
13303
13304 bgp_show_ipv6_bgp_deprecate_warning(vty);
13305 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13306 }
13307
13308 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13309 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13310 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13311 SHOW_STR
13312 BGP_STR
13313 BGP_INSTANCE_HELP_STR
13314 "Detailed information on TCP and BGP neighbor connections\n"
13315 "Neighbor to display information about\n"
13316 "Neighbor to display information about\n"
13317 "Neighbor on bgp configured interface\n"
13318 "Display information received from a BGP neighbor\n"
13319 "Display the prefixlist filter\n"
13320 "JavaScript Object Notation\n")
13321 {
13322 char name[BUFSIZ];
13323 union sockunion su;
13324 struct peer *peer;
13325 struct bgp *bgp;
13326 int count, ret;
13327 u_char uj = use_json(argc, argv);
13328
13329 /* BGP structure lookup. */
13330 bgp = bgp_lookup_by_name (argv[1]);
13331 if (bgp == NULL)
13332 {
13333 if (uj)
13334 {
13335 json_object *json_no = NULL;
13336 json_no = json_object_new_object();
13337 json_object_string_add(json_no, "warning", "Can't find BGP view");
13338 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13339 json_object_free(json_no);
13340 }
13341 else
13342 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13343 return CMD_WARNING;
13344 }
13345
13346 ret = str2sockunion (argv[2], &su);
13347 if (ret < 0)
13348 {
13349 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13350 if (! peer)
13351 {
13352 if (uj)
13353 {
13354 json_object *json_no = NULL;
13355 json_object *json_sub = NULL;
13356 json_no = json_object_new_object();
13357 json_sub = json_object_new_object();
13358 json_object_string_add(json_no, "warning", "Malformed address or name");
13359 json_object_string_add(json_sub, "warningCause", argv[2]);
13360 json_object_object_add(json_no, "detail", json_sub);
13361 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13362 json_object_free(json_no);
13363 }
13364 else
13365 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13366 return CMD_WARNING;
13367 }
13368 }
13369 else
13370 {
13371 peer = peer_lookup (bgp, &su);
13372 if (! peer)
13373 {
13374 if (uj)
13375 {
13376 json_object *json_no = NULL;
13377 json_no = json_object_new_object();
13378 json_object_boolean_true_add(json_no, "noPeer");
13379 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13380 json_object_free(json_no);
13381 }
13382 else
13383 vty_out (vty, "No peer%s", VTY_NEWLINE);
13384 return CMD_WARNING;
13385 }
13386
13387 }
13388
13389 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13390 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13391 if (count)
13392 {
13393 if (!uj)
13394 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13395 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13396 }
13397
13398 return CMD_SUCCESS;
13399 }
13400 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13401 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13402 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13403 SHOW_STR
13404 BGP_STR
13405 BGP_INSTANCE_HELP_STR
13406 "Address family\n"
13407 "Detailed information on TCP and BGP neighbor connections\n"
13408 "Neighbor to display information about\n"
13409 "Neighbor to display information about\n"
13410 "Neighbor on bgp configured interface\n"
13411 "Display information received from a BGP neighbor\n"
13412 "Display the prefixlist filter\n"
13413 "JavaScript Object NOtation\n")
13414 #endif /* HAVE_IPV6 */
13415
13416 static int
13417 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13418 safi_t safi, enum bgp_show_type type, u_char use_json)
13419 {
13420 if (! peer || ! peer->afc[afi][safi])
13421 {
13422 if (use_json)
13423 {
13424 json_object *json_no = NULL;
13425 json_no = json_object_new_object();
13426 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13427 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13428 json_object_free(json_no);
13429 }
13430 else
13431 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13432 return CMD_WARNING;
13433 }
13434
13435 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13436 }
13437
13438 DEFUN (show_ip_bgp_neighbor_routes,
13439 show_ip_bgp_neighbor_routes_cmd,
13440 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13441 SHOW_STR
13442 IP_STR
13443 BGP_STR
13444 "Detailed information on TCP and BGP neighbor connections\n"
13445 "Neighbor to display information about\n"
13446 "Neighbor to display information about\n"
13447 "Neighbor on bgp configured interface\n"
13448 "Display routes learned from neighbor\n"
13449 "JavaScript Object Notation\n")
13450 {
13451 struct peer *peer;
13452 u_char uj = use_json(argc, argv);
13453
13454 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13455 if (! peer)
13456 return CMD_WARNING;
13457
13458 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13459 bgp_show_type_neighbor, uj);
13460 }
13461
13462 DEFUN (show_ip_bgp_instance_neighbor_routes,
13463 show_ip_bgp_instance_neighbor_routes_cmd,
13464 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13465 SHOW_STR
13466 IP_STR
13467 BGP_STR
13468 BGP_INSTANCE_HELP_STR
13469 "Detailed information on TCP and BGP neighbor connections\n"
13470 "Neighbor to display information about\n"
13471 "Neighbor to display information about\n"
13472 "Neighbor on bgp configured interface\n"
13473 "Display routes learned from neighbor\n"
13474 "JavaScript Object Notation\n")
13475 {
13476 struct peer *peer;
13477 u_char uj = use_json(argc, argv);
13478
13479 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13480 if (! peer)
13481 return CMD_WARNING;
13482
13483 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13484 bgp_show_type_neighbor, uj);
13485 }
13486
13487 DEFUN (show_ip_bgp_neighbor_flap,
13488 show_ip_bgp_neighbor_flap_cmd,
13489 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13490 SHOW_STR
13491 IP_STR
13492 BGP_STR
13493 "Detailed information on TCP and BGP neighbor connections\n"
13494 "Neighbor to display information about\n"
13495 "Neighbor to display information about\n"
13496 "Neighbor on bgp configured interface\n"
13497 "Display flap statistics of the routes learned from neighbor\n"
13498 "JavaScript Object Notation\n")
13499 {
13500 struct peer *peer;
13501 u_char uj = use_json(argc, argv);
13502
13503 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13504 if (! peer)
13505 return CMD_WARNING;
13506
13507 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13508 bgp_show_type_flap_neighbor, uj);
13509 }
13510
13511 DEFUN (show_ip_bgp_neighbor_damp,
13512 show_ip_bgp_neighbor_damp_cmd,
13513 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13514 SHOW_STR
13515 IP_STR
13516 BGP_STR
13517 "Detailed information on TCP and BGP neighbor connections\n"
13518 "Neighbor to display information about\n"
13519 "Neighbor to display information about\n"
13520 "Neighbor on bgp configured interface\n"
13521 "Display the dampened routes received from neighbor\n"
13522 "JavaScript Object Notation\n")
13523 {
13524 struct peer *peer;
13525 u_char uj = use_json(argc, argv);
13526
13527 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13528 if (! peer)
13529 return CMD_WARNING;
13530
13531 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13532 bgp_show_type_damp_neighbor, uj);
13533 }
13534
13535 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13536 show_ip_bgp_ipv4_neighbor_routes_cmd,
13537 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13538 SHOW_STR
13539 IP_STR
13540 BGP_STR
13541 "Address family\n"
13542 "Address Family modifier\n"
13543 "Address Family modifier\n"
13544 "Detailed information on TCP and BGP neighbor connections\n"
13545 "Neighbor to display information about\n"
13546 "Neighbor to display information about\n"
13547 "Neighbor on bgp configured interface\n"
13548 "Display routes learned from neighbor\n"
13549 "JavaScript Object Notation\n")
13550 {
13551 struct peer *peer;
13552 safi_t safi;
13553 u_char uj = use_json(argc, argv);
13554
13555 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13556 if (! peer)
13557 return CMD_WARNING;
13558
13559 safi = bgp_vty_safi_from_arg(argv[0]);
13560 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
13561 bgp_show_type_neighbor, uj);
13562 }
13563
13564 #ifdef HAVE_IPV6
13565 DEFUN (show_bgp_instance_neighbor_routes,
13566 show_bgp_instance_neighbor_routes_cmd,
13567 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13568 SHOW_STR
13569 BGP_STR
13570 BGP_INSTANCE_HELP_STR
13571 "Detailed information on TCP and BGP neighbor connections\n"
13572 "Neighbor to display information about\n"
13573 "Neighbor to display information about\n"
13574 "Neighbor on bgp configured interface\n"
13575 "Display routes learned from neighbor\n"
13576 "JavaScript Object Notation\n")
13577 {
13578 struct peer *peer;
13579 u_char uj = use_json(argc, argv);
13580
13581 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13582 if (! peer)
13583 return CMD_WARNING;
13584
13585 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13586 bgp_show_type_neighbor, uj);
13587 }
13588
13589 ALIAS (show_bgp_instance_neighbor_routes,
13590 show_bgp_instance_ipv6_neighbor_routes_cmd,
13591 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13592 SHOW_STR
13593 BGP_STR
13594 BGP_INSTANCE_HELP_STR
13595 "Address family\n"
13596 "Detailed information on TCP and BGP neighbor connections\n"
13597 "Neighbor to display information about\n"
13598 "Neighbor to display information about\n"
13599 "Neighbor on bgp configured interface\n"
13600 "Display routes learned from neighbor\n"
13601 "JavaScript Object Notation\n")
13602
13603 DEFUN (show_bgp_instance_neighbor_damp,
13604 show_bgp_instance_neighbor_damp_cmd,
13605 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13606 SHOW_STR
13607 BGP_STR
13608 BGP_INSTANCE_HELP_STR
13609 "Detailed information on TCP and BGP neighbor connections\n"
13610 "Neighbor to display information about\n"
13611 "Neighbor to display information about\n"
13612 "Neighbor on bgp configured interface\n"
13613 "Display the dampened routes received from neighbor\n"
13614 "JavaScript Object Notation\n")
13615 {
13616 struct peer *peer;
13617 u_char uj = use_json(argc, argv);
13618
13619 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13620 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13621 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13622 else
13623 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13624
13625 if (! peer)
13626 return CMD_WARNING;
13627
13628 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13629 bgp_show_type_damp_neighbor, uj);
13630 }
13631
13632 ALIAS (show_bgp_instance_neighbor_damp,
13633 show_bgp_instance_ipv6_neighbor_damp_cmd,
13634 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13635 SHOW_STR
13636 BGP_STR
13637 BGP_INSTANCE_HELP_STR
13638 "Address family\n"
13639 "Detailed information on TCP and BGP neighbor connections\n"
13640 "Neighbor to display information about\n"
13641 "Neighbor to display information about\n"
13642 "Neighbor on bgp configured interface\n"
13643 "Display the dampened routes received from neighbor\n"
13644 "JavaScript Object Notation\n")
13645
13646 DEFUN (show_bgp_instance_neighbor_flap,
13647 show_bgp_instance_neighbor_flap_cmd,
13648 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13649 SHOW_STR
13650 BGP_STR
13651 BGP_INSTANCE_HELP_STR
13652 "Detailed information on TCP and BGP neighbor connections\n"
13653 "Neighbor to display information about\n"
13654 "Neighbor to display information about\n"
13655 "Neighbor on bgp configured interface\n"
13656 "Display flap statistics of the routes learned from neighbor\n"
13657 "JavaScript Object Notation\n")
13658 {
13659 struct peer *peer;
13660 u_char uj = use_json(argc, argv);
13661
13662 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13663 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13664 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13665 else
13666 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13667
13668 if (! peer)
13669 return CMD_WARNING;
13670
13671 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13672 bgp_show_type_flap_neighbor, uj);
13673 }
13674
13675 ALIAS (show_bgp_instance_neighbor_flap,
13676 show_bgp_instance_ipv6_neighbor_flap_cmd,
13677 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13678 SHOW_STR
13679 BGP_STR
13680 BGP_INSTANCE_HELP_STR
13681 "Address family\n"
13682 "Detailed information on TCP and BGP neighbor connections\n"
13683 "Neighbor to display information about\n"
13684 "Neighbor to display information about\n"
13685 "Neighbor on bgp configured interface\n"
13686 "Display flap statistics of the routes learned from neighbor\n"
13687 "JavaScript Object Notation\n")
13688
13689 DEFUN (show_bgp_neighbor_routes,
13690 show_bgp_neighbor_routes_cmd,
13691 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13692 SHOW_STR
13693 BGP_STR
13694 "Detailed information on TCP and BGP neighbor connections\n"
13695 "Neighbor to display information about\n"
13696 "Neighbor to display information about\n"
13697 "Neighbor on bgp configured interface\n"
13698 "Display routes learned from neighbor\n"
13699 "JavaScript Object Notation\n")
13700 {
13701 struct peer *peer;
13702 u_char uj = use_json(argc, argv);
13703
13704 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13705 if (! peer)
13706 return CMD_WARNING;
13707
13708 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13709 bgp_show_type_neighbor, uj);
13710 }
13711
13712
13713 ALIAS (show_bgp_neighbor_routes,
13714 show_bgp_ipv6_neighbor_routes_cmd,
13715 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13716 SHOW_STR
13717 BGP_STR
13718 "Address family\n"
13719 "Detailed information on TCP and BGP neighbor connections\n"
13720 "Neighbor to display information about\n"
13721 "Neighbor to display information about\n"
13722 "Neighbor on bgp configured interface\n"
13723 "Display routes learned from neighbor\n"
13724 "JavaScript Object Notation\n")
13725
13726 /* old command */
13727 ALIAS (show_bgp_neighbor_routes,
13728 ipv6_bgp_neighbor_routes_cmd,
13729 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13730 SHOW_STR
13731 IPV6_STR
13732 BGP_STR
13733 "Detailed information on TCP and BGP neighbor connections\n"
13734 "Neighbor to display information about\n"
13735 "Neighbor to display information about\n"
13736 "Neighbor on bgp configured interface\n"
13737 "Display routes learned from neighbor\n"
13738 "JavaScript Object Notation\n")
13739
13740 /* old command */
13741 DEFUN (ipv6_mbgp_neighbor_routes,
13742 ipv6_mbgp_neighbor_routes_cmd,
13743 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13744 SHOW_STR
13745 IPV6_STR
13746 MBGP_STR
13747 "Detailed information on TCP and BGP neighbor connections\n"
13748 "Neighbor to display information about\n"
13749 "Neighbor to display information about\n"
13750 "Neighbor on bgp configured interface\n"
13751 "Display routes learned from neighbor\n"
13752 "JavaScript Object Notation\n")
13753 {
13754 struct peer *peer;
13755 u_char uj = use_json(argc, argv);
13756
13757 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13758 if (! peer)
13759 return CMD_WARNING;
13760
13761 bgp_show_ipv6_bgp_deprecate_warning(vty);
13762 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13763 bgp_show_type_neighbor, uj);
13764 }
13765
13766 ALIAS (show_bgp_instance_neighbor_flap,
13767 show_bgp_neighbor_flap_cmd,
13768 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13769 SHOW_STR
13770 BGP_STR
13771 "Detailed information on TCP and BGP neighbor connections\n"
13772 "Neighbor to display information about\n"
13773 "Neighbor to display information about\n"
13774 "Neighbor on bgp configured interface\n"
13775 "Display flap statistics of the routes learned from neighbor\n"
13776 "JavaScript Object Notation\n")
13777
13778 ALIAS (show_bgp_instance_neighbor_flap,
13779 show_bgp_ipv6_neighbor_flap_cmd,
13780 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13781 SHOW_STR
13782 BGP_STR
13783 "Address family\n"
13784 "Detailed information on TCP and BGP neighbor connections\n"
13785 "Neighbor to display information about\n"
13786 "Neighbor to display information about\n"
13787 "Neighbor on bgp configured interface\n"
13788 "Display flap statistics of the routes learned from neighbor\n"
13789 "JavaScript Object Notation\n")
13790
13791 ALIAS (show_bgp_instance_neighbor_damp,
13792 show_bgp_neighbor_damp_cmd,
13793 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13794 SHOW_STR
13795 BGP_STR
13796 "Detailed information on TCP and BGP neighbor connections\n"
13797 "Neighbor to display information about\n"
13798 "Neighbor to display information about\n"
13799 "Neighbor on bgp configured interface\n"
13800 "Display the dampened routes received from neighbor\n"
13801 "JavaScript Object Notation\n")
13802
13803 ALIAS (show_bgp_instance_neighbor_damp,
13804 show_bgp_ipv6_neighbor_damp_cmd,
13805 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13806 SHOW_STR
13807 BGP_STR
13808 "Address family\n"
13809 "Detailed information on TCP and BGP neighbor connections\n"
13810 "Neighbor to display information about\n"
13811 "Neighbor to display information about\n"
13812 "Neighbor on bgp configured interface\n"
13813 "Display the dampened routes received from neighbor\n"
13814 "JavaScript Object Notation\n")
13815
13816 #endif /* HAVE_IPV6 */
13817
13818 struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
13819
13820 struct bgp_distance
13821 {
13822 /* Distance value for the IP source prefix. */
13823 u_char distance;
13824
13825 /* Name of the access-list to be matched. */
13826 char *access_list;
13827 };
13828
13829 static struct bgp_distance *
13830 bgp_distance_new (void)
13831 {
13832 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13833 }
13834
13835 static void
13836 bgp_distance_free (struct bgp_distance *bdistance)
13837 {
13838 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13839 }
13840
13841 static int
13842 bgp_distance_set (struct vty *vty, const char *distance_str,
13843 const char *ip_str, const char *access_list_str)
13844 {
13845 int ret;
13846 afi_t afi;
13847 safi_t safi;
13848 struct prefix p;
13849 u_char distance;
13850 struct bgp_node *rn;
13851 struct bgp_distance *bdistance;
13852
13853 afi = bgp_node_afi (vty);
13854 safi = bgp_node_safi (vty);
13855
13856 ret = str2prefix (ip_str, &p);
13857 if (ret == 0)
13858 {
13859 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13860 return CMD_WARNING;
13861 }
13862
13863 distance = atoi (distance_str);
13864
13865 /* Get BGP distance node. */
13866 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
13867 if (rn->info)
13868 {
13869 bdistance = rn->info;
13870 bgp_unlock_node (rn);
13871 }
13872 else
13873 {
13874 bdistance = bgp_distance_new ();
13875 rn->info = bdistance;
13876 }
13877
13878 /* Set distance value. */
13879 bdistance->distance = distance;
13880
13881 /* Reset access-list configuration. */
13882 if (bdistance->access_list)
13883 {
13884 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13885 bdistance->access_list = NULL;
13886 }
13887 if (access_list_str)
13888 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13889
13890 return CMD_SUCCESS;
13891 }
13892
13893 static int
13894 bgp_distance_unset (struct vty *vty, const char *distance_str,
13895 const char *ip_str, const char *access_list_str)
13896 {
13897 int ret;
13898 afi_t afi;
13899 safi_t safi;
13900 struct prefix p;
13901 int distance;
13902 struct bgp_node *rn;
13903 struct bgp_distance *bdistance;
13904
13905 afi = bgp_node_afi (vty);
13906 safi = bgp_node_safi (vty);
13907
13908 ret = str2prefix (ip_str, &p);
13909 if (ret == 0)
13910 {
13911 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13912 return CMD_WARNING;
13913 }
13914
13915 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
13916 if (! rn)
13917 {
13918 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13919 return CMD_WARNING;
13920 }
13921
13922 bdistance = rn->info;
13923 distance = atoi(distance_str);
13924
13925 if (bdistance->distance != distance)
13926 {
13927 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13928 return CMD_WARNING;
13929 }
13930
13931 if (bdistance->access_list)
13932 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13933 bgp_distance_free (bdistance);
13934
13935 rn->info = NULL;
13936 bgp_unlock_node (rn);
13937 bgp_unlock_node (rn);
13938
13939 return CMD_SUCCESS;
13940 }
13941
13942 /* Apply BGP information to distance method. */
13943 u_char
13944 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
13945 safi_t safi, struct bgp *bgp)
13946 {
13947 struct bgp_node *rn;
13948 struct prefix q;
13949 struct peer *peer;
13950 struct bgp_distance *bdistance;
13951 struct access_list *alist;
13952 struct bgp_static *bgp_static;
13953
13954 if (! bgp)
13955 return 0;
13956
13957 peer = rinfo->peer;
13958
13959 /* Check source address. */
13960 sockunion2hostprefix (&peer->su, &q);
13961 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
13962 if (rn)
13963 {
13964 bdistance = rn->info;
13965 bgp_unlock_node (rn);
13966
13967 if (bdistance->access_list)
13968 {
13969 alist = access_list_lookup (afi, bdistance->access_list);
13970 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13971 return bdistance->distance;
13972 }
13973 else
13974 return bdistance->distance;
13975 }
13976
13977 /* Backdoor check. */
13978 rn = bgp_node_lookup (bgp->route[afi][safi], p);
13979 if (rn)
13980 {
13981 bgp_static = rn->info;
13982 bgp_unlock_node (rn);
13983
13984 if (bgp_static->backdoor)
13985 {
13986 if (bgp->distance_local[afi][safi])
13987 return bgp->distance_local[afi][safi];
13988 else
13989 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13990 }
13991 }
13992
13993 if (peer->sort == BGP_PEER_EBGP)
13994 {
13995 if (bgp->distance_ebgp[afi][safi])
13996 return bgp->distance_ebgp[afi][safi];
13997 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13998 }
13999 else
14000 {
14001 if (bgp->distance_ibgp[afi][safi])
14002 return bgp->distance_ibgp[afi][safi];
14003 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14004 }
14005 }
14006
14007 DEFUN (bgp_distance,
14008 bgp_distance_cmd,
14009 "distance bgp <1-255> <1-255> <1-255>",
14010 "Define an administrative distance\n"
14011 "BGP distance\n"
14012 "Distance for routes external to the AS\n"
14013 "Distance for routes internal to the AS\n"
14014 "Distance for local routes\n")
14015 {
14016 struct bgp *bgp;
14017 afi_t afi;
14018 safi_t safi;
14019
14020 bgp = vty->index;
14021 afi = bgp_node_afi (vty);
14022 safi = bgp_node_safi (vty);
14023
14024 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
14025 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
14026 bgp->distance_local[afi][safi] = atoi (argv[2]);
14027 return CMD_SUCCESS;
14028 }
14029
14030 DEFUN (no_bgp_distance,
14031 no_bgp_distance_cmd,
14032 "no distance bgp <1-255> <1-255> <1-255>",
14033 NO_STR
14034 "Define an administrative distance\n"
14035 "BGP distance\n"
14036 "Distance for routes external to the AS\n"
14037 "Distance for routes internal to the AS\n"
14038 "Distance for local routes\n")
14039 {
14040 struct bgp *bgp;
14041 afi_t afi;
14042 safi_t safi;
14043
14044 bgp = vty->index;
14045 afi = bgp_node_afi (vty);
14046 safi = bgp_node_safi (vty);
14047
14048 bgp->distance_ebgp[afi][safi] = 0;
14049 bgp->distance_ibgp[afi][safi] = 0;
14050 bgp->distance_local[afi][safi] = 0;
14051 return CMD_SUCCESS;
14052 }
14053
14054 ALIAS (no_bgp_distance,
14055 no_bgp_distance2_cmd,
14056 "no distance bgp",
14057 NO_STR
14058 "Define an administrative distance\n"
14059 "BGP distance\n")
14060
14061 DEFUN (bgp_distance_source,
14062 bgp_distance_source_cmd,
14063 "distance <1-255> A.B.C.D/M",
14064 "Define an administrative distance\n"
14065 "Administrative distance\n"
14066 "IP source prefix\n")
14067 {
14068 bgp_distance_set (vty, argv[0], argv[1], NULL);
14069 return CMD_SUCCESS;
14070 }
14071
14072 DEFUN (no_bgp_distance_source,
14073 no_bgp_distance_source_cmd,
14074 "no distance <1-255> A.B.C.D/M",
14075 NO_STR
14076 "Define an administrative distance\n"
14077 "Administrative distance\n"
14078 "IP source prefix\n")
14079 {
14080 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14081 return CMD_SUCCESS;
14082 }
14083
14084 DEFUN (bgp_distance_source_access_list,
14085 bgp_distance_source_access_list_cmd,
14086 "distance <1-255> A.B.C.D/M WORD",
14087 "Define an administrative distance\n"
14088 "Administrative distance\n"
14089 "IP source prefix\n"
14090 "Access list name\n")
14091 {
14092 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14093 return CMD_SUCCESS;
14094 }
14095
14096 DEFUN (no_bgp_distance_source_access_list,
14097 no_bgp_distance_source_access_list_cmd,
14098 "no distance <1-255> A.B.C.D/M WORD",
14099 NO_STR
14100 "Define an administrative distance\n"
14101 "Administrative distance\n"
14102 "IP source prefix\n"
14103 "Access list name\n")
14104 {
14105 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14106 return CMD_SUCCESS;
14107 }
14108
14109 DEFUN (ipv6_bgp_distance_source,
14110 ipv6_bgp_distance_source_cmd,
14111 "distance <1-255> X:X::X:X/M",
14112 "Define an administrative distance\n"
14113 "Administrative distance\n"
14114 "IP source prefix\n")
14115 {
14116 bgp_distance_set (vty, argv[0], argv[1], NULL);
14117 return CMD_SUCCESS;
14118 }
14119
14120 DEFUN (no_ipv6_bgp_distance_source,
14121 no_ipv6_bgp_distance_source_cmd,
14122 "no distance <1-255> X:X::X:X/M",
14123 NO_STR
14124 "Define an administrative distance\n"
14125 "Administrative distance\n"
14126 "IP source prefix\n")
14127 {
14128 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14129 return CMD_SUCCESS;
14130 }
14131
14132 DEFUN (ipv6_bgp_distance_source_access_list,
14133 ipv6_bgp_distance_source_access_list_cmd,
14134 "distance <1-255> X:X::X:X/M WORD",
14135 "Define an administrative distance\n"
14136 "Administrative distance\n"
14137 "IP source prefix\n"
14138 "Access list name\n")
14139 {
14140 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14141 return CMD_SUCCESS;
14142 }
14143
14144 DEFUN (no_ipv6_bgp_distance_source_access_list,
14145 no_ipv6_bgp_distance_source_access_list_cmd,
14146 "no distance <1-255> X:X::X:X/M WORD",
14147 NO_STR
14148 "Define an administrative distance\n"
14149 "Administrative distance\n"
14150 "IP source prefix\n"
14151 "Access list name\n")
14152 {
14153 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14154 return CMD_SUCCESS;
14155 }
14156
14157 DEFUN (bgp_damp_set,
14158 bgp_damp_set_cmd,
14159 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14160 "BGP Specific commands\n"
14161 "Enable route-flap dampening\n"
14162 "Half-life time for the penalty\n"
14163 "Value to start reusing a route\n"
14164 "Value to start suppressing a route\n"
14165 "Maximum duration to suppress a stable route\n")
14166 {
14167 struct bgp *bgp;
14168 int half = DEFAULT_HALF_LIFE * 60;
14169 int reuse = DEFAULT_REUSE;
14170 int suppress = DEFAULT_SUPPRESS;
14171 int max = 4 * half;
14172
14173 if (argc == 4)
14174 {
14175 half = atoi (argv[0]) * 60;
14176 reuse = atoi (argv[1]);
14177 suppress = atoi (argv[2]);
14178 max = atoi (argv[3]) * 60;
14179 }
14180 else if (argc == 1)
14181 {
14182 half = atoi (argv[0]) * 60;
14183 max = 4 * half;
14184 }
14185
14186 bgp = vty->index;
14187
14188 if (suppress < reuse)
14189 {
14190 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14191 VTY_NEWLINE);
14192 return 0;
14193 }
14194
14195 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14196 half, reuse, suppress, max);
14197 }
14198
14199 ALIAS (bgp_damp_set,
14200 bgp_damp_set2_cmd,
14201 "bgp dampening <1-45>",
14202 "BGP Specific commands\n"
14203 "Enable route-flap dampening\n"
14204 "Half-life time for the penalty\n")
14205
14206 ALIAS (bgp_damp_set,
14207 bgp_damp_set3_cmd,
14208 "bgp dampening",
14209 "BGP Specific commands\n"
14210 "Enable route-flap dampening\n")
14211
14212 DEFUN (bgp_damp_unset,
14213 bgp_damp_unset_cmd,
14214 "no bgp dampening",
14215 NO_STR
14216 "BGP Specific commands\n"
14217 "Enable route-flap dampening\n")
14218 {
14219 struct bgp *bgp;
14220
14221 bgp = vty->index;
14222 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14223 }
14224
14225 ALIAS (bgp_damp_unset,
14226 bgp_damp_unset2_cmd,
14227 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14228 NO_STR
14229 "BGP Specific commands\n"
14230 "Enable route-flap dampening\n"
14231 "Half-life time for the penalty\n"
14232 "Value to start reusing a route\n"
14233 "Value to start suppressing a route\n"
14234 "Maximum duration to suppress a stable route\n")
14235
14236 ALIAS (bgp_damp_unset,
14237 bgp_damp_unset3_cmd,
14238 "no bgp dampening <1-45>",
14239 NO_STR
14240 "BGP Specific commands\n"
14241 "Enable route-flap dampening\n"
14242 "Half-life time for the penalty\n")
14243
14244 DEFUN (show_ip_bgp_dampened_paths,
14245 show_ip_bgp_dampened_paths_cmd,
14246 "show ip bgp dampened-paths",
14247 SHOW_STR
14248 IP_STR
14249 BGP_STR
14250 "Display paths suppressed due to dampening\n")
14251 {
14252 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14253 NULL, 0);
14254 }
14255
14256 ALIAS (show_ip_bgp_dampened_paths,
14257 show_ip_bgp_damp_dampened_paths_cmd,
14258 "show ip bgp dampening dampened-paths",
14259 SHOW_STR
14260 IP_STR
14261 BGP_STR
14262 "Display detailed information about dampening\n"
14263 "Display paths suppressed due to dampening\n")
14264
14265 DEFUN (show_ip_bgp_flap_statistics,
14266 show_ip_bgp_flap_statistics_cmd,
14267 "show ip bgp flap-statistics",
14268 SHOW_STR
14269 IP_STR
14270 BGP_STR
14271 "Display flap statistics of routes\n")
14272 {
14273 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14274 bgp_show_type_flap_statistics, NULL, 0);
14275 }
14276
14277 ALIAS (show_ip_bgp_flap_statistics,
14278 show_ip_bgp_damp_flap_statistics_cmd,
14279 "show ip bgp dampening flap-statistics",
14280 SHOW_STR
14281 IP_STR
14282 BGP_STR
14283 "Display detailed information about dampening\n"
14284 "Display flap statistics of routes\n")
14285
14286 /* Display specified route of BGP table. */
14287 static int
14288 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14289 const char *ip_str, afi_t afi, safi_t safi,
14290 struct prefix_rd *prd, int prefix_check)
14291 {
14292 int ret;
14293 struct prefix match;
14294 struct bgp_node *rn;
14295 struct bgp_node *rm;
14296 struct bgp_info *ri;
14297 struct bgp_info *ri_temp;
14298 struct bgp *bgp;
14299 struct bgp_table *table;
14300
14301 /* BGP structure lookup. */
14302 if (view_name)
14303 {
14304 bgp = bgp_lookup_by_name (view_name);
14305 if (bgp == NULL)
14306 {
14307 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14308 return CMD_WARNING;
14309 }
14310 }
14311 else
14312 {
14313 bgp = bgp_get_default ();
14314 if (bgp == NULL)
14315 {
14316 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14317 return CMD_WARNING;
14318 }
14319 }
14320
14321 /* Check IP address argument. */
14322 ret = str2prefix (ip_str, &match);
14323 if (! ret)
14324 {
14325 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14326 return CMD_WARNING;
14327 }
14328
14329 match.family = afi2family (afi);
14330
14331 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14332 {
14333 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14334 {
14335 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14336 continue;
14337
14338 if ((table = rn->info) != NULL)
14339 if ((rm = bgp_node_match (table, &match)) != NULL)
14340 {
14341 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14342 {
14343 ri = rm->info;
14344 while (ri)
14345 {
14346 if (ri->extra && ri->extra->damp_info)
14347 {
14348 ri_temp = ri->next;
14349 bgp_damp_info_free (ri->extra->damp_info, 1);
14350 ri = ri_temp;
14351 }
14352 else
14353 ri = ri->next;
14354 }
14355 }
14356
14357 bgp_unlock_node (rm);
14358 }
14359 }
14360 }
14361 else
14362 {
14363 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14364 {
14365 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14366 {
14367 ri = rn->info;
14368 while (ri)
14369 {
14370 if (ri->extra && ri->extra->damp_info)
14371 {
14372 ri_temp = ri->next;
14373 bgp_damp_info_free (ri->extra->damp_info, 1);
14374 ri = ri_temp;
14375 }
14376 else
14377 ri = ri->next;
14378 }
14379 }
14380
14381 bgp_unlock_node (rn);
14382 }
14383 }
14384
14385 return CMD_SUCCESS;
14386 }
14387
14388 DEFUN (clear_ip_bgp_dampening,
14389 clear_ip_bgp_dampening_cmd,
14390 "clear ip bgp dampening",
14391 CLEAR_STR
14392 IP_STR
14393 BGP_STR
14394 "Clear route flap dampening information\n")
14395 {
14396 bgp_damp_info_clean ();
14397 return CMD_SUCCESS;
14398 }
14399
14400 DEFUN (clear_ip_bgp_dampening_prefix,
14401 clear_ip_bgp_dampening_prefix_cmd,
14402 "clear ip bgp dampening A.B.C.D/M",
14403 CLEAR_STR
14404 IP_STR
14405 BGP_STR
14406 "Clear route flap dampening information\n"
14407 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14408 {
14409 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14410 SAFI_UNICAST, NULL, 1);
14411 }
14412
14413 DEFUN (clear_ip_bgp_dampening_address,
14414 clear_ip_bgp_dampening_address_cmd,
14415 "clear ip bgp dampening A.B.C.D",
14416 CLEAR_STR
14417 IP_STR
14418 BGP_STR
14419 "Clear route flap dampening information\n"
14420 "Network to clear damping information\n")
14421 {
14422 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14423 SAFI_UNICAST, NULL, 0);
14424 }
14425
14426 DEFUN (clear_ip_bgp_dampening_address_mask,
14427 clear_ip_bgp_dampening_address_mask_cmd,
14428 "clear ip bgp dampening A.B.C.D A.B.C.D",
14429 CLEAR_STR
14430 IP_STR
14431 BGP_STR
14432 "Clear route flap dampening information\n"
14433 "Network to clear damping information\n"
14434 "Network mask\n")
14435 {
14436 int ret;
14437 char prefix_str[BUFSIZ];
14438
14439 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14440 if (! ret)
14441 {
14442 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14443 return CMD_WARNING;
14444 }
14445
14446 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14447 SAFI_UNICAST, NULL, 0);
14448 }
14449
14450 /* also used for encap safi */
14451 static int
14452 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14453 afi_t afi, safi_t safi, int *write)
14454 {
14455 struct bgp_node *prn;
14456 struct bgp_node *rn;
14457 struct bgp_table *table;
14458 struct prefix *p;
14459 struct prefix_rd *prd;
14460 struct bgp_static *bgp_static;
14461 u_int32_t label;
14462 char buf[SU_ADDRSTRLEN];
14463 char rdbuf[RD_ADDRSTRLEN];
14464
14465 /* Network configuration. */
14466 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14467 if ((table = prn->info) != NULL)
14468 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14469 if ((bgp_static = rn->info) != NULL)
14470 {
14471 p = &rn->p;
14472 prd = (struct prefix_rd *) &prn->p;
14473
14474 /* "address-family" display. */
14475 bgp_config_write_family_header (vty, afi, safi, write);
14476
14477 /* "network" configuration display. */
14478 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14479 label = decode_label (bgp_static->tag);
14480
14481 vty_out (vty, " network %s/%d rd %s tag %d",
14482 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14483 p->prefixlen,
14484 rdbuf, label);
14485 vty_out (vty, "%s", VTY_NEWLINE);
14486 }
14487 return 0;
14488 }
14489
14490 /* Configuration of static route announcement and aggregate
14491 information. */
14492 int
14493 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14494 afi_t afi, safi_t safi, int *write)
14495 {
14496 struct bgp_node *rn;
14497 struct prefix *p;
14498 struct bgp_static *bgp_static;
14499 struct bgp_aggregate *bgp_aggregate;
14500 char buf[SU_ADDRSTRLEN];
14501
14502 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14503 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14504
14505 /* Network configuration. */
14506 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14507 if ((bgp_static = rn->info) != NULL)
14508 {
14509 p = &rn->p;
14510
14511 /* "address-family" display. */
14512 bgp_config_write_family_header (vty, afi, safi, write);
14513
14514 /* "network" configuration display. */
14515 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14516 {
14517 u_int32_t destination;
14518 struct in_addr netmask;
14519
14520 destination = ntohl (p->u.prefix4.s_addr);
14521 masklen2ip (p->prefixlen, &netmask);
14522 vty_out (vty, " network %s",
14523 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14524
14525 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14526 || (IN_CLASSB (destination) && p->prefixlen == 16)
14527 || (IN_CLASSA (destination) && p->prefixlen == 8)
14528 || p->u.prefix4.s_addr == 0)
14529 {
14530 /* Natural mask is not display. */
14531 }
14532 else
14533 vty_out (vty, " mask %s", inet_ntoa (netmask));
14534 }
14535 else
14536 {
14537 vty_out (vty, " network %s/%d",
14538 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14539 p->prefixlen);
14540 }
14541
14542 if (bgp_static->rmap.name)
14543 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14544 else
14545 {
14546 if (bgp_static->backdoor)
14547 vty_out (vty, " backdoor");
14548 }
14549
14550 vty_out (vty, "%s", VTY_NEWLINE);
14551 }
14552
14553 /* Aggregate-address configuration. */
14554 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14555 if ((bgp_aggregate = rn->info) != NULL)
14556 {
14557 p = &rn->p;
14558
14559 /* "address-family" display. */
14560 bgp_config_write_family_header (vty, afi, safi, write);
14561
14562 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14563 {
14564 struct in_addr netmask;
14565
14566 masklen2ip (p->prefixlen, &netmask);
14567 vty_out (vty, " aggregate-address %s %s",
14568 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14569 inet_ntoa (netmask));
14570 }
14571 else
14572 {
14573 vty_out (vty, " aggregate-address %s/%d",
14574 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14575 p->prefixlen);
14576 }
14577
14578 if (bgp_aggregate->as_set)
14579 vty_out (vty, " as-set");
14580
14581 if (bgp_aggregate->summary_only)
14582 vty_out (vty, " summary-only");
14583
14584 vty_out (vty, "%s", VTY_NEWLINE);
14585 }
14586
14587 return 0;
14588 }
14589
14590 int
14591 bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14592 safi_t safi, int *write)
14593 {
14594 struct bgp_node *rn;
14595 struct bgp_distance *bdistance;
14596
14597 /* Distance configuration. */
14598 if (bgp->distance_ebgp[afi][safi]
14599 && bgp->distance_ibgp[afi][safi]
14600 && bgp->distance_local[afi][safi]
14601 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14602 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14603 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14604 {
14605 bgp_config_write_family_header (vty, afi, safi, write);
14606 vty_out (vty, " distance bgp %d %d %d%s",
14607 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14608 bgp->distance_local[afi][safi], VTY_NEWLINE);
14609 }
14610
14611 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14612 rn = bgp_route_next (rn))
14613 if ((bdistance = rn->info) != NULL)
14614 {
14615 char buf[PREFIX_STRLEN];
14616
14617 bgp_config_write_family_header (vty, afi, safi, write);
14618 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14619 prefix2str (&rn->p, buf, sizeof (buf)),
14620 bdistance->access_list ? bdistance->access_list : "",
14621 VTY_NEWLINE);
14622 }
14623
14624 return *write;
14625 }
14626
14627 /* Allocate routing table structure and install commands. */
14628 void
14629 bgp_route_init (void)
14630 {
14631 afi_t afi;
14632 safi_t safi;
14633
14634 /* Init BGP distance table. */
14635 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14636 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14637 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
14638
14639 /* IPv4 BGP commands. */
14640 install_element (BGP_NODE, &bgp_table_map_cmd);
14641 install_element (BGP_NODE, &bgp_network_cmd);
14642 install_element (BGP_NODE, &bgp_network_mask_cmd);
14643 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14644 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14645 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14646 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14647 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14648 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14649 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14650 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14651 install_element (BGP_NODE, &no_bgp_network_cmd);
14652 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14653 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14654 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14655 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14656 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14657 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14658 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14659 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14660
14661 install_element (BGP_NODE, &aggregate_address_cmd);
14662 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14663 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14664 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14665 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14666 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14667 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14668 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14669 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14670 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14671 install_element (BGP_NODE, &no_aggregate_address_cmd);
14672 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14673 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14674 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14675 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14676 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14677 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14678 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14679 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14680 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14681
14682 /* IPv4 unicast configuration. */
14683 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14684 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14685 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14686 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14687 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14688 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14689 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14690 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14691 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14692 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14693 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14694 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14695 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14696 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14697
14698 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14699 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14700 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14701 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14702 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14703 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14704 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14705 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14706 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14707 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14708 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14709 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14710 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14711 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14712 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14713 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14714 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14715 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14716 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14717 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14718
14719 /* IPv4 multicast configuration. */
14720 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14721 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14722 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14723 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14724 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14725 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14726 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14727 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14728 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14729 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14730 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14731 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14732 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14733 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14734 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14735 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14736 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14737 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14738 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14739 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14740 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14741 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14742 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14743 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14744 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14745 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14746 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14747 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14748 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14749 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14750 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14751 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14752 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14753 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14754
14755 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14756 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14757 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14758 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14759 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14760 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14761 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14762 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14763 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14764 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14765 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14766 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14767 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14768 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14769 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14770 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14771 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14772 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14773 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14774 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14775
14776 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14778 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14779 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14780 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14781 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14782 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14783 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14784 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14785 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14786 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14787 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14788 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14789 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14790 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14791 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14792 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14793 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14794 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14795 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14796 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14797 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14798 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14799 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14800 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14801 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14802 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14803 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14804 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14805 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14806 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14807 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14811 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14812 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14813 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14814 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14815 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14816 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14817 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14818 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14820 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14821 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14822 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14823 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14825 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14826 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14827 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14828 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14829 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14830 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14832 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14833 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14834 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14835 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14836 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14838 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14839 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14840 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14841 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
14843 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14844 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14845 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14846 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14847 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14848 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14849 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14850 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14851 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14852 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14853 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14854 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14855 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14856 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14857 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14858 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14859 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14860 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14861 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14862
14863 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
14864 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
14865 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
14866 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
14867 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
14868
14869 /* BGP dampening clear commands */
14870 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14871 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14872 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14873 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14874
14875 /* prefix count */
14876 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14877 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14878 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14879 #ifdef HAVE_IPV6
14880 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14881 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14882
14883 /* New config IPv6 BGP commands. */
14884 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14885 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14886 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14887 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14888 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14889 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14890
14891 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14892 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14893 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14894 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14895
14896 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14897 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14898
14899 /* Old config IPv6 BGP commands. */
14900 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14901 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14902
14903 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14904 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14905 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14906 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14907
14908 install_element (VIEW_NODE, &show_bgp_cmd);
14909 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14910 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14911 install_element (VIEW_NODE, &show_bgp_route_cmd);
14912 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14913 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14914 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14915 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14916 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14917 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14918 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14919 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14920 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14921 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14922 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14923 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14924 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14925 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14926 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14927 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14928 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14929 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14930 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14931 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14932 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14933 install_element (VIEW_NODE, &show_bgp_community_cmd);
14934 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14935 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14936 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14937 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14938 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14939 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14940 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14941 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14942 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14943 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14944 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14945 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14946 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14947 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14948 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14949 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14950 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14951 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14952 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14953 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14954 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14955 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14956 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14957 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14958 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14959 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14960 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14961 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14962 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14963 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14964 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14965 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14966 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14967 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14968 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14969 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14970 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14971 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14972 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14973 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14974 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14975 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14976 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14977 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14978 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14979 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14980 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14981 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14982 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14983 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14984 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14985 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14986 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14987 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14988 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14989 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14990 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14991 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14992 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14993 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14994 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14995 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14996 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14997 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14998 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14999 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
15000
15001 /* Statistics */
15002 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15003 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15004 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15005 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15006
15007 /* old command */
15008 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15009 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15010 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15011 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15012 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15013 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15014 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15015 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15016 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15017 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15018 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15019 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15020 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15021 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15022 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15023 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15024 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15025 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15026 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15027 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15028 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15029 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15030 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15031 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15032 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15033 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15034 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15035 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15036 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15037 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15038 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15039 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15040 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15041 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15042 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15043 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15044
15045 /* old command */
15046 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15047 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15048
15049 /* old command */
15050 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15051 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15052
15053 /* old command */
15054 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15055 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15056 #endif /* HAVE_IPV6 */
15057
15058 install_element (BGP_NODE, &bgp_distance_cmd);
15059 install_element (BGP_NODE, &no_bgp_distance_cmd);
15060 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15061 install_element (BGP_NODE, &bgp_distance_source_cmd);
15062 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15063 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15064 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15065 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
15066 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
15067 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
15068 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
15069 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
15070 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
15071 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
15072 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
15073 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
15074 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
15075 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
15076 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
15077 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
15078 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
15079 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
15080 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
15081 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
15082 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
15083 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
15084 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15085 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15086 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15087 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15088 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15089 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15090 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15091 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15092 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15093
15094 install_element (BGP_NODE, &bgp_damp_set_cmd);
15095 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15096 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15097 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15098 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15099 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15100 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15101 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15102 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15103 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15104 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15105 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15106
15107 /* IPv4 Multicast Mode */
15108 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15109 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15110 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15111 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15112 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15113 }
15114
15115 void
15116 bgp_route_finish (void)
15117 {
15118 afi_t afi;
15119 safi_t safi;
15120
15121 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15122 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15123 {
15124 bgp_table_unlock (bgp_distance_table[afi][safi]);
15125 bgp_distance_table[afi][safi] = NULL;
15126 }
15127 }