]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
Merge branch 'cmaster-next' of ssh://stash.cumulusnetworks.com:7999/quag/quagga into...
[mirror_frr.git] / bgpd / bgp_route.c
1 /* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4 This file is part of GNU Zebra.
5
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #include <zebra.h>
22
23 #include "lib/json.h"
24 #include "prefix.h"
25 #include "linklist.h"
26 #include "memory.h"
27 #include "command.h"
28 #include "stream.h"
29 #include "filter.h"
30 #include "str.h"
31 #include "log.h"
32 #include "routemap.h"
33 #include "buffer.h"
34 #include "sockunion.h"
35 #include "plist.h"
36 #include "thread.h"
37 #include "workqueue.h"
38 #include "queue.h"
39 #include "memory.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_table.h"
43 #include "bgpd/bgp_route.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_regex.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_ecommunity.h"
50 #include "bgpd/bgp_clist.h"
51 #include "bgpd/bgp_packet.h"
52 #include "bgpd/bgp_filter.h"
53 #include "bgpd/bgp_fsm.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_nexthop.h"
56 #include "bgpd/bgp_damp.h"
57 #include "bgpd/bgp_advertise.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_nht.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_vty.h"
64
65 /* Extern from bgp_dump.c */
66 extern const char *bgp_origin_str[];
67 extern const char *bgp_origin_long_str[];
68
69 struct bgp_node *
70 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
71 struct prefix_rd *prd)
72 {
73 struct bgp_node *rn;
74 struct bgp_node *prn = NULL;
75
76 assert (table);
77 if (!table)
78 return NULL;
79
80 if (safi == SAFI_MPLS_VPN)
81 {
82 prn = bgp_node_get (table, (struct prefix *) prd);
83
84 if (prn->info == NULL)
85 prn->info = bgp_table_init (afi, safi);
86 else
87 bgp_unlock_node (prn);
88 table = prn->info;
89 }
90
91 rn = bgp_node_get (table, p);
92
93 if (safi == SAFI_MPLS_VPN)
94 rn->prn = prn;
95
96 return rn;
97 }
98
99 /* Allocate bgp_info_extra */
100 static struct bgp_info_extra *
101 bgp_info_extra_new (void)
102 {
103 struct bgp_info_extra *new;
104 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
105 return new;
106 }
107
108 static void
109 bgp_info_extra_free (struct bgp_info_extra **extra)
110 {
111 if (extra && *extra)
112 {
113 if ((*extra)->damp_info)
114 bgp_damp_info_free ((*extra)->damp_info, 0);
115
116 (*extra)->damp_info = NULL;
117
118 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
119
120 *extra = NULL;
121 }
122 }
123
124 /* Get bgp_info extra information for the given bgp_info, lazy allocated
125 * if required.
126 */
127 struct bgp_info_extra *
128 bgp_info_extra_get (struct bgp_info *ri)
129 {
130 if (!ri->extra)
131 ri->extra = bgp_info_extra_new();
132 return ri->extra;
133 }
134
135 /* Free bgp route information. */
136 static void
137 bgp_info_free (struct bgp_info *binfo)
138 {
139 if (binfo->attr)
140 bgp_attr_unintern (&binfo->attr);
141
142 bgp_unlink_nexthop(binfo);
143 bgp_info_extra_free (&binfo->extra);
144 bgp_info_mpath_free (&binfo->mpath);
145
146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
148 XFREE (MTYPE_BGP_ROUTE, binfo);
149 }
150
151 struct bgp_info *
152 bgp_info_lock (struct bgp_info *binfo)
153 {
154 binfo->lock++;
155 return binfo;
156 }
157
158 struct bgp_info *
159 bgp_info_unlock (struct bgp_info *binfo)
160 {
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166 #if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169 #endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174 #if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180 #endif
181
182 return binfo;
183 }
184
185 void
186 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187 {
188 struct bgp_info *top;
189
190 top = rn->info;
191
192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
201 }
202
203 /* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205 static void
206 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
207 {
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
214
215 bgp_info_mpath_dequeue (ri);
216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
218 }
219
220 void
221 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222 {
223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226 }
227
228 /* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231 static void
232 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233 {
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237 }
238
239 /* Adjust pcount as required */
240 static void
241 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242 {
243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
246 assert (ri && ri->peer && ri->peer->bgp);
247
248 table = bgp_node_table (rn);
249
250 if (ri->peer == ri->peer->bgp->peer_self)
251 return;
252
253 if (!BGP_INFO_COUNTABLE (ri)
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
270 else if (BGP_INFO_COUNTABLE (ri)
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
274 ri->peer->pcount[table->afi][table->safi]++;
275 }
276 }
277
278
279 /* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282 void
283 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284 {
285 SET_FLAG (ri->flags, flag);
286
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292 }
293
294 void
295 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296 {
297 UNSET_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 /* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
308 static u_int32_t
309 bgp_med_value (struct attr *attr, struct bgp *bgp)
310 {
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
316 return BGP_MED_MAX;
317 else
318 return 0;
319 }
320 }
321
322 void
323 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
324 {
325 if (ri->addpath_rx_id)
326 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
327 else
328 sprintf(buf, "path %s", ri->peer->host);
329 }
330
331 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
332 static int
333 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
334 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
335 char *pfx_buf)
336 {
337 struct attr *newattr, *existattr;
338 struct attr_extra *newattre, *existattre;
339 bgp_peer_sort_t new_sort;
340 bgp_peer_sort_t exist_sort;
341 u_int32_t new_pref;
342 u_int32_t exist_pref;
343 u_int32_t new_med;
344 u_int32_t exist_med;
345 u_int32_t new_weight;
346 u_int32_t exist_weight;
347 uint32_t newm, existm;
348 struct in_addr new_id;
349 struct in_addr exist_id;
350 int new_cluster;
351 int exist_cluster;
352 int internal_as_route;
353 int confed_as_route;
354 int ret;
355 char new_buf[PATH_ADDPATH_STR_BUFFER];
356 char exist_buf[PATH_ADDPATH_STR_BUFFER];
357
358 *paths_eq = 0;
359
360 /* 0. Null check. */
361 if (new == NULL)
362 {
363 if (debug)
364 zlog_debug("%s: new is NULL", pfx_buf);
365 return 0;
366 }
367
368 if (debug)
369 bgp_info_path_with_addpath_rx_str (new, new_buf);
370
371 if (exist == NULL)
372 {
373 if (debug)
374 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
375 return 1;
376 }
377
378 if (debug)
379 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
380
381 newattr = new->attr;
382 existattr = exist->attr;
383 newattre = newattr->extra;
384 existattre = existattr->extra;
385
386 /* 1. Weight check. */
387 new_weight = exist_weight = 0;
388
389 if (newattre)
390 new_weight = newattre->weight;
391 if (existattre)
392 exist_weight = existattre->weight;
393
394 if (new_weight > exist_weight)
395 {
396 if (debug)
397 zlog_debug("%s: %s wins over %s due to weight %d > %d",
398 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
399 return 1;
400 }
401
402 if (new_weight < exist_weight)
403 {
404 if (debug)
405 zlog_debug("%s: %s loses to %s due to weight %d < %d",
406 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
407 return 0;
408 }
409
410 /* 2. Local preference check. */
411 new_pref = exist_pref = bgp->default_local_pref;
412
413 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
414 new_pref = newattr->local_pref;
415 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
416 exist_pref = existattr->local_pref;
417
418 if (new_pref > exist_pref)
419 {
420 if (debug)
421 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
422 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
423 return 1;
424 }
425
426 if (new_pref < exist_pref)
427 {
428 if (debug)
429 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
430 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
431 return 0;
432 }
433
434 /* 3. Local route check. We prefer:
435 * - BGP_ROUTE_STATIC
436 * - BGP_ROUTE_AGGREGATE
437 * - BGP_ROUTE_REDISTRIBUTE
438 */
439 if (! (new->sub_type == BGP_ROUTE_NORMAL))
440 {
441 if (debug)
442 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
443 pfx_buf, new_buf, exist_buf);
444 return 1;
445 }
446
447 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
448 {
449 if (debug)
450 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
451 pfx_buf, new_buf, exist_buf);
452 return 0;
453 }
454
455 /* 4. AS path length check. */
456 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
457 {
458 int exist_hops = aspath_count_hops (existattr->aspath);
459 int exist_confeds = aspath_count_confeds (existattr->aspath);
460
461 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
462 {
463 int aspath_hops;
464
465 aspath_hops = aspath_count_hops (newattr->aspath);
466 aspath_hops += aspath_count_confeds (newattr->aspath);
467
468 if ( aspath_hops < (exist_hops + exist_confeds))
469 {
470 if (debug)
471 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
472 pfx_buf, new_buf, exist_buf,
473 aspath_hops, (exist_hops + exist_confeds));
474 return 1;
475 }
476
477 if ( aspath_hops > (exist_hops + exist_confeds))
478 {
479 if (debug)
480 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
481 pfx_buf, new_buf, exist_buf,
482 aspath_hops, (exist_hops + exist_confeds));
483 return 0;
484 }
485 }
486 else
487 {
488 int newhops = aspath_count_hops (newattr->aspath);
489
490 if (newhops < exist_hops)
491 {
492 if (debug)
493 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
494 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
495 return 1;
496 }
497
498 if (newhops > exist_hops)
499 {
500 if (debug)
501 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
502 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
503 return 0;
504 }
505 }
506 }
507
508 /* 5. Origin check. */
509 if (newattr->origin < existattr->origin)
510 {
511 if (debug)
512 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
513 pfx_buf, new_buf, exist_buf,
514 bgp_origin_long_str[newattr->origin],
515 bgp_origin_long_str[existattr->origin]);
516 return 1;
517 }
518
519 if (newattr->origin > existattr->origin)
520 {
521 if (debug)
522 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
523 pfx_buf, new_buf, exist_buf,
524 bgp_origin_long_str[newattr->origin],
525 bgp_origin_long_str[existattr->origin]);
526 return 0;
527 }
528
529 /* 6. MED check. */
530 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
531 && aspath_count_hops (existattr->aspath) == 0);
532 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
533 && aspath_count_confeds (existattr->aspath) > 0
534 && aspath_count_hops (newattr->aspath) == 0
535 && aspath_count_hops (existattr->aspath) == 0);
536
537 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
538 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
539 && confed_as_route)
540 || aspath_cmp_left (newattr->aspath, existattr->aspath)
541 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
542 || internal_as_route)
543 {
544 new_med = bgp_med_value (new->attr, bgp);
545 exist_med = bgp_med_value (exist->attr, bgp);
546
547 if (new_med < exist_med)
548 {
549 if (debug)
550 zlog_debug("%s: %s wins over %s due to MED %d < %d",
551 pfx_buf, new_buf, exist_buf, new_med, exist_med);
552 return 1;
553 }
554
555 if (new_med > exist_med)
556 {
557 if (debug)
558 zlog_debug("%s: %s loses to %s due to MED %d > %d",
559 pfx_buf, new_buf, exist_buf, new_med, exist_med);
560 return 0;
561 }
562 }
563
564 /* 7. Peer type check. */
565 new_sort = new->peer->sort;
566 exist_sort = exist->peer->sort;
567
568 if (new_sort == BGP_PEER_EBGP
569 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
570 {
571 if (debug)
572 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
573 pfx_buf, new_buf, exist_buf);
574 return 1;
575 }
576
577 if (exist_sort == BGP_PEER_EBGP
578 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
579 {
580 if (debug)
581 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
582 pfx_buf, new_buf, exist_buf);
583 return 0;
584 }
585
586 /* 8. IGP metric check. */
587 newm = existm = 0;
588
589 if (new->extra)
590 newm = new->extra->igpmetric;
591 if (exist->extra)
592 existm = exist->extra->igpmetric;
593
594 if (newm < existm)
595 {
596 if (debug)
597 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
598 pfx_buf, new_buf, exist_buf, newm, existm);
599 ret = 1;
600 }
601
602 if (newm > existm)
603 {
604 if (debug)
605 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
606 pfx_buf, new_buf, exist_buf, newm, existm);
607 ret = 0;
608 }
609
610 /* 9. Same IGP metric. Compare the cluster list length as
611 representative of IGP hops metric. Rewrite the metric value
612 pair (newm, existm) with the cluster list length. Prefer the
613 path with smaller cluster list length. */
614 if (newm == existm)
615 {
616 if (peer_sort (new->peer) == BGP_PEER_IBGP
617 && peer_sort (exist->peer) == BGP_PEER_IBGP
618 && CHECK_FLAG (mpath_cfg->ibgp_flags,
619 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
620 {
621 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
622 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
623
624 if (newm < existm)
625 {
626 if (debug)
627 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
628 pfx_buf, new_buf, exist_buf, newm, existm);
629 ret = 1;
630 }
631
632 if (newm > existm)
633 {
634 if (debug)
635 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
636 pfx_buf, new_buf, exist_buf, newm, existm);
637 ret = 0;
638 }
639 }
640 }
641
642 /* 10. confed-external vs. confed-internal */
643 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
644 {
645 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
646 {
647 if (debug)
648 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
649 pfx_buf, new_buf, exist_buf);
650 return 1;
651 }
652
653 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
654 {
655 if (debug)
656 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
657 pfx_buf, new_buf, exist_buf);
658 return 0;
659 }
660 }
661
662 /* 11. Maximum path check. */
663 if (newm == existm)
664 {
665 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
666 {
667
668 /*
669 * For the two paths, all comparison steps till IGP metric
670 * have succeeded - including AS_PATH hop count. Since 'bgp
671 * bestpath as-path multipath-relax' knob is on, we don't need
672 * an exact match of AS_PATH. Thus, mark the paths are equal.
673 * That will trigger both these paths to get into the multipath
674 * array.
675 */
676 *paths_eq = 1;
677
678 if (debug)
679 zlog_debug("%s: %s and %s are equal via multipath-relax",
680 pfx_buf, new_buf, exist_buf);
681 }
682 else if (new->peer->sort == BGP_PEER_IBGP)
683 {
684 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
685 {
686 *paths_eq = 1;
687
688 if (debug)
689 zlog_debug("%s: %s and %s are equal via matching aspaths",
690 pfx_buf, new_buf, exist_buf);
691 }
692 }
693 else if (new->peer->as == exist->peer->as)
694 {
695 *paths_eq = 1;
696
697 if (debug)
698 zlog_debug("%s: %s and %s are equal via same remote-as",
699 pfx_buf, new_buf, exist_buf);
700 }
701 }
702 else
703 {
704 /*
705 * TODO: If unequal cost ibgp multipath is enabled we can
706 * mark the paths as equal here instead of returning
707 */
708 return ret;
709 }
710
711 /* 12. If both paths are external, prefer the path that was received
712 first (the oldest one). This step minimizes route-flap, since a
713 newer path won't displace an older one, even if it was the
714 preferred route based on the additional decision criteria below. */
715 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
716 && new_sort == BGP_PEER_EBGP
717 && exist_sort == BGP_PEER_EBGP)
718 {
719 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
720 {
721 if (debug)
722 zlog_debug("%s: %s wins over %s due to oldest external",
723 pfx_buf, new_buf, exist_buf);
724 return 1;
725 }
726
727 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
728 {
729 if (debug)
730 zlog_debug("%s: %s loses to %s due to oldest external",
731 pfx_buf, new_buf, exist_buf);
732 return 0;
733 }
734 }
735
736 /* 13. Router-ID comparision. */
737 /* If one of the paths is "stale", the corresponding peer router-id will
738 * be 0 and would always win over the other path. If originator id is
739 * used for the comparision, it will decide which path is better.
740 */
741 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
742 new_id.s_addr = newattre->originator_id.s_addr;
743 else
744 new_id.s_addr = new->peer->remote_id.s_addr;
745 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
746 exist_id.s_addr = existattre->originator_id.s_addr;
747 else
748 exist_id.s_addr = exist->peer->remote_id.s_addr;
749
750 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
751 {
752 if (debug)
753 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
754 pfx_buf, new_buf, exist_buf);
755 return 1;
756 }
757
758 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
759 {
760 if (debug)
761 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
762 pfx_buf, new_buf, exist_buf);
763 return 0;
764 }
765
766 /* 14. Cluster length comparision. */
767 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
768 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
769
770 if (new_cluster < exist_cluster)
771 {
772 if (debug)
773 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
774 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
775 return 1;
776 }
777
778 if (new_cluster > exist_cluster)
779 {
780 if (debug)
781 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
782 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
783 return 0;
784 }
785
786 /* 15. Neighbor address comparision. */
787 /* Do this only if neither path is "stale" as stale paths do not have
788 * valid peer information (as the connection may or may not be up).
789 */
790 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
791 {
792 if (debug)
793 zlog_debug("%s: %s wins over %s due to latter path being STALE",
794 pfx_buf, new_buf, exist_buf);
795 return 1;
796 }
797
798 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
799 {
800 if (debug)
801 zlog_debug("%s: %s loses to %s due to former path being STALE",
802 pfx_buf, new_buf, exist_buf);
803 return 0;
804 }
805
806 /* locally configured routes to advertise do not have su_remote */
807 if (new->peer->su_remote == NULL)
808 return 0;
809 if (exist->peer->su_remote == NULL)
810 return 1;
811
812 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
813
814 if (ret == 1)
815 {
816 if (debug)
817 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
818 pfx_buf, new_buf, exist_buf);
819 return 0;
820 }
821
822 if (ret == -1)
823 {
824 if (debug)
825 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
826 pfx_buf, new_buf, exist_buf);
827 return 1;
828 }
829
830 if (debug)
831 zlog_debug("%s: %s wins over %s due to nothing left to compare",
832 pfx_buf, new_buf, exist_buf);
833
834 return 1;
835 }
836
837 static enum filter_type
838 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
839 afi_t afi, safi_t safi)
840 {
841 struct bgp_filter *filter;
842
843 filter = &peer->filter[afi][safi];
844
845 #define FILTER_EXIST_WARN(F,f,filter) \
846 if (BGP_DEBUG (update, UPDATE_IN) \
847 && !(F ## _IN (filter))) \
848 zlog_warn ("%s: Could not find configured input %s-list %s!", \
849 peer->host, #f, F ## _IN_NAME(filter));
850
851 if (DISTRIBUTE_IN_NAME (filter)) {
852 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
853
854 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
855 return FILTER_DENY;
856 }
857
858 if (PREFIX_LIST_IN_NAME (filter)) {
859 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
860
861 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
862 return FILTER_DENY;
863 }
864
865 if (FILTER_LIST_IN_NAME (filter)) {
866 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
867
868 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
869 return FILTER_DENY;
870 }
871
872 return FILTER_PERMIT;
873 #undef FILTER_EXIST_WARN
874 }
875
876 static enum filter_type
877 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
878 afi_t afi, safi_t safi)
879 {
880 struct bgp_filter *filter;
881
882 filter = &peer->filter[afi][safi];
883
884 #define FILTER_EXIST_WARN(F,f,filter) \
885 if (BGP_DEBUG (update, UPDATE_OUT) \
886 && !(F ## _OUT (filter))) \
887 zlog_warn ("%s: Could not find configured output %s-list %s!", \
888 peer->host, #f, F ## _OUT_NAME(filter));
889
890 if (DISTRIBUTE_OUT_NAME (filter)) {
891 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
892
893 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
894 return FILTER_DENY;
895 }
896
897 if (PREFIX_LIST_OUT_NAME (filter)) {
898 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
899
900 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
901 return FILTER_DENY;
902 }
903
904 if (FILTER_LIST_OUT_NAME (filter)) {
905 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
906
907 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
908 return FILTER_DENY;
909 }
910
911 return FILTER_PERMIT;
912 #undef FILTER_EXIST_WARN
913 }
914
915 /* If community attribute includes no_export then return 1. */
916 static int
917 bgp_community_filter (struct peer *peer, struct attr *attr)
918 {
919 if (attr->community)
920 {
921 /* NO_ADVERTISE check. */
922 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
923 return 1;
924
925 /* NO_EXPORT check. */
926 if (peer->sort == BGP_PEER_EBGP &&
927 community_include (attr->community, COMMUNITY_NO_EXPORT))
928 return 1;
929
930 /* NO_EXPORT_SUBCONFED check. */
931 if (peer->sort == BGP_PEER_EBGP
932 || peer->sort == BGP_PEER_CONFED)
933 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
934 return 1;
935 }
936 return 0;
937 }
938
939 /* Route reflection loop check. */
940 static int
941 bgp_cluster_filter (struct peer *peer, struct attr *attr)
942 {
943 struct in_addr cluster_id;
944
945 if (attr->extra && attr->extra->cluster)
946 {
947 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
948 cluster_id = peer->bgp->cluster_id;
949 else
950 cluster_id = peer->bgp->router_id;
951
952 if (cluster_loop_check (attr->extra->cluster, cluster_id))
953 return 1;
954 }
955 return 0;
956 }
957
958 static int
959 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
960 afi_t afi, safi_t safi, const char *rmap_name)
961 {
962 struct bgp_filter *filter;
963 struct bgp_info info;
964 route_map_result_t ret;
965 struct route_map *rmap = NULL;
966
967 filter = &peer->filter[afi][safi];
968
969 /* Apply default weight value. */
970 if (peer->weight)
971 (bgp_attr_extra_get (attr))->weight = peer->weight;
972
973 if (rmap_name)
974 {
975 rmap = route_map_lookup_by_name(rmap_name);
976
977 if (rmap == NULL)
978 return RMAP_DENY;
979 }
980 else
981 {
982 if (ROUTE_MAP_IN_NAME(filter))
983 {
984 rmap = ROUTE_MAP_IN (filter);
985
986 if (rmap == NULL)
987 return RMAP_DENY;
988 }
989 }
990
991 /* Route map apply. */
992 if (rmap)
993 {
994 /* Duplicate current value to new strucutre for modification. */
995 info.peer = peer;
996 info.attr = attr;
997
998 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
999
1000 /* Apply BGP route map to the attribute. */
1001 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1002
1003 peer->rmap_type = 0;
1004
1005 if (ret == RMAP_DENYMATCH)
1006 {
1007 /* Free newly generated AS path and community by route-map. */
1008 bgp_attr_flush (attr);
1009 return RMAP_DENY;
1010 }
1011 }
1012 return RMAP_PERMIT;
1013 }
1014
1015 static int
1016 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1017 afi_t afi, safi_t safi, const char *rmap_name)
1018 {
1019 struct bgp_filter *filter;
1020 struct bgp_info info;
1021 route_map_result_t ret;
1022 struct route_map *rmap = NULL;
1023
1024 filter = &peer->filter[afi][safi];
1025
1026 /* Apply default weight value. */
1027 if (peer->weight)
1028 (bgp_attr_extra_get (attr))->weight = peer->weight;
1029
1030 if (rmap_name)
1031 {
1032 rmap = route_map_lookup_by_name(rmap_name);
1033
1034 if (rmap == NULL)
1035 return RMAP_DENY;
1036 }
1037 else
1038 {
1039 if (ROUTE_MAP_OUT_NAME(filter))
1040 {
1041 rmap = ROUTE_MAP_OUT (filter);
1042
1043 if (rmap == NULL)
1044 return RMAP_DENY;
1045 }
1046 }
1047
1048 /* Route map apply. */
1049 if (rmap)
1050 {
1051 /* Duplicate current value to new strucutre for modification. */
1052 info.peer = peer;
1053 info.attr = attr;
1054
1055 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1056
1057 /* Apply BGP route map to the attribute. */
1058 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1059
1060 peer->rmap_type = 0;
1061
1062 if (ret == RMAP_DENYMATCH)
1063 /* caller has multiple error paths with bgp_attr_flush() */
1064 return RMAP_DENY;
1065 }
1066 return RMAP_PERMIT;
1067 }
1068
1069 /* If this is an EBGP peer with remove-private-AS */
1070 static void
1071 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1072 struct peer *peer, struct attr *attr)
1073 {
1074 if (peer->sort == BGP_PEER_EBGP &&
1075 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1076 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1077 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1078 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1079 {
1080 // Take action on the entire aspath
1081 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1082 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1083 {
1084 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1085 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1086
1087 // The entire aspath consists of private ASNs so create an empty aspath
1088 else if (aspath_private_as_check (attr->aspath))
1089 attr->aspath = aspath_empty_get ();
1090
1091 // There are some public and some private ASNs, remove the private ASNs
1092 else
1093 attr->aspath = aspath_remove_private_asns (attr->aspath);
1094 }
1095
1096 // 'all' was not specified so the entire aspath must be private ASNs
1097 // for us to do anything
1098 else if (aspath_private_as_check (attr->aspath))
1099 {
1100 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1101 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1102 else
1103 attr->aspath = aspath_empty_get ();
1104 }
1105 }
1106 }
1107
1108 /* If this is an EBGP peer with as-override */
1109 static void
1110 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1111 struct peer *peer, struct attr *attr)
1112 {
1113 if (peer->sort == BGP_PEER_EBGP &&
1114 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1115 {
1116 if (aspath_single_asn_check (attr->aspath, peer->as))
1117 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1118 }
1119 }
1120
1121 static void
1122 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1123 {
1124 if (family == AF_INET)
1125 attr->nexthop.s_addr = 0;
1126 #ifdef HAVE_IPV6
1127 if (family == AF_INET6)
1128 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1129 #endif
1130 }
1131
1132 int
1133 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1134 struct prefix *p, struct attr *attr)
1135 {
1136 struct bgp_filter *filter;
1137 struct peer *from;
1138 struct peer *peer;
1139 struct peer *onlypeer;
1140 struct bgp *bgp;
1141 struct attr *riattr;
1142 struct peer_af *paf;
1143 char buf[SU_ADDRSTRLEN];
1144 int ret;
1145 int transparent;
1146 int reflect;
1147 afi_t afi;
1148 safi_t safi;
1149
1150 if (DISABLE_BGP_ANNOUNCE)
1151 return 0;
1152
1153 afi = SUBGRP_AFI(subgrp);
1154 safi = SUBGRP_SAFI(subgrp);
1155 peer = SUBGRP_PEER(subgrp);
1156 onlypeer = NULL;
1157 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1158 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1159
1160 from = ri->peer;
1161 filter = &peer->filter[afi][safi];
1162 bgp = SUBGRP_INST(subgrp);
1163 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1164
1165 /* With addpath we may be asked to TX all kinds of paths so make sure
1166 * ri is valid */
1167 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1168 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1169 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1170 {
1171 return 0;
1172 }
1173
1174 /* If this is not the bestpath then check to see if there is an enabled addpath
1175 * feature that requires us to advertise it */
1176 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1177 {
1178 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1179 {
1180 return 0;
1181 }
1182 }
1183
1184 /* Aggregate-address suppress check. */
1185 if (ri->extra && ri->extra->suppress)
1186 if (! UNSUPPRESS_MAP_NAME (filter))
1187 {
1188 return 0;
1189 }
1190
1191 /* Do not send back route to sender. */
1192 if (onlypeer && from == onlypeer)
1193 {
1194 return 0;
1195 }
1196
1197 /* Do not send the default route in the BGP table if the neighbor is
1198 * configured for default-originate */
1199 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1200 {
1201 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1202 return 0;
1203 #ifdef HAVE_IPV6
1204 else if (p->family == AF_INET6 && p->prefixlen == 0)
1205 return 0;
1206 #endif /* HAVE_IPV6 */
1207 }
1208
1209 /* Transparency check. */
1210 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1211 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1212 transparent = 1;
1213 else
1214 transparent = 0;
1215
1216 /* If community is not disabled check the no-export and local. */
1217 if (! transparent && bgp_community_filter (peer, riattr))
1218 {
1219 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1220 zlog_debug ("subgrpannouncecheck: community filter check fail");
1221 return 0;
1222 }
1223
1224 /* If the attribute has originator-id and it is same as remote
1225 peer's id. */
1226 if (onlypeer &&
1227 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1228 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1229 {
1230 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1231 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1232 "remote router-id",
1233 onlypeer->host,
1234 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1235 p->prefixlen);
1236 return 0;
1237 }
1238
1239 /* ORF prefix-list filter check */
1240 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1241 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1242 || CHECK_FLAG (peer->af_cap[afi][safi],
1243 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1244 if (peer->orf_plist[afi][safi])
1245 {
1246 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1247 {
1248 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1249 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1250 peer->host,
1251 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1252 p->prefixlen);
1253 return 0;
1254 }
1255 }
1256
1257 /* Output filter check. */
1258 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1259 {
1260 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1261 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1262 peer->host,
1263 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1264 p->prefixlen);
1265 return 0;
1266 }
1267
1268 #ifdef BGP_SEND_ASPATH_CHECK
1269 /* AS path loop check. */
1270 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1271 {
1272 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1273 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1274 "that is part of AS path.",
1275 onlypeer->host, onlypeer->as);
1276 return 0;
1277 }
1278 #endif /* BGP_SEND_ASPATH_CHECK */
1279
1280 /* If we're a CONFED we need to loop check the CONFED ID too */
1281 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1282 {
1283 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1284 {
1285 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1286 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1287 " is AS path.",
1288 peer->host,
1289 bgp->confed_id);
1290 return 0;
1291 }
1292 }
1293
1294 /* Route-Reflect check. */
1295 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1296 reflect = 1;
1297 else
1298 reflect = 0;
1299
1300 /* IBGP reflection check. */
1301 if (reflect)
1302 {
1303 /* A route from a Client peer. */
1304 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1305 {
1306 /* Reflect to all the Non-Client peers and also to the
1307 Client peers other than the originator. Originator check
1308 is already done. So there is noting to do. */
1309 /* no bgp client-to-client reflection check. */
1310 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1311 if (CHECK_FLAG (peer->af_flags[afi][safi],
1312 PEER_FLAG_REFLECTOR_CLIENT))
1313 return 0;
1314 }
1315 else
1316 {
1317 /* A route from a Non-client peer. Reflect to all other
1318 clients. */
1319 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1320 PEER_FLAG_REFLECTOR_CLIENT))
1321 return 0;
1322 }
1323 }
1324
1325 /* For modify attribute, copy it to temporary structure. */
1326 bgp_attr_dup (attr, riattr);
1327
1328 /* If local-preference is not set. */
1329 if ((peer->sort == BGP_PEER_IBGP
1330 || peer->sort == BGP_PEER_CONFED)
1331 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1332 {
1333 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1334 attr->local_pref = bgp->default_local_pref;
1335 }
1336
1337 /* If originator-id is not set and the route is to be reflected,
1338 set the originator id */
1339 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1340 {
1341 attr->extra = bgp_attr_extra_get(attr);
1342 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1343 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1344 }
1345
1346 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1347 if (peer->sort == BGP_PEER_EBGP
1348 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1349 {
1350 if (from != bgp->peer_self && ! transparent
1351 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1352 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1353 }
1354
1355 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1356 * in announce check, only certain flags and length (or number of nexthops
1357 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1358 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1359 * Typically, the source nexthop in the attribute is preserved but in the
1360 * scenarios where we know it will always be overwritten, we reset the
1361 * nexthop to "0" in an attempt to achieve better Update packing. An
1362 * example of this is when a prefix from each of 2 IBGP peers needs to be
1363 * announced to an EBGP peer (and they have the same attributes barring
1364 * their nexthop).
1365 */
1366 if (reflect)
1367 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1368
1369 #ifdef HAVE_IPV6
1370 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1371 * the peer (group) is configured to receive link-local nexthop unchanged
1372 * and it is available in the prefix OR we're not reflecting the route and
1373 * the peer (group) to whom we're going to announce is on a shared network
1374 * and this is either a self-originated route or the peer is EBGP.
1375 */
1376 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1377 {
1378 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1379 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1380 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1381 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1382 (!reflect && peer->shared_network &&
1383 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1384 {
1385 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1386 }
1387
1388 /* Clear off link-local nexthop in source, whenever it is not needed to
1389 * ensure more prefixes share the same attribute for announcement.
1390 */
1391 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1392 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1393 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1394 }
1395 #endif /* HAVE_IPV6 */
1396
1397 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1398 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1399
1400 /* Route map & unsuppress-map apply. */
1401 if (ROUTE_MAP_OUT_NAME (filter)
1402 || (ri->extra && ri->extra->suppress) )
1403 {
1404 struct bgp_info info;
1405 struct attr dummy_attr;
1406 struct attr_extra dummy_extra;
1407
1408 dummy_attr.extra = &dummy_extra;
1409
1410 info.peer = peer;
1411 info.attr = attr;
1412 /* don't confuse inbound and outbound setting */
1413 RESET_FLAG(attr->rmap_change_flags);
1414
1415 /*
1416 * The route reflector is not allowed to modify the attributes
1417 * of the reflected IBGP routes unless explicitly allowed.
1418 */
1419 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1420 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1421 {
1422 bgp_attr_dup (&dummy_attr, attr);
1423 info.attr = &dummy_attr;
1424 }
1425
1426 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1427
1428 if (ri->extra && ri->extra->suppress)
1429 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1430 else
1431 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1432
1433 peer->rmap_type = 0;
1434
1435 if (ret == RMAP_DENYMATCH)
1436 {
1437 bgp_attr_flush (attr);
1438 return 0;
1439 }
1440 }
1441
1442 /* After route-map has been applied, we check to see if the nexthop to
1443 * be carried in the attribute (that is used for the announcement) can
1444 * be cleared off or not. We do this in all cases where we would be
1445 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1446 * the global nexthop here; the link-local nexthop would have been cleared
1447 * already, and if not, it is required by the update formation code.
1448 * Also see earlier comments in this function.
1449 */
1450 /*
1451 * If route-map has performed some operation on the nexthop or the peer
1452 * configuration says to pass it unchanged, we cannot reset the nexthop
1453 * here, so only attempt to do it if these aren't true. Note that the
1454 * route-map handler itself might have cleared the nexthop, if for example,
1455 * it is configured as 'peer-address'.
1456 */
1457 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1458 riattr->rmap_change_flags) &&
1459 !transparent &&
1460 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1461 {
1462 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1463 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1464 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1465 {
1466 if (!reflect ||
1467 CHECK_FLAG (peer->af_flags[afi][safi],
1468 PEER_FLAG_FORCE_NEXTHOP_SELF))
1469 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1470 AF_INET6 : p->family), attr);
1471 }
1472 else if (peer->sort == BGP_PEER_EBGP)
1473 {
1474 /* Can also reset the nexthop if announcing to EBGP, but only if
1475 * no peer in the subgroup is on a shared subnet.
1476 * Note: 3rd party nexthop currently implemented for IPv4 only.
1477 */
1478 SUBGRP_FOREACH_PEER (subgrp, paf)
1479 {
1480 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1481 break;
1482 }
1483 if (!paf)
1484 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1485 }
1486 /* If IPv6/MP and nexthop does not have any override and happens to
1487 * be a link-local address, reset it so that we don't pass along the
1488 * source's link-local IPv6 address to recipients who may not be on
1489 * the same interface.
1490 */
1491 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1492 {
1493 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1494 subgroup_announce_reset_nhop (AF_INET6, attr);
1495 }
1496 }
1497
1498 return 1;
1499 }
1500
1501 struct bgp_info_pair
1502 {
1503 struct bgp_info *old;
1504 struct bgp_info *new;
1505 };
1506
1507 static void
1508 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1509 struct bgp_maxpaths_cfg *mpath_cfg,
1510 struct bgp_info_pair *result)
1511 {
1512 struct bgp_info *new_select;
1513 struct bgp_info *old_select;
1514 struct bgp_info *ri;
1515 struct bgp_info *ri1;
1516 struct bgp_info *ri2;
1517 struct bgp_info *nextri = NULL;
1518 int paths_eq, do_mpath, debug;
1519 struct list mp_list;
1520 char pfx_buf[PREFIX2STR_BUFFER];
1521 char path_buf[PATH_ADDPATH_STR_BUFFER];
1522
1523 result->old = result->new = NULL;
1524
1525 if (rn->info == NULL)
1526 {
1527 char buf[PREFIX2STR_BUFFER];
1528 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1529 __func__,
1530 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1531 return;
1532 }
1533
1534 bgp_mp_list_init (&mp_list);
1535 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1536
1537 debug = bgp_debug_bestpath(&rn->p);
1538
1539 if (debug)
1540 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1541
1542 /* bgp deterministic-med */
1543 new_select = NULL;
1544 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1545 {
1546
1547 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1548 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1549 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1550
1551 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1552 {
1553 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1554 continue;
1555 if (BGP_INFO_HOLDDOWN (ri1))
1556 continue;
1557 if (ri1->peer && ri1->peer != bgp->peer_self)
1558 if (ri1->peer->status != Established)
1559 continue;
1560
1561 new_select = ri1;
1562 if (ri1->next)
1563 {
1564 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1565 {
1566 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1567 continue;
1568 if (BGP_INFO_HOLDDOWN (ri2))
1569 continue;
1570 if (ri2->peer &&
1571 ri2->peer != bgp->peer_self &&
1572 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1573 if (ri2->peer->status != Established)
1574 continue;
1575
1576 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1577 || aspath_cmp_left_confed (ri1->attr->aspath,
1578 ri2->attr->aspath))
1579 {
1580 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1581 mpath_cfg, debug, pfx_buf))
1582 {
1583 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1584 new_select = ri2;
1585 }
1586
1587 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1588 }
1589 }
1590 }
1591 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1592 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1593
1594 if (debug)
1595 {
1596 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1597 zlog_debug("%s: %s is the bestpath from AS %d",
1598 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1599 }
1600 }
1601 }
1602
1603 /* Check old selected route and new selected route. */
1604 old_select = NULL;
1605 new_select = NULL;
1606 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1607 {
1608 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1609 old_select = ri;
1610
1611 if (BGP_INFO_HOLDDOWN (ri))
1612 {
1613 /* reap REMOVED routes, if needs be
1614 * selected route must stay for a while longer though
1615 */
1616 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1617 && (ri != old_select))
1618 bgp_info_reap (rn, ri);
1619
1620 continue;
1621 }
1622
1623 if (ri->peer &&
1624 ri->peer != bgp->peer_self &&
1625 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1626 if (ri->peer->status != Established)
1627 continue;
1628
1629 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1630 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1631 {
1632 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1633 continue;
1634 }
1635
1636 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1637
1638 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1639 {
1640 new_select = ri;
1641 }
1642 }
1643
1644 /* Now that we know which path is the bestpath see if any of the other paths
1645 * qualify as multipaths
1646 */
1647 if (do_mpath && new_select)
1648 {
1649 if (debug)
1650 {
1651 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1652 zlog_debug("%s: %s is the bestpath, now find multipaths", pfx_buf, path_buf);
1653 }
1654
1655 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1656 {
1657
1658 if (debug)
1659 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1660
1661 if (ri == new_select)
1662 {
1663 if (debug)
1664 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1665 pfx_buf, path_buf);
1666 bgp_mp_list_add (&mp_list, ri);
1667 continue;
1668 }
1669
1670 if (BGP_INFO_HOLDDOWN (ri))
1671 continue;
1672
1673 if (ri->peer &&
1674 ri->peer != bgp->peer_self &&
1675 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1676 if (ri->peer->status != Established)
1677 continue;
1678
1679 if (!bgp_info_nexthop_cmp (ri, new_select))
1680 {
1681 if (debug)
1682 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1683 pfx_buf, path_buf);
1684 continue;
1685 }
1686
1687 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1688
1689 if (paths_eq)
1690 {
1691 if (debug)
1692 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1693 pfx_buf, path_buf);
1694 bgp_mp_list_add (&mp_list, ri);
1695 }
1696 }
1697 }
1698
1699 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1700 bgp_info_mpath_aggregate_update (new_select, old_select);
1701 bgp_mp_list_clear (&mp_list);
1702
1703 result->old = old_select;
1704 result->new = new_select;
1705
1706 return;
1707 }
1708
1709 /*
1710 * A new route/change in bestpath of an existing route. Evaluate the path
1711 * for advertisement to the subgroup.
1712 */
1713 int
1714 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1715 struct bgp_info *selected,
1716 struct bgp_node *rn,
1717 u_int32_t addpath_tx_id)
1718 {
1719 struct prefix *p;
1720 struct peer *onlypeer;
1721 struct attr attr;
1722 struct attr_extra extra;
1723 afi_t afi;
1724 safi_t safi;
1725
1726 p = &rn->p;
1727 afi = SUBGRP_AFI(subgrp);
1728 safi = SUBGRP_SAFI(subgrp);
1729 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1730 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1731
1732 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1733 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1734 PEER_STATUS_ORF_WAIT_REFRESH))
1735 return 0;
1736
1737 /* It's initialized in bgp_announce_check() */
1738 attr.extra = &extra;
1739
1740 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1741 if (selected)
1742 {
1743 if (subgroup_announce_check(selected, subgrp, p, &attr))
1744 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1745 else
1746 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1747 }
1748
1749 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1750 else
1751 {
1752 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1753 }
1754
1755 return 0;
1756 }
1757
1758 struct bgp_process_queue
1759 {
1760 struct bgp *bgp;
1761 struct bgp_node *rn;
1762 afi_t afi;
1763 safi_t safi;
1764 };
1765
1766 static wq_item_status
1767 bgp_process_main (struct work_queue *wq, void *data)
1768 {
1769 struct bgp_process_queue *pq = data;
1770 struct bgp *bgp = pq->bgp;
1771 struct bgp_node *rn = pq->rn;
1772 afi_t afi = pq->afi;
1773 safi_t safi = pq->safi;
1774 struct prefix *p = &rn->p;
1775 struct bgp_info *new_select;
1776 struct bgp_info *old_select;
1777 struct bgp_info_pair old_and_new;
1778
1779 /* Is it end of initial update? (after startup) */
1780 if (!rn)
1781 {
1782 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1783 sizeof(bgp->update_delay_zebra_resume_time));
1784
1785 bgp->main_zebra_update_hold = 0;
1786 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1787 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1788 {
1789 bgp_zebra_announce_table(bgp, afi, safi);
1790 }
1791 bgp->main_peers_update_hold = 0;
1792
1793 bgp_start_routeadv(bgp);
1794 return WQ_SUCCESS;
1795 }
1796
1797 /* Best path selection. */
1798 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1799 old_select = old_and_new.old;
1800 new_select = old_and_new.new;
1801
1802 /* Nothing to do. */
1803 if (old_select && old_select == new_select &&
1804 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1805 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1806 !bgp->addpath_tx_used[afi][safi])
1807 {
1808 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1809 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1810 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1811
1812 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1813 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1814 return WQ_SUCCESS;
1815 }
1816
1817 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1818 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1819
1820 /* bestpath has changed; bump version */
1821 if (old_select || new_select)
1822 {
1823 bgp_bump_version(rn);
1824
1825 if (!bgp->t_rmap_def_originate_eval)
1826 {
1827 bgp_lock (bgp);
1828 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1829 update_group_refresh_default_originate_route_map,
1830 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1831 }
1832 }
1833
1834 if (old_select)
1835 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1836 if (new_select)
1837 {
1838 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1839 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1840 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1841 }
1842
1843 group_announce_route(bgp, afi, safi, rn, new_select);
1844
1845 /* FIB update. */
1846 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1847 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1848 !bgp_option_check (BGP_OPT_NO_FIB))
1849 {
1850 if (new_select
1851 && new_select->type == ZEBRA_ROUTE_BGP
1852 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1853 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1854 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1855 else
1856 {
1857 /* Withdraw the route from the kernel. */
1858 if (old_select
1859 && old_select->type == ZEBRA_ROUTE_BGP
1860 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1861 old_select->sub_type == BGP_ROUTE_AGGREGATE))
1862 bgp_zebra_withdraw (p, old_select, safi);
1863 }
1864 }
1865
1866 /* Reap old select bgp_info, if it has been removed */
1867 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1868 bgp_info_reap (rn, old_select);
1869
1870 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1871 return WQ_SUCCESS;
1872 }
1873
1874 static void
1875 bgp_processq_del (struct work_queue *wq, void *data)
1876 {
1877 struct bgp_process_queue *pq = data;
1878 struct bgp_table *table;
1879
1880 bgp_unlock (pq->bgp);
1881 if (pq->rn)
1882 {
1883 table = bgp_node_table (pq->rn);
1884 bgp_unlock_node (pq->rn);
1885 bgp_table_unlock (table);
1886 }
1887 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1888 }
1889
1890 void
1891 bgp_process_queue_init (void)
1892 {
1893 if (!bm->process_main_queue)
1894 {
1895 bm->process_main_queue
1896 = work_queue_new (bm->master, "process_main_queue");
1897
1898 if ( !bm->process_main_queue)
1899 {
1900 zlog_err ("%s: Failed to allocate work queue", __func__);
1901 exit (1);
1902 }
1903 }
1904
1905 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1906 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1907 bm->process_main_queue->spec.max_retries = 0;
1908 bm->process_main_queue->spec.hold = 50;
1909 /* Use a higher yield value of 50ms for main queue processing */
1910 bm->process_main_queue->spec.yield = 50 * 1000L;
1911 }
1912
1913 void
1914 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1915 {
1916 struct bgp_process_queue *pqnode;
1917
1918 /* already scheduled for processing? */
1919 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1920 return;
1921
1922 if (rn->info == NULL)
1923 {
1924 /* XXX: Perhaps remove before next release, after we've flushed out
1925 * any obvious cases
1926 */
1927 assert (rn->info != NULL);
1928 char buf[PREFIX2STR_BUFFER];
1929 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1930 __func__,
1931 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1932 return;
1933 }
1934
1935 if (bm->process_main_queue == NULL)
1936 bgp_process_queue_init ();
1937
1938 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1939 sizeof (struct bgp_process_queue));
1940 if (!pqnode)
1941 return;
1942
1943 /* all unlocked in bgp_processq_del */
1944 bgp_table_lock (bgp_node_table (rn));
1945 pqnode->rn = bgp_lock_node (rn);
1946 pqnode->bgp = bgp;
1947 bgp_lock (bgp);
1948 pqnode->afi = afi;
1949 pqnode->safi = safi;
1950 work_queue_add (bm->process_main_queue, pqnode);
1951 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1952 return;
1953 }
1954
1955 void
1956 bgp_add_eoiu_mark (struct bgp *bgp)
1957 {
1958 struct bgp_process_queue *pqnode;
1959
1960 if (bm->process_main_queue == NULL)
1961 bgp_process_queue_init ();
1962
1963 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1964 sizeof (struct bgp_process_queue));
1965 if (!pqnode)
1966 return;
1967
1968 pqnode->rn = NULL;
1969 pqnode->bgp = bgp;
1970 bgp_lock (bgp);
1971 work_queue_add (bm->process_main_queue, pqnode);
1972 }
1973
1974 static int
1975 bgp_maximum_prefix_restart_timer (struct thread *thread)
1976 {
1977 struct peer *peer;
1978
1979 peer = THREAD_ARG (thread);
1980 peer->t_pmax_restart = NULL;
1981
1982 if (bgp_debug_neighbor_events(peer))
1983 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1984 peer->host);
1985
1986 peer_clear (peer, NULL);
1987
1988 return 0;
1989 }
1990
1991 int
1992 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1993 safi_t safi, int always)
1994 {
1995 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1996 return 0;
1997
1998 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1999 {
2000 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2001 && ! always)
2002 return 0;
2003
2004 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2005 "limit %ld", afi_safi_print (afi, safi), peer->host,
2006 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2007 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2008
2009 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2010 return 0;
2011
2012 {
2013 u_int8_t ndata[7];
2014
2015 if (safi == SAFI_MPLS_VPN)
2016 safi = SAFI_MPLS_LABELED_VPN;
2017
2018 ndata[0] = (afi >> 8);
2019 ndata[1] = afi;
2020 ndata[2] = safi;
2021 ndata[3] = (peer->pmax[afi][safi] >> 24);
2022 ndata[4] = (peer->pmax[afi][safi] >> 16);
2023 ndata[5] = (peer->pmax[afi][safi] >> 8);
2024 ndata[6] = (peer->pmax[afi][safi]);
2025
2026 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2027 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2028 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2029 }
2030
2031 /* Dynamic peers will just close their connection. */
2032 if (peer_dynamic_neighbor (peer))
2033 return 1;
2034
2035 /* restart timer start */
2036 if (peer->pmax_restart[afi][safi])
2037 {
2038 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2039
2040 if (bgp_debug_neighbor_events(peer))
2041 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2042 peer->host, peer->v_pmax_restart);
2043
2044 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2045 peer->v_pmax_restart);
2046 }
2047
2048 return 1;
2049 }
2050 else
2051 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2052
2053 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2054 {
2055 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2056 && ! always)
2057 return 0;
2058
2059 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2060 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2061 peer->pmax[afi][safi]);
2062 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2063 }
2064 else
2065 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2066 return 0;
2067 }
2068
2069 /* Unconditionally remove the route from the RIB, without taking
2070 * damping into consideration (eg, because the session went down)
2071 */
2072 static void
2073 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2074 afi_t afi, safi_t safi)
2075 {
2076 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2077
2078 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2079 bgp_info_delete (rn, ri); /* keep historical info */
2080
2081 bgp_process (peer->bgp, rn, afi, safi);
2082 }
2083
2084 static void
2085 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2086 afi_t afi, safi_t safi)
2087 {
2088 int status = BGP_DAMP_NONE;
2089
2090 /* apply dampening, if result is suppressed, we'll be retaining
2091 * the bgp_info in the RIB for historical reference.
2092 */
2093 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2094 && peer->sort == BGP_PEER_EBGP)
2095 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2096 == BGP_DAMP_SUPPRESSED)
2097 {
2098 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2099 return;
2100 }
2101
2102 bgp_rib_remove (rn, ri, peer, afi, safi);
2103 }
2104
2105 static struct bgp_info *
2106 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2107 struct bgp_node *rn)
2108 {
2109 struct bgp_info *new;
2110
2111 /* Make new BGP info. */
2112 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2113 new->type = type;
2114 new->instance = instance;
2115 new->sub_type = sub_type;
2116 new->peer = peer;
2117 new->attr = attr;
2118 new->uptime = bgp_clock ();
2119 new->net = rn;
2120 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2121 return new;
2122 }
2123
2124 static void
2125 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2126 {
2127 if (addpath_id)
2128 sprintf(buf, " with addpath ID %d", addpath_id);
2129 }
2130
2131
2132 /* Check if received nexthop is valid or not. */
2133 static int
2134 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2135 {
2136 struct attr_extra *attre = attr->extra;
2137 int ret = 0;
2138
2139 /* Only validated for unicast and multicast currently. */
2140 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2141 return 0;
2142
2143 /* If NEXT_HOP is present, validate it. */
2144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2145 {
2146 if (attr->nexthop.s_addr == 0 ||
2147 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2148 bgp_nexthop_self (bgp, attr))
2149 ret = 1;
2150 }
2151
2152 /* If MP_NEXTHOP is present, validate it. */
2153 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2154 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2155 * it is not an IPv6 link-local address.
2156 */
2157 if (attre && attre->mp_nexthop_len)
2158 {
2159 switch (attre->mp_nexthop_len)
2160 {
2161 case BGP_ATTR_NHLEN_IPV4:
2162 case BGP_ATTR_NHLEN_VPNV4:
2163 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2164 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2165 break;
2166
2167 #ifdef HAVE_IPV6
2168 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2169 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2170 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2171 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2172 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2173 break;
2174 #endif /* HAVE_IPV6 */
2175
2176 default:
2177 ret = 1;
2178 break;
2179 }
2180 }
2181
2182 return ret;
2183 }
2184
2185 int
2186 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2187 struct attr *attr, afi_t afi, safi_t safi, int type,
2188 int sub_type, struct prefix_rd *prd, u_char *tag,
2189 int soft_reconfig)
2190 {
2191 int ret;
2192 int aspath_loop_count = 0;
2193 struct bgp_node *rn;
2194 struct bgp *bgp;
2195 struct attr new_attr;
2196 struct attr_extra new_extra;
2197 struct attr *attr_new;
2198 struct bgp_info *ri;
2199 struct bgp_info *new;
2200 const char *reason;
2201 char buf[SU_ADDRSTRLEN];
2202 char buf2[30];
2203 int connected = 0;
2204
2205 bgp = peer->bgp;
2206 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2207
2208 /* When peer's soft reconfiguration enabled. Record input packet in
2209 Adj-RIBs-In. */
2210 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2211 && peer != bgp->peer_self)
2212 bgp_adj_in_set (rn, peer, attr, addpath_id);
2213
2214 /* Check previously received route. */
2215 for (ri = rn->info; ri; ri = ri->next)
2216 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2217 ri->addpath_rx_id == addpath_id)
2218 break;
2219
2220 /* AS path local-as loop check. */
2221 if (peer->change_local_as)
2222 {
2223 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2224 aspath_loop_count = 1;
2225
2226 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2227 {
2228 reason = "as-path contains our own AS;";
2229 goto filtered;
2230 }
2231 }
2232
2233 /* AS path loop check. */
2234 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2235 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2236 && aspath_loop_check(attr->aspath, bgp->confed_id)
2237 > peer->allowas_in[afi][safi]))
2238 {
2239 reason = "as-path contains our own AS;";
2240 goto filtered;
2241 }
2242
2243 /* Route reflector originator ID check. */
2244 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2245 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2246 {
2247 reason = "originator is us;";
2248 goto filtered;
2249 }
2250
2251 /* Route reflector cluster ID check. */
2252 if (bgp_cluster_filter (peer, attr))
2253 {
2254 reason = "reflected from the same cluster;";
2255 goto filtered;
2256 }
2257
2258 /* Apply incoming filter. */
2259 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2260 {
2261 reason = "filter;";
2262 goto filtered;
2263 }
2264
2265 new_attr.extra = &new_extra;
2266 bgp_attr_dup (&new_attr, attr);
2267
2268 /* Apply incoming route-map.
2269 * NB: new_attr may now contain newly allocated values from route-map "set"
2270 * commands, so we need bgp_attr_flush in the error paths, until we intern
2271 * the attr (which takes over the memory references) */
2272 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2273 {
2274 reason = "route-map;";
2275 bgp_attr_flush (&new_attr);
2276 goto filtered;
2277 }
2278
2279 /* next hop check. */
2280 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2281 {
2282 reason = "martian or self next-hop;";
2283 bgp_attr_flush (&new_attr);
2284 goto filtered;
2285 }
2286
2287 attr_new = bgp_attr_intern (&new_attr);
2288
2289 /* If the update is implicit withdraw. */
2290 if (ri)
2291 {
2292 ri->uptime = bgp_clock ();
2293
2294 /* Same attribute comes in. */
2295 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2296 && attrhash_cmp (ri->attr, attr_new))
2297 {
2298 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2299 && peer->sort == BGP_PEER_EBGP
2300 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2301 {
2302 if (bgp_debug_update(peer, p, NULL, 1))
2303 {
2304 bgp_info_addpath_rx_str(addpath_id, buf2);
2305 zlog_debug ("%s rcvd %s/%d%s",
2306 peer->host,
2307 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2308 p->prefixlen, buf2);
2309 }
2310
2311 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2312 {
2313 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2314 bgp_process (bgp, rn, afi, safi);
2315 }
2316 }
2317 else /* Duplicate - odd */
2318 {
2319 if (bgp_debug_update(peer, p, NULL, 1))
2320 {
2321 if (!peer->rcvd_attr_printed)
2322 {
2323 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2324 peer->rcvd_attr_printed = 1;
2325 }
2326
2327 bgp_info_addpath_rx_str(addpath_id, buf2);
2328 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2329 peer->host,
2330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2331 p->prefixlen, buf2);
2332 }
2333
2334 /* graceful restart STALE flag unset. */
2335 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2336 {
2337 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2338 bgp_process (bgp, rn, afi, safi);
2339 }
2340 }
2341
2342 bgp_unlock_node (rn);
2343 bgp_attr_unintern (&attr_new);
2344
2345 return 0;
2346 }
2347
2348 /* Withdraw/Announce before we fully processed the withdraw */
2349 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2350 {
2351 if (bgp_debug_update(peer, p, NULL, 1))
2352 {
2353 bgp_info_addpath_rx_str(addpath_id, buf2);
2354 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2355 peer->host,
2356 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2357 p->prefixlen, buf2);
2358 }
2359 bgp_info_restore (rn, ri);
2360 }
2361
2362 /* Received Logging. */
2363 if (bgp_debug_update(peer, p, NULL, 1))
2364 {
2365 bgp_info_addpath_rx_str(addpath_id, buf2);
2366 zlog_debug ("%s rcvd %s/%d%s",
2367 peer->host,
2368 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2369 p->prefixlen, buf2);
2370 }
2371
2372 /* graceful restart STALE flag unset. */
2373 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2374 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2375
2376 /* The attribute is changed. */
2377 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2378
2379 /* implicit withdraw, decrement aggregate and pcount here.
2380 * only if update is accepted, they'll increment below.
2381 */
2382 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2383
2384 /* Update bgp route dampening information. */
2385 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2386 && peer->sort == BGP_PEER_EBGP)
2387 {
2388 /* This is implicit withdraw so we should update dampening
2389 information. */
2390 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2391 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2392 }
2393
2394 /* Update to new attribute. */
2395 bgp_attr_unintern (&ri->attr);
2396 ri->attr = attr_new;
2397
2398 /* Update MPLS tag. */
2399 if (safi == SAFI_MPLS_VPN)
2400 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2401
2402 /* Update bgp route dampening information. */
2403 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2404 && peer->sort == BGP_PEER_EBGP)
2405 {
2406 /* Now we do normal update dampening. */
2407 ret = bgp_damp_update (ri, rn, afi, safi);
2408 if (ret == BGP_DAMP_SUPPRESSED)
2409 {
2410 bgp_unlock_node (rn);
2411 return 0;
2412 }
2413 }
2414
2415 /* Nexthop reachability check. */
2416 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2417 {
2418 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2419 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2420 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2421 connected = 1;
2422 else
2423 connected = 0;
2424
2425 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2426 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2427 else
2428 {
2429 if (BGP_DEBUG(nht, NHT))
2430 {
2431 char buf1[INET6_ADDRSTRLEN];
2432 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2433 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2434 }
2435 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2436 }
2437 }
2438 else
2439 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2440
2441 /* Process change. */
2442 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2443
2444 bgp_process (bgp, rn, afi, safi);
2445 bgp_unlock_node (rn);
2446
2447 return 0;
2448 } // End of implicit withdraw
2449
2450 /* Received Logging. */
2451 if (bgp_debug_update(peer, p, NULL, 1))
2452 {
2453 if (!peer->rcvd_attr_printed)
2454 {
2455 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2456 peer->rcvd_attr_printed = 1;
2457 }
2458
2459 bgp_info_addpath_rx_str(addpath_id, buf2);
2460 zlog_debug ("%s rcvd %s/%d%s",
2461 peer->host,
2462 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2463 p->prefixlen, buf2);
2464 }
2465
2466 /* Make new BGP info. */
2467 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2468
2469 /* Update MPLS tag. */
2470 if (safi == SAFI_MPLS_VPN)
2471 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2472
2473 /* Nexthop reachability check. */
2474 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2475 {
2476 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2477 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2478 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2479 connected = 1;
2480 else
2481 connected = 0;
2482
2483 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2484 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2485 else
2486 {
2487 if (BGP_DEBUG(nht, NHT))
2488 {
2489 char buf1[INET6_ADDRSTRLEN];
2490 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2491 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2492 }
2493 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2494 }
2495 }
2496 else
2497 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2498
2499 /* Addpath ID */
2500 new->addpath_rx_id = addpath_id;
2501
2502 /* Increment prefix */
2503 bgp_aggregate_increment (bgp, p, new, afi, safi);
2504
2505 /* Register new BGP information. */
2506 bgp_info_add (rn, new);
2507
2508 /* route_node_get lock */
2509 bgp_unlock_node (rn);
2510
2511 /* If maximum prefix count is configured and current prefix
2512 count exeed it. */
2513 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2514 return -1;
2515
2516 /* Process change. */
2517 bgp_process (bgp, rn, afi, safi);
2518
2519 return 0;
2520
2521 /* This BGP update is filtered. Log the reason then update BGP
2522 entry. */
2523 filtered:
2524 if (bgp_debug_update(peer, p, NULL, 1))
2525 {
2526 if (!peer->rcvd_attr_printed)
2527 {
2528 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2529 peer->rcvd_attr_printed = 1;
2530 }
2531
2532 bgp_info_addpath_rx_str(addpath_id, buf2);
2533 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2534 peer->host,
2535 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2536 p->prefixlen, buf2, reason);
2537 }
2538
2539 if (ri)
2540 bgp_rib_remove (rn, ri, peer, afi, safi);
2541
2542 bgp_unlock_node (rn);
2543
2544 return 0;
2545 }
2546
2547 int
2548 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2549 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2550 struct prefix_rd *prd, u_char *tag)
2551 {
2552 struct bgp *bgp;
2553 char buf[SU_ADDRSTRLEN];
2554 char buf2[30];
2555 struct bgp_node *rn;
2556 struct bgp_info *ri;
2557
2558 bgp = peer->bgp;
2559
2560 /* Lookup node. */
2561 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2562
2563 /* If peer is soft reconfiguration enabled. Record input packet for
2564 * further calculation.
2565 *
2566 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2567 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2568 * the iteration over all RS clients.
2569 * Since we need to remove the entry from adj_in anyway, do that first and
2570 * if there was no entry, we don't need to do anything more.
2571 */
2572 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2573 && peer != bgp->peer_self)
2574 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2575 {
2576 if (bgp_debug_update (peer, p, NULL, 1))
2577 zlog_debug ("%s withdrawing route %s/%d "
2578 "not in adj-in", peer->host,
2579 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2580 p->prefixlen);
2581 bgp_unlock_node (rn);
2582 return 0;
2583 }
2584
2585 /* Lookup withdrawn route. */
2586 for (ri = rn->info; ri; ri = ri->next)
2587 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2588 ri->addpath_rx_id == addpath_id)
2589 break;
2590
2591 /* Logging. */
2592 if (bgp_debug_update(peer, p, NULL, 1))
2593 {
2594 bgp_info_addpath_rx_str(addpath_id, buf2);
2595 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2596 peer->host,
2597 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2598 p->prefixlen, buf2);
2599 }
2600
2601 /* Withdraw specified route from routing table. */
2602 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2603 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2604 else if (bgp_debug_update(peer, p, NULL, 1))
2605 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2606 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2607 p->prefixlen);
2608
2609 /* Unlock bgp_node_get() lock. */
2610 bgp_unlock_node (rn);
2611
2612 return 0;
2613 }
2614
2615 void
2616 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2617 {
2618 struct update_subgroup *subgrp;
2619 subgrp = peer_subgroup(peer, afi, safi);
2620 subgroup_default_originate(subgrp, withdraw);
2621 }
2622
2623
2624 /*
2625 * bgp_stop_announce_route_timer
2626 */
2627 void
2628 bgp_stop_announce_route_timer (struct peer_af *paf)
2629 {
2630 if (!paf->t_announce_route)
2631 return;
2632
2633 THREAD_TIMER_OFF (paf->t_announce_route);
2634 }
2635
2636 /*
2637 * bgp_announce_route_timer_expired
2638 *
2639 * Callback that is invoked when the route announcement timer for a
2640 * peer_af expires.
2641 */
2642 static int
2643 bgp_announce_route_timer_expired (struct thread *t)
2644 {
2645 struct peer_af *paf;
2646 struct peer *peer;
2647
2648
2649 paf = THREAD_ARG (t);
2650 peer = paf->peer;
2651
2652 assert (paf->t_announce_route);
2653 paf->t_announce_route = NULL;
2654
2655 if (peer->status != Established)
2656 return 0;
2657
2658 if (!peer->afc_nego[paf->afi][paf->safi])
2659 return 0;
2660
2661 peer_af_announce_route (paf, 1);
2662 return 0;
2663 }
2664
2665 /*
2666 * bgp_announce_route
2667 *
2668 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2669 */
2670 void
2671 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2672 {
2673 struct peer_af *paf;
2674 struct update_subgroup *subgrp;
2675
2676 paf = peer_af_find (peer, afi, safi);
2677 if (!paf)
2678 return;
2679 subgrp = PAF_SUBGRP(paf);
2680
2681 /*
2682 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2683 * or a refresh has already been triggered.
2684 */
2685 if (!subgrp || paf->t_announce_route)
2686 return;
2687
2688 /*
2689 * Start a timer to stagger/delay the announce. This serves
2690 * two purposes - announcement can potentially be combined for
2691 * multiple peers and the announcement doesn't happen in the
2692 * vty context.
2693 */
2694 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2695 bgp_announce_route_timer_expired, paf,
2696 (subgrp->peer_count == 1) ?
2697 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2698 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2699 }
2700
2701 /*
2702 * Announce routes from all AF tables to a peer.
2703 *
2704 * This should ONLY be called when there is a need to refresh the
2705 * routes to the peer based on a policy change for this peer alone
2706 * or a route refresh request received from the peer.
2707 * The operation will result in splitting the peer from its existing
2708 * subgroups and putting it in new subgroups.
2709 */
2710 void
2711 bgp_announce_route_all (struct peer *peer)
2712 {
2713 afi_t afi;
2714 safi_t safi;
2715
2716 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2717 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2718 bgp_announce_route (peer, afi, safi);
2719 }
2720
2721 static void
2722 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2723 struct bgp_table *table, struct prefix_rd *prd)
2724 {
2725 int ret;
2726 struct bgp_node *rn;
2727 struct bgp_adj_in *ain;
2728
2729 if (! table)
2730 table = peer->bgp->rib[afi][safi];
2731
2732 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2733 for (ain = rn->adj_in; ain; ain = ain->next)
2734 {
2735 if (ain->peer == peer)
2736 {
2737 struct bgp_info *ri = rn->info;
2738 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2739
2740 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2741 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2742 prd, tag, 1);
2743
2744 if (ret < 0)
2745 {
2746 bgp_unlock_node (rn);
2747 return;
2748 }
2749 }
2750 }
2751 }
2752
2753 void
2754 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2755 {
2756 struct bgp_node *rn;
2757 struct bgp_table *table;
2758
2759 if (peer->status != Established)
2760 return;
2761
2762 if (safi != SAFI_MPLS_VPN)
2763 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2764 else
2765 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2766 rn = bgp_route_next (rn))
2767 if ((table = rn->info) != NULL)
2768 {
2769 struct prefix_rd prd;
2770 prd.family = AF_UNSPEC;
2771 prd.prefixlen = 64;
2772 memcpy(&prd.val, rn->p.u.val, 8);
2773
2774 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2775 }
2776 }
2777
2778
2779 struct bgp_clear_node_queue
2780 {
2781 struct bgp_node *rn;
2782 };
2783
2784 static wq_item_status
2785 bgp_clear_route_node (struct work_queue *wq, void *data)
2786 {
2787 struct bgp_clear_node_queue *cnq = data;
2788 struct bgp_node *rn = cnq->rn;
2789 struct peer *peer = wq->spec.data;
2790 struct bgp_info *ri;
2791 afi_t afi = bgp_node_table (rn)->afi;
2792 safi_t safi = bgp_node_table (rn)->safi;
2793
2794 assert (rn && peer);
2795
2796 /* It is possible that we have multiple paths for a prefix from a peer
2797 * if that peer is using AddPath.
2798 */
2799 for (ri = rn->info; ri; ri = ri->next)
2800 if (ri->peer == peer)
2801 {
2802 /* graceful restart STALE flag set. */
2803 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2804 && peer->nsf[afi][safi]
2805 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2806 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2807 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2808 else
2809 bgp_rib_remove (rn, ri, peer, afi, safi);
2810 }
2811 return WQ_SUCCESS;
2812 }
2813
2814 static void
2815 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2816 {
2817 struct bgp_clear_node_queue *cnq = data;
2818 struct bgp_node *rn = cnq->rn;
2819 struct bgp_table *table = bgp_node_table (rn);
2820
2821 bgp_unlock_node (rn);
2822 bgp_table_unlock (table);
2823 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2824 }
2825
2826 static void
2827 bgp_clear_node_complete (struct work_queue *wq)
2828 {
2829 struct peer *peer = wq->spec.data;
2830
2831 /* Tickle FSM to start moving again */
2832 BGP_EVENT_ADD (peer, Clearing_Completed);
2833
2834 peer_unlock (peer); /* bgp_clear_route */
2835 }
2836
2837 static void
2838 bgp_clear_node_queue_init (struct peer *peer)
2839 {
2840 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2841
2842 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2843 #undef CLEAR_QUEUE_NAME_LEN
2844
2845 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2846 {
2847 zlog_err ("%s: Failed to allocate work queue", __func__);
2848 exit (1);
2849 }
2850 peer->clear_node_queue->spec.hold = 10;
2851 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2852 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2853 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2854 peer->clear_node_queue->spec.max_retries = 0;
2855
2856 /* we only 'lock' this peer reference when the queue is actually active */
2857 peer->clear_node_queue->spec.data = peer;
2858 }
2859
2860 static void
2861 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2862 struct bgp_table *table)
2863 {
2864 struct bgp_node *rn;
2865
2866
2867 if (! table)
2868 table = peer->bgp->rib[afi][safi];
2869
2870 /* If still no table => afi/safi isn't configured at all or smth. */
2871 if (! table)
2872 return;
2873
2874 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2875 {
2876 struct bgp_info *ri;
2877 struct bgp_adj_in *ain;
2878 struct bgp_adj_in *ain_next;
2879
2880 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2881 * queued for every clearing peer, regardless of whether it is
2882 * relevant to the peer at hand.
2883 *
2884 * Overview: There are 3 different indices which need to be
2885 * scrubbed, potentially, when a peer is removed:
2886 *
2887 * 1 peer's routes visible via the RIB (ie accepted routes)
2888 * 2 peer's routes visible by the (optional) peer's adj-in index
2889 * 3 other routes visible by the peer's adj-out index
2890 *
2891 * 3 there is no hurry in scrubbing, once the struct peer is
2892 * removed from bgp->peer, we could just GC such deleted peer's
2893 * adj-outs at our leisure.
2894 *
2895 * 1 and 2 must be 'scrubbed' in some way, at least made
2896 * invisible via RIB index before peer session is allowed to be
2897 * brought back up. So one needs to know when such a 'search' is
2898 * complete.
2899 *
2900 * Ideally:
2901 *
2902 * - there'd be a single global queue or a single RIB walker
2903 * - rather than tracking which route_nodes still need to be
2904 * examined on a peer basis, we'd track which peers still
2905 * aren't cleared
2906 *
2907 * Given that our per-peer prefix-counts now should be reliable,
2908 * this may actually be achievable. It doesn't seem to be a huge
2909 * problem at this time,
2910 *
2911 * It is possible that we have multiple paths for a prefix from a peer
2912 * if that peer is using AddPath.
2913 */
2914 ain = rn->adj_in;
2915 while (ain)
2916 {
2917 ain_next = ain->next;
2918
2919 if (ain->peer == peer)
2920 {
2921 bgp_adj_in_remove (rn, ain);
2922 bgp_unlock_node (rn);
2923 }
2924
2925 ain = ain_next;
2926 }
2927
2928 for (ri = rn->info; ri; ri = ri->next)
2929 if (ri->peer == peer)
2930 {
2931 struct bgp_clear_node_queue *cnq;
2932
2933 /* both unlocked in bgp_clear_node_queue_del */
2934 bgp_table_lock (bgp_node_table (rn));
2935 bgp_lock_node (rn);
2936 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2937 sizeof (struct bgp_clear_node_queue));
2938 cnq->rn = rn;
2939 work_queue_add (peer->clear_node_queue, cnq);
2940 break;
2941 }
2942 }
2943 return;
2944 }
2945
2946 void
2947 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2948 {
2949 struct bgp_node *rn;
2950 struct bgp_table *table;
2951
2952 if (peer->clear_node_queue == NULL)
2953 bgp_clear_node_queue_init (peer);
2954
2955 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2956 * Idle until it receives a Clearing_Completed event. This protects
2957 * against peers which flap faster than we can we clear, which could
2958 * lead to:
2959 *
2960 * a) race with routes from the new session being installed before
2961 * clear_route_node visits the node (to delete the route of that
2962 * peer)
2963 * b) resource exhaustion, clear_route_node likely leads to an entry
2964 * on the process_main queue. Fast-flapping could cause that queue
2965 * to grow and grow.
2966 */
2967
2968 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2969 * the unlock will happen upon work-queue completion; other wise, the
2970 * unlock happens at the end of this function.
2971 */
2972 if (!peer->clear_node_queue->thread)
2973 peer_lock (peer);
2974
2975 if (safi != SAFI_MPLS_VPN)
2976 bgp_clear_route_table (peer, afi, safi, NULL);
2977 else
2978 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2979 rn = bgp_route_next (rn))
2980 if ((table = rn->info) != NULL)
2981 bgp_clear_route_table (peer, afi, safi, table);
2982
2983 /* unlock if no nodes got added to the clear-node-queue. */
2984 if (!peer->clear_node_queue->thread)
2985 peer_unlock (peer);
2986
2987 }
2988
2989 void
2990 bgp_clear_route_all (struct peer *peer)
2991 {
2992 afi_t afi;
2993 safi_t safi;
2994
2995 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2996 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2997 bgp_clear_route (peer, afi, safi);
2998 }
2999
3000 /*
3001 * Finish freeing things when exiting
3002 */
3003 static void
3004 bgp_drain_workqueue_immediate (struct work_queue *wq)
3005 {
3006 if (!wq)
3007 return;
3008
3009 if (!wq->thread)
3010 {
3011 /*
3012 * no thread implies no queued items
3013 */
3014 assert(!wq->items->count);
3015 return;
3016 }
3017
3018 while (wq->items->count)
3019 {
3020 if (wq->thread)
3021 thread_cancel(wq->thread);
3022 work_queue_run(wq->thread);
3023 }
3024 }
3025
3026 /*
3027 * Special function to process clear node queue when bgpd is exiting
3028 * and the thread scheduler is no longer running.
3029 */
3030 void
3031 bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3032 {
3033 if (!peer)
3034 return;
3035
3036 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3037 }
3038
3039 /*
3040 * The work queues are not specific to a BGP instance, but the
3041 * items in them refer to BGP instances, so this should be called
3042 * before each BGP instance is deleted.
3043 */
3044 void
3045 bgp_process_queues_drain_immediate(void)
3046 {
3047 bgp_drain_workqueue_immediate(bm->process_main_queue);
3048 }
3049
3050 void
3051 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3052 {
3053 struct bgp_table *table;
3054 struct bgp_node *rn;
3055 struct bgp_adj_in *ain;
3056 struct bgp_adj_in *ain_next;
3057
3058 table = peer->bgp->rib[afi][safi];
3059
3060 /* It is possible that we have multiple paths for a prefix from a peer
3061 * if that peer is using AddPath.
3062 */
3063 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3064 {
3065 ain = rn->adj_in;
3066
3067 while (ain)
3068 {
3069 ain_next = ain->next;
3070
3071 if (ain->peer == peer)
3072 {
3073 bgp_adj_in_remove (rn, ain);
3074 bgp_unlock_node (rn);
3075 }
3076
3077 ain = ain_next;
3078 }
3079 }
3080 }
3081
3082 void
3083 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3084 {
3085 struct bgp_node *rn;
3086 struct bgp_info *ri;
3087 struct bgp_table *table;
3088
3089 table = peer->bgp->rib[afi][safi];
3090
3091 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3092 {
3093 for (ri = rn->info; ri; ri = ri->next)
3094 if (ri->peer == peer)
3095 {
3096 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3097 bgp_rib_remove (rn, ri, peer, afi, safi);
3098 break;
3099 }
3100 }
3101 }
3102
3103 static void
3104 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3105 {
3106 struct bgp_node *rn;
3107 struct bgp_info *ri;
3108 struct bgp_info *next;
3109
3110 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3111 for (ri = rn->info; ri; ri = next)
3112 {
3113 next = ri->next;
3114 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3115 && ri->type == ZEBRA_ROUTE_BGP
3116 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3117 ri->sub_type == BGP_ROUTE_AGGREGATE))
3118 bgp_zebra_withdraw (&rn->p, ri, safi);
3119 }
3120 }
3121
3122 /* Delete all kernel routes. */
3123 void
3124 bgp_cleanup_routes (void)
3125 {
3126 struct bgp *bgp;
3127 struct listnode *node, *nnode;
3128 afi_t afi;
3129
3130 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3131 {
3132 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3133 {
3134 struct bgp_node *rn;
3135
3136 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3137
3138 /*
3139 * VPN and ENCAP tables are two-level (RD is top level)
3140 */
3141 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3142 rn = bgp_route_next (rn))
3143 if (rn->info)
3144 {
3145 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3146 bgp_table_finish ((struct bgp_table **)&(rn->info));
3147 rn->info = NULL;
3148 bgp_unlock_node(rn);
3149 }
3150 }
3151 }
3152 }
3153
3154 void
3155 bgp_reset (void)
3156 {
3157 vty_reset ();
3158 bgp_zclient_reset ();
3159 access_list_reset ();
3160 prefix_list_reset ();
3161 }
3162
3163 static int
3164 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3165 {
3166 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3167 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3168 }
3169
3170 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3171 value. */
3172 int
3173 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3174 {
3175 u_char *pnt;
3176 u_char *lim;
3177 struct prefix p;
3178 int psize;
3179 int ret;
3180 afi_t afi;
3181 safi_t safi;
3182 int addpath_encoded;
3183 u_int32_t addpath_id;
3184
3185 /* Check peer status. */
3186 if (peer->status != Established)
3187 return 0;
3188
3189 pnt = packet->nlri;
3190 lim = pnt + packet->length;
3191 afi = packet->afi;
3192 safi = packet->safi;
3193 addpath_id = 0;
3194 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3195
3196 for (; pnt < lim; pnt += psize)
3197 {
3198 /* Clear prefix structure. */
3199 memset (&p, 0, sizeof (struct prefix));
3200
3201 if (addpath_encoded)
3202 {
3203
3204 /* When packet overflow occurs return immediately. */
3205 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3206 return -1;
3207
3208 addpath_id = ntohl(*((uint32_t*) pnt));
3209 pnt += BGP_ADDPATH_ID_LEN;
3210 }
3211
3212 /* Fetch prefix length. */
3213 p.prefixlen = *pnt++;
3214 p.family = afi2family (afi);
3215
3216 /* Already checked in nlri_sanity_check(). We do double check
3217 here. */
3218 if ((afi == AFI_IP && p.prefixlen > 32)
3219 || (afi == AFI_IP6 && p.prefixlen > 128))
3220 return -1;
3221
3222 /* Packet size overflow check. */
3223 psize = PSIZE (p.prefixlen);
3224
3225 /* When packet overflow occur return immediately. */
3226 if (pnt + psize > lim)
3227 return -1;
3228
3229 /* Fetch prefix from NLRI packet. */
3230 memcpy (&p.u.prefix, pnt, psize);
3231
3232 /* Check address. */
3233 if (afi == AFI_IP && safi == SAFI_UNICAST)
3234 {
3235 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3236 {
3237 /*
3238 * From draft-ietf-idr-bgp4-22, Section 6.3:
3239 * If a BGP router receives an UPDATE message with a
3240 * semantically incorrect NLRI field, in which a prefix is
3241 * semantically incorrect (eg. an unexpected multicast IP
3242 * address), it should ignore the prefix.
3243 */
3244 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3245 inet_ntoa (p.u.prefix4));
3246
3247 return -1;
3248 }
3249 }
3250
3251 #ifdef HAVE_IPV6
3252 /* Check address. */
3253 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3254 {
3255 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3256 {
3257 char buf[BUFSIZ];
3258
3259 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3260 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3261
3262 continue;
3263 }
3264 }
3265 #endif /* HAVE_IPV6 */
3266
3267 /* Normal process. */
3268 if (attr)
3269 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3270 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3271 else
3272 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3273 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3274
3275 /* Address family configuration mismatch or maximum-prefix count
3276 overflow. */
3277 if (ret < 0)
3278 return -1;
3279 }
3280
3281 /* Packet length consistency check. */
3282 if (pnt != lim)
3283 return -1;
3284
3285 return 0;
3286 }
3287
3288 /* NLRI encode syntax check routine. */
3289 int
3290 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3291 bgp_size_t length, int *numpfx)
3292 {
3293 u_char *end;
3294 u_char prefixlen;
3295 int psize;
3296 int addpath_encoded;
3297
3298 *numpfx = 0;
3299 end = pnt + length;
3300 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3301
3302 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3303 syntactic validity. If the field is syntactically incorrect,
3304 then the Error Subcode is set to Invalid Network Field. */
3305
3306 while (pnt < end)
3307 {
3308
3309 /* If the NLRI is encoded using addpath then the first 4 bytes are
3310 * the addpath ID. */
3311 if (addpath_encoded)
3312 {
3313 if (pnt + BGP_ADDPATH_ID_LEN > end)
3314 {
3315 zlog_err ("%s [Error] Update packet error"
3316 " (prefix data addpath overflow)",
3317 peer->host);
3318 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3319 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3320 return -1;
3321 }
3322 pnt += BGP_ADDPATH_ID_LEN;
3323 }
3324
3325 prefixlen = *pnt++;
3326
3327 /* Prefix length check. */
3328 if ((afi == AFI_IP && prefixlen > 32)
3329 || (afi == AFI_IP6 && prefixlen > 128))
3330 {
3331 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3332 peer->host, prefixlen);
3333 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3334 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3335 return -1;
3336 }
3337
3338 /* Packet size overflow check. */
3339 psize = PSIZE (prefixlen);
3340
3341 if (pnt + psize > end)
3342 {
3343 zlog_err ("%s [Error] Update packet error"
3344 " (prefix data overflow prefix size is %d)",
3345 peer->host, psize);
3346 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3347 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3348 return -1;
3349 }
3350
3351 pnt += psize;
3352 (*numpfx)++;
3353 }
3354
3355 /* Packet length consistency check. */
3356 if (pnt != end)
3357 {
3358 zlog_err ("%s [Error] Update packet error"
3359 " (prefix length mismatch with total length)",
3360 peer->host);
3361 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3362 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3363 return -1;
3364 }
3365 return 0;
3366 }
3367
3368 static struct bgp_static *
3369 bgp_static_new (void)
3370 {
3371 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3372 }
3373
3374 static void
3375 bgp_static_free (struct bgp_static *bgp_static)
3376 {
3377 if (bgp_static->rmap.name)
3378 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3379 XFREE (MTYPE_BGP_STATIC, bgp_static);
3380 }
3381
3382 static void
3383 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3384 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3385 {
3386 struct bgp_node *rn;
3387 struct bgp_info *ri;
3388 struct bgp_info *new;
3389 struct bgp_info info;
3390 struct attr attr;
3391 struct attr *attr_new;
3392 int ret;
3393
3394 assert (bgp_static);
3395 if (!bgp_static)
3396 return;
3397
3398 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3399
3400 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3401
3402 attr.nexthop = bgp_static->igpnexthop;
3403 attr.med = bgp_static->igpmetric;
3404 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3405
3406 if (bgp_static->atomic)
3407 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3408
3409 /* Apply route-map. */
3410 if (bgp_static->rmap.name)
3411 {
3412 struct attr attr_tmp = attr;
3413 info.peer = bgp->peer_self;
3414 info.attr = &attr_tmp;
3415
3416 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3417
3418 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3419
3420 bgp->peer_self->rmap_type = 0;
3421
3422 if (ret == RMAP_DENYMATCH)
3423 {
3424 /* Free uninterned attribute. */
3425 bgp_attr_flush (&attr_tmp);
3426
3427 /* Unintern original. */
3428 aspath_unintern (&attr.aspath);
3429 bgp_attr_extra_free (&attr);
3430 bgp_static_withdraw (bgp, p, afi, safi);
3431 return;
3432 }
3433 attr_new = bgp_attr_intern (&attr_tmp);
3434 }
3435 else
3436 attr_new = bgp_attr_intern (&attr);
3437
3438 for (ri = rn->info; ri; ri = ri->next)
3439 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3440 && ri->sub_type == BGP_ROUTE_STATIC)
3441 break;
3442
3443 if (ri)
3444 {
3445 if (attrhash_cmp (ri->attr, attr_new) &&
3446 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3447 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3448 {
3449 bgp_unlock_node (rn);
3450 bgp_attr_unintern (&attr_new);
3451 aspath_unintern (&attr.aspath);
3452 bgp_attr_extra_free (&attr);
3453 return;
3454 }
3455 else
3456 {
3457 /* The attribute is changed. */
3458 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3459
3460 /* Rewrite BGP route information. */
3461 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3462 bgp_info_restore(rn, ri);
3463 else
3464 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3465 bgp_attr_unintern (&ri->attr);
3466 ri->attr = attr_new;
3467 ri->uptime = bgp_clock ();
3468
3469 /* Nexthop reachability check. */
3470 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3471 {
3472 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3473 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3474 else
3475 {
3476 if (BGP_DEBUG(nht, NHT))
3477 {
3478 char buf1[INET6_ADDRSTRLEN];
3479 inet_ntop(p->family, &p->u.prefix, buf1,
3480 INET6_ADDRSTRLEN);
3481 zlog_debug("%s(%s): Route not in table, not advertising",
3482 __FUNCTION__, buf1);
3483 }
3484 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3485 }
3486 }
3487 else
3488 {
3489 /* Delete the NHT structure if any, if we're toggling between
3490 * enabling/disabling import check. We deregister the route
3491 * from NHT to avoid overloading NHT and the process interaction
3492 */
3493 bgp_unlink_nexthop(ri);
3494 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3495 }
3496 /* Process change. */
3497 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3498 bgp_process (bgp, rn, afi, safi);
3499 bgp_unlock_node (rn);
3500 aspath_unintern (&attr.aspath);
3501 bgp_attr_extra_free (&attr);
3502 return;
3503 }
3504 }
3505
3506 /* Make new BGP info. */
3507 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3508 rn);
3509 /* Nexthop reachability check. */
3510 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3511 {
3512 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3513 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3514 else
3515 {
3516 if (BGP_DEBUG(nht, NHT))
3517 {
3518 char buf1[INET6_ADDRSTRLEN];
3519 inet_ntop(p->family, &p->u.prefix, buf1,
3520 INET6_ADDRSTRLEN);
3521 zlog_debug("%s(%s): Route not in table, not advertising",
3522 __FUNCTION__, buf1);
3523 }
3524 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3525 }
3526 }
3527 else
3528 {
3529 /* Delete the NHT structure if any, if we're toggling between
3530 * enabling/disabling import check. We deregister the route
3531 * from NHT to avoid overloading NHT and the process interaction
3532 */
3533 bgp_unlink_nexthop(new);
3534
3535 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3536 }
3537
3538 /* Aggregate address increment. */
3539 bgp_aggregate_increment (bgp, p, new, afi, safi);
3540
3541 /* Register new BGP information. */
3542 bgp_info_add (rn, new);
3543
3544 /* route_node_get lock */
3545 bgp_unlock_node (rn);
3546
3547 /* Process change. */
3548 bgp_process (bgp, rn, afi, safi);
3549
3550 /* Unintern original. */
3551 aspath_unintern (&attr.aspath);
3552 bgp_attr_extra_free (&attr);
3553 }
3554
3555 void
3556 bgp_static_update (struct bgp *bgp, struct prefix *p,
3557 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3558 {
3559 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3560 }
3561
3562 void
3563 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3564 safi_t safi)
3565 {
3566 struct bgp_node *rn;
3567 struct bgp_info *ri;
3568
3569 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3570
3571 /* Check selected route and self inserted route. */
3572 for (ri = rn->info; ri; ri = ri->next)
3573 if (ri->peer == bgp->peer_self
3574 && ri->type == ZEBRA_ROUTE_BGP
3575 && ri->sub_type == BGP_ROUTE_STATIC)
3576 break;
3577
3578 /* Withdraw static BGP route from routing table. */
3579 if (ri)
3580 {
3581 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3582 bgp_unlink_nexthop(ri);
3583 bgp_info_delete (rn, ri);
3584 bgp_process (bgp, rn, afi, safi);
3585 }
3586
3587 /* Unlock bgp_node_lookup. */
3588 bgp_unlock_node (rn);
3589 }
3590
3591 /*
3592 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3593 */
3594 static void
3595 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3596 safi_t safi, struct prefix_rd *prd, u_char *tag)
3597 {
3598 struct bgp_node *rn;
3599 struct bgp_info *ri;
3600
3601 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3602
3603 /* Check selected route and self inserted route. */
3604 for (ri = rn->info; ri; ri = ri->next)
3605 if (ri->peer == bgp->peer_self
3606 && ri->type == ZEBRA_ROUTE_BGP
3607 && ri->sub_type == BGP_ROUTE_STATIC)
3608 break;
3609
3610 /* Withdraw static BGP route from routing table. */
3611 if (ri)
3612 {
3613 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3614 bgp_info_delete (rn, ri);
3615 bgp_process (bgp, rn, afi, safi);
3616 }
3617
3618 /* Unlock bgp_node_lookup. */
3619 bgp_unlock_node (rn);
3620 }
3621
3622 static void
3623 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3624 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3625 {
3626 struct bgp_node *rn;
3627 struct bgp_info *new;
3628 struct attr *attr_new;
3629 struct attr attr = { 0 };
3630 struct bgp_info *ri;
3631
3632 assert (bgp_static);
3633
3634 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3635
3636 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3637
3638 attr.nexthop = bgp_static->igpnexthop;
3639 attr.med = bgp_static->igpmetric;
3640 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3641
3642 /* Apply route-map. */
3643 if (bgp_static->rmap.name)
3644 {
3645 struct attr attr_tmp = attr;
3646 struct bgp_info info;
3647 int ret;
3648
3649 info.peer = bgp->peer_self;
3650 info.attr = &attr_tmp;
3651
3652 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3653
3654 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3655
3656 bgp->peer_self->rmap_type = 0;
3657
3658 if (ret == RMAP_DENYMATCH)
3659 {
3660 /* Free uninterned attribute. */
3661 bgp_attr_flush (&attr_tmp);
3662
3663 /* Unintern original. */
3664 aspath_unintern (&attr.aspath);
3665 bgp_attr_extra_free (&attr);
3666 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3667 bgp_static->tag);
3668 return;
3669 }
3670
3671 attr_new = bgp_attr_intern (&attr_tmp);
3672 }
3673 else
3674 {
3675 attr_new = bgp_attr_intern (&attr);
3676 }
3677
3678 for (ri = rn->info; ri; ri = ri->next)
3679 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3680 && ri->sub_type == BGP_ROUTE_STATIC)
3681 break;
3682
3683 if (ri)
3684 {
3685 if (attrhash_cmp (ri->attr, attr_new) &&
3686 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3687 {
3688 bgp_unlock_node (rn);
3689 bgp_attr_unintern (&attr_new);
3690 aspath_unintern (&attr.aspath);
3691 bgp_attr_extra_free (&attr);
3692 return;
3693 }
3694 else
3695 {
3696 /* The attribute is changed. */
3697 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3698
3699 /* Rewrite BGP route information. */
3700 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3701 bgp_info_restore(rn, ri);
3702 else
3703 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3704 bgp_attr_unintern (&ri->attr);
3705 ri->attr = attr_new;
3706 ri->uptime = bgp_clock ();
3707
3708 /* Process change. */
3709 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3710 bgp_process (bgp, rn, afi, safi);
3711 bgp_unlock_node (rn);
3712 aspath_unintern (&attr.aspath);
3713 bgp_attr_extra_free (&attr);
3714 return;
3715 }
3716 }
3717
3718
3719 /* Make new BGP info. */
3720 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3721 rn);
3722 SET_FLAG (new->flags, BGP_INFO_VALID);
3723 new->extra = bgp_info_extra_new();
3724 memcpy (new->extra->tag, bgp_static->tag, 3);
3725
3726 /* Aggregate address increment. */
3727 bgp_aggregate_increment (bgp, p, new, afi, safi);
3728
3729 /* Register new BGP information. */
3730 bgp_info_add (rn, new);
3731
3732 /* route_node_get lock */
3733 bgp_unlock_node (rn);
3734
3735 /* Process change. */
3736 bgp_process (bgp, rn, afi, safi);
3737
3738 /* Unintern original. */
3739 aspath_unintern (&attr.aspath);
3740 bgp_attr_extra_free (&attr);
3741 }
3742
3743 /* Configure static BGP network. When user don't run zebra, static
3744 route should be installed as valid. */
3745 static int
3746 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3747 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3748 {
3749 int ret;
3750 struct prefix p;
3751 struct bgp_static *bgp_static;
3752 struct bgp_node *rn;
3753 u_char need_update = 0;
3754
3755 /* Convert IP prefix string to struct prefix. */
3756 ret = str2prefix (ip_str, &p);
3757 if (! ret)
3758 {
3759 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3760 return CMD_WARNING;
3761 }
3762 #ifdef HAVE_IPV6
3763 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3764 {
3765 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3766 VTY_NEWLINE);
3767 return CMD_WARNING;
3768 }
3769 #endif /* HAVE_IPV6 */
3770
3771 apply_mask (&p);
3772
3773 /* Set BGP static route configuration. */
3774 rn = bgp_node_get (bgp->route[afi][safi], &p);
3775
3776 if (rn->info)
3777 {
3778 /* Configuration change. */
3779 bgp_static = rn->info;
3780
3781 /* Check previous routes are installed into BGP. */
3782 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3783 need_update = 1;
3784
3785 bgp_static->backdoor = backdoor;
3786
3787 if (rmap)
3788 {
3789 if (bgp_static->rmap.name)
3790 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3791 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3792 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3793 }
3794 else
3795 {
3796 if (bgp_static->rmap.name)
3797 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3798 bgp_static->rmap.name = NULL;
3799 bgp_static->rmap.map = NULL;
3800 bgp_static->valid = 0;
3801 }
3802 bgp_unlock_node (rn);
3803 }
3804 else
3805 {
3806 /* New configuration. */
3807 bgp_static = bgp_static_new ();
3808 bgp_static->backdoor = backdoor;
3809 bgp_static->valid = 0;
3810 bgp_static->igpmetric = 0;
3811 bgp_static->igpnexthop.s_addr = 0;
3812
3813 if (rmap)
3814 {
3815 if (bgp_static->rmap.name)
3816 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3817 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3818 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3819 }
3820 rn->info = bgp_static;
3821 }
3822
3823 bgp_static->valid = 1;
3824 if (need_update)
3825 bgp_static_withdraw (bgp, &p, afi, safi);
3826
3827 if (! bgp_static->backdoor)
3828 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3829
3830 return CMD_SUCCESS;
3831 }
3832
3833 /* Configure static BGP network. */
3834 static int
3835 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3836 afi_t afi, safi_t safi)
3837 {
3838 int ret;
3839 struct prefix p;
3840 struct bgp_static *bgp_static;
3841 struct bgp_node *rn;
3842
3843 /* Convert IP prefix string to struct prefix. */
3844 ret = str2prefix (ip_str, &p);
3845 if (! ret)
3846 {
3847 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3848 return CMD_WARNING;
3849 }
3850 #ifdef HAVE_IPV6
3851 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3852 {
3853 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3854 VTY_NEWLINE);
3855 return CMD_WARNING;
3856 }
3857 #endif /* HAVE_IPV6 */
3858
3859 apply_mask (&p);
3860
3861 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3862 if (! rn)
3863 {
3864 vty_out (vty, "%% Can't find specified static route configuration.%s",
3865 VTY_NEWLINE);
3866 return CMD_WARNING;
3867 }
3868
3869 bgp_static = rn->info;
3870
3871 /* Update BGP RIB. */
3872 if (! bgp_static->backdoor)
3873 bgp_static_withdraw (bgp, &p, afi, safi);
3874
3875 /* Clear configuration. */
3876 bgp_static_free (bgp_static);
3877 rn->info = NULL;
3878 bgp_unlock_node (rn);
3879 bgp_unlock_node (rn);
3880
3881 return CMD_SUCCESS;
3882 }
3883
3884 void
3885 bgp_static_add (struct bgp *bgp)
3886 {
3887 afi_t afi;
3888 safi_t safi;
3889 struct bgp_node *rn;
3890 struct bgp_node *rm;
3891 struct bgp_table *table;
3892 struct bgp_static *bgp_static;
3893
3894 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3895 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3896 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3897 if (rn->info != NULL)
3898 {
3899 if (safi == SAFI_MPLS_VPN)
3900 {
3901 table = rn->info;
3902
3903 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3904 {
3905 bgp_static = rn->info;
3906 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
3907 }
3908 }
3909 else
3910 {
3911 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3912 }
3913 }
3914 }
3915
3916 /* Called from bgp_delete(). Delete all static routes from the BGP
3917 instance. */
3918 void
3919 bgp_static_delete (struct bgp *bgp)
3920 {
3921 afi_t afi;
3922 safi_t safi;
3923 struct bgp_node *rn;
3924 struct bgp_node *rm;
3925 struct bgp_table *table;
3926 struct bgp_static *bgp_static;
3927
3928 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3929 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3930 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3931 if (rn->info != NULL)
3932 {
3933 if (safi == SAFI_MPLS_VPN)
3934 {
3935 table = rn->info;
3936
3937 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3938 {
3939 bgp_static = rn->info;
3940 bgp_static_withdraw_safi (bgp, &rm->p,
3941 AFI_IP, safi,
3942 (struct prefix_rd *)&rn->p,
3943 bgp_static->tag);
3944 bgp_static_free (bgp_static);
3945 rn->info = NULL;
3946 bgp_unlock_node (rn);
3947 }
3948 }
3949 else
3950 {
3951 bgp_static = rn->info;
3952 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3953 bgp_static_free (bgp_static);
3954 rn->info = NULL;
3955 bgp_unlock_node (rn);
3956 }
3957 }
3958 }
3959
3960 void
3961 bgp_static_redo_import_check (struct bgp *bgp)
3962 {
3963 afi_t afi;
3964 safi_t safi;
3965 struct bgp_node *rn;
3966 struct bgp_static *bgp_static;
3967
3968 /* Use this flag to force reprocessing of the route */
3969 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3970 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3971 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3972 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3973 if (rn->info != NULL)
3974 {
3975 bgp_static = rn->info;
3976 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3977 }
3978 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3979 }
3980
3981 static void
3982 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
3983 {
3984 struct bgp_table *table;
3985 struct bgp_node *rn;
3986 struct bgp_info *ri;
3987
3988 table = bgp->rib[afi][safi];
3989 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3990 {
3991 for (ri = rn->info; ri; ri = ri->next)
3992 {
3993 if (ri->peer == bgp->peer_self &&
3994 ((ri->type == ZEBRA_ROUTE_BGP &&
3995 ri->sub_type == BGP_ROUTE_STATIC) ||
3996 (ri->type != ZEBRA_ROUTE_BGP &&
3997 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
3998 {
3999 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4000 bgp_unlink_nexthop(ri);
4001 bgp_info_delete (rn, ri);
4002 bgp_process (bgp, rn, afi, safi);
4003 }
4004 }
4005 }
4006 }
4007
4008 /*
4009 * Purge all networks and redistributed routes from routing table.
4010 * Invoked upon the instance going down.
4011 */
4012 void
4013 bgp_purge_static_redist_routes (struct bgp *bgp)
4014 {
4015 afi_t afi;
4016 safi_t safi;
4017
4018 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4019 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4020 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4021 }
4022
4023 /*
4024 * gpz 110624
4025 * Currently this is used to set static routes for VPN and ENCAP.
4026 * I think it can probably be factored with bgp_static_set.
4027 */
4028 int
4029 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4030 const char *rd_str, const char *tag_str,
4031 const char *rmap_str)
4032 {
4033 int ret;
4034 struct prefix p;
4035 struct prefix_rd prd;
4036 struct bgp *bgp;
4037 struct bgp_node *prn;
4038 struct bgp_node *rn;
4039 struct bgp_table *table;
4040 struct bgp_static *bgp_static;
4041 u_char tag[3];
4042
4043 bgp = vty->index;
4044
4045 ret = str2prefix (ip_str, &p);
4046 if (! ret)
4047 {
4048 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4049 return CMD_WARNING;
4050 }
4051 apply_mask (&p);
4052
4053 ret = str2prefix_rd (rd_str, &prd);
4054 if (! ret)
4055 {
4056 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4057 return CMD_WARNING;
4058 }
4059
4060 ret = str2tag (tag_str, tag);
4061 if (! ret)
4062 {
4063 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4064 return CMD_WARNING;
4065 }
4066
4067 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4068 (struct prefix *)&prd);
4069 if (prn->info == NULL)
4070 prn->info = bgp_table_init (AFI_IP, safi);
4071 else
4072 bgp_unlock_node (prn);
4073 table = prn->info;
4074
4075 rn = bgp_node_get (table, &p);
4076
4077 if (rn->info)
4078 {
4079 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4080 bgp_unlock_node (rn);
4081 }
4082 else
4083 {
4084 /* New configuration. */
4085 bgp_static = bgp_static_new ();
4086 bgp_static->backdoor = 0;
4087 bgp_static->valid = 0;
4088 bgp_static->igpmetric = 0;
4089 bgp_static->igpnexthop.s_addr = 0;
4090 memcpy(bgp_static->tag, tag, 3);
4091 bgp_static->prd = prd;
4092
4093 if (rmap_str)
4094 {
4095 if (bgp_static->rmap.name)
4096 free (bgp_static->rmap.name);
4097 bgp_static->rmap.name = strdup (rmap_str);
4098 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4099 }
4100 rn->info = bgp_static;
4101
4102 bgp_static->valid = 1;
4103 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4104 }
4105
4106 return CMD_SUCCESS;
4107 }
4108
4109 /* Configure static BGP network. */
4110 int
4111 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4112 const char *rd_str, const char *tag_str)
4113 {
4114 int ret;
4115 struct bgp *bgp;
4116 struct prefix p;
4117 struct prefix_rd prd;
4118 struct bgp_node *prn;
4119 struct bgp_node *rn;
4120 struct bgp_table *table;
4121 struct bgp_static *bgp_static;
4122 u_char tag[3];
4123
4124 bgp = vty->index;
4125
4126 /* Convert IP prefix string to struct prefix. */
4127 ret = str2prefix (ip_str, &p);
4128 if (! ret)
4129 {
4130 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4131 return CMD_WARNING;
4132 }
4133 apply_mask (&p);
4134
4135 ret = str2prefix_rd (rd_str, &prd);
4136 if (! ret)
4137 {
4138 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4139 return CMD_WARNING;
4140 }
4141
4142 ret = str2tag (tag_str, tag);
4143 if (! ret)
4144 {
4145 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4146 return CMD_WARNING;
4147 }
4148
4149 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4150 (struct prefix *)&prd);
4151 if (prn->info == NULL)
4152 prn->info = bgp_table_init (AFI_IP, safi);
4153 else
4154 bgp_unlock_node (prn);
4155 table = prn->info;
4156
4157 rn = bgp_node_lookup (table, &p);
4158
4159 if (rn)
4160 {
4161 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4162
4163 bgp_static = rn->info;
4164 bgp_static_free (bgp_static);
4165 rn->info = NULL;
4166 bgp_unlock_node (rn);
4167 bgp_unlock_node (rn);
4168 }
4169 else
4170 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4171
4172 return CMD_SUCCESS;
4173 }
4174
4175 static int
4176 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4177 const char *rmap_name)
4178 {
4179 struct bgp_rmap *rmap;
4180
4181 rmap = &bgp->table_map[afi][safi];
4182 if (rmap_name)
4183 {
4184 if (rmap->name)
4185 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4186 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4187 rmap->map = route_map_lookup_by_name (rmap_name);
4188 }
4189 else
4190 {
4191 if (rmap->name)
4192 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4193 rmap->name = NULL;
4194 rmap->map = NULL;
4195 }
4196
4197 bgp_zebra_announce_table(bgp, afi, safi);
4198
4199 return CMD_SUCCESS;
4200 }
4201
4202 static int
4203 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4204 const char *rmap_name)
4205 {
4206 struct bgp_rmap *rmap;
4207
4208 rmap = &bgp->table_map[afi][safi];
4209 if (rmap->name)
4210 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4211 rmap->name = NULL;
4212 rmap->map = NULL;
4213
4214 bgp_zebra_announce_table(bgp, afi, safi);
4215
4216 return CMD_SUCCESS;
4217 }
4218
4219 int
4220 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4221 safi_t safi, int *write)
4222 {
4223 if (bgp->table_map[afi][safi].name)
4224 {
4225 bgp_config_write_family_header (vty, afi, safi, write);
4226 vty_out (vty, " table-map %s%s",
4227 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4228 }
4229
4230 return 0;
4231 }
4232
4233
4234 DEFUN (bgp_table_map,
4235 bgp_table_map_cmd,
4236 "table-map WORD",
4237 "BGP table to RIB route download filter\n"
4238 "Name of the route map\n")
4239 {
4240 return bgp_table_map_set (vty, vty->index,
4241 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4242 }
4243 DEFUN (no_bgp_table_map,
4244 no_bgp_table_map_cmd,
4245 "no table-map WORD",
4246 "BGP table to RIB route download filter\n"
4247 "Name of the route map\n")
4248 {
4249 return bgp_table_map_unset (vty, vty->index,
4250 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4251 }
4252
4253 DEFUN (bgp_network,
4254 bgp_network_cmd,
4255 "network A.B.C.D/M",
4256 "Specify a network to announce via BGP\n"
4257 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4258 {
4259 return bgp_static_set (vty, vty->index, argv[0],
4260 AFI_IP, bgp_node_safi (vty), NULL, 0);
4261 }
4262
4263 DEFUN (bgp_network_route_map,
4264 bgp_network_route_map_cmd,
4265 "network A.B.C.D/M route-map WORD",
4266 "Specify a network to announce via BGP\n"
4267 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4268 "Route-map to modify the attributes\n"
4269 "Name of the route map\n")
4270 {
4271 return bgp_static_set (vty, vty->index, argv[0],
4272 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4273 }
4274
4275 DEFUN (bgp_network_backdoor,
4276 bgp_network_backdoor_cmd,
4277 "network A.B.C.D/M backdoor",
4278 "Specify a network to announce via BGP\n"
4279 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4280 "Specify a BGP backdoor route\n")
4281 {
4282 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4283 NULL, 1);
4284 }
4285
4286 DEFUN (bgp_network_mask,
4287 bgp_network_mask_cmd,
4288 "network A.B.C.D mask A.B.C.D",
4289 "Specify a network to announce via BGP\n"
4290 "Network number\n"
4291 "Network mask\n"
4292 "Network mask\n")
4293 {
4294 int ret;
4295 char prefix_str[BUFSIZ];
4296
4297 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4298 if (! ret)
4299 {
4300 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4301 return CMD_WARNING;
4302 }
4303
4304 return bgp_static_set (vty, vty->index, prefix_str,
4305 AFI_IP, bgp_node_safi (vty), NULL, 0);
4306 }
4307
4308 DEFUN (bgp_network_mask_route_map,
4309 bgp_network_mask_route_map_cmd,
4310 "network A.B.C.D mask A.B.C.D route-map WORD",
4311 "Specify a network to announce via BGP\n"
4312 "Network number\n"
4313 "Network mask\n"
4314 "Network mask\n"
4315 "Route-map to modify the attributes\n"
4316 "Name of the route map\n")
4317 {
4318 int ret;
4319 char prefix_str[BUFSIZ];
4320
4321 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4322 if (! ret)
4323 {
4324 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4325 return CMD_WARNING;
4326 }
4327
4328 return bgp_static_set (vty, vty->index, prefix_str,
4329 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4330 }
4331
4332 DEFUN (bgp_network_mask_backdoor,
4333 bgp_network_mask_backdoor_cmd,
4334 "network A.B.C.D mask A.B.C.D backdoor",
4335 "Specify a network to announce via BGP\n"
4336 "Network number\n"
4337 "Network mask\n"
4338 "Network mask\n"
4339 "Specify a BGP backdoor route\n")
4340 {
4341 int ret;
4342 char prefix_str[BUFSIZ];
4343
4344 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4345 if (! ret)
4346 {
4347 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4348 return CMD_WARNING;
4349 }
4350
4351 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4352 NULL, 1);
4353 }
4354
4355 DEFUN (bgp_network_mask_natural,
4356 bgp_network_mask_natural_cmd,
4357 "network A.B.C.D",
4358 "Specify a network to announce via BGP\n"
4359 "Network number\n")
4360 {
4361 int ret;
4362 char prefix_str[BUFSIZ];
4363
4364 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4365 if (! ret)
4366 {
4367 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4368 return CMD_WARNING;
4369 }
4370
4371 return bgp_static_set (vty, vty->index, prefix_str,
4372 AFI_IP, bgp_node_safi (vty), NULL, 0);
4373 }
4374
4375 DEFUN (bgp_network_mask_natural_route_map,
4376 bgp_network_mask_natural_route_map_cmd,
4377 "network A.B.C.D route-map WORD",
4378 "Specify a network to announce via BGP\n"
4379 "Network number\n"
4380 "Route-map to modify the attributes\n"
4381 "Name of the route map\n")
4382 {
4383 int ret;
4384 char prefix_str[BUFSIZ];
4385
4386 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4387 if (! ret)
4388 {
4389 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4390 return CMD_WARNING;
4391 }
4392
4393 return bgp_static_set (vty, vty->index, prefix_str,
4394 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4395 }
4396
4397 DEFUN (bgp_network_mask_natural_backdoor,
4398 bgp_network_mask_natural_backdoor_cmd,
4399 "network A.B.C.D backdoor",
4400 "Specify a network to announce via BGP\n"
4401 "Network number\n"
4402 "Specify a BGP backdoor route\n")
4403 {
4404 int ret;
4405 char prefix_str[BUFSIZ];
4406
4407 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4408 if (! ret)
4409 {
4410 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4411 return CMD_WARNING;
4412 }
4413
4414 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4415 NULL, 1);
4416 }
4417
4418 DEFUN (no_bgp_network,
4419 no_bgp_network_cmd,
4420 "no network A.B.C.D/M",
4421 NO_STR
4422 "Specify a network to announce via BGP\n"
4423 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4424 {
4425 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4426 bgp_node_safi (vty));
4427 }
4428
4429 ALIAS (no_bgp_network,
4430 no_bgp_network_route_map_cmd,
4431 "no network A.B.C.D/M route-map WORD",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4435 "Route-map to modify the attributes\n"
4436 "Name of the route map\n")
4437
4438 ALIAS (no_bgp_network,
4439 no_bgp_network_backdoor_cmd,
4440 "no network A.B.C.D/M backdoor",
4441 NO_STR
4442 "Specify a network to announce via BGP\n"
4443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4444 "Specify a BGP backdoor route\n")
4445
4446 DEFUN (no_bgp_network_mask,
4447 no_bgp_network_mask_cmd,
4448 "no network A.B.C.D mask A.B.C.D",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "Network number\n"
4452 "Network mask\n"
4453 "Network mask\n")
4454 {
4455 int ret;
4456 char prefix_str[BUFSIZ];
4457
4458 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4459 if (! ret)
4460 {
4461 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4462 return CMD_WARNING;
4463 }
4464
4465 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4466 bgp_node_safi (vty));
4467 }
4468
4469 ALIAS (no_bgp_network_mask,
4470 no_bgp_network_mask_route_map_cmd,
4471 "no network A.B.C.D mask A.B.C.D route-map WORD",
4472 NO_STR
4473 "Specify a network to announce via BGP\n"
4474 "Network number\n"
4475 "Network mask\n"
4476 "Network mask\n"
4477 "Route-map to modify the attributes\n"
4478 "Name of the route map\n")
4479
4480 ALIAS (no_bgp_network_mask,
4481 no_bgp_network_mask_backdoor_cmd,
4482 "no network A.B.C.D mask A.B.C.D backdoor",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "Network number\n"
4486 "Network mask\n"
4487 "Network mask\n"
4488 "Specify a BGP backdoor route\n")
4489
4490 DEFUN (no_bgp_network_mask_natural,
4491 no_bgp_network_mask_natural_cmd,
4492 "no network A.B.C.D",
4493 NO_STR
4494 "Specify a network to announce via BGP\n"
4495 "Network number\n")
4496 {
4497 int ret;
4498 char prefix_str[BUFSIZ];
4499
4500 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4501 if (! ret)
4502 {
4503 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4504 return CMD_WARNING;
4505 }
4506
4507 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4508 bgp_node_safi (vty));
4509 }
4510
4511 ALIAS (no_bgp_network_mask_natural,
4512 no_bgp_network_mask_natural_route_map_cmd,
4513 "no network A.B.C.D route-map WORD",
4514 NO_STR
4515 "Specify a network to announce via BGP\n"
4516 "Network number\n"
4517 "Route-map to modify the attributes\n"
4518 "Name of the route map\n")
4519
4520 ALIAS (no_bgp_network_mask_natural,
4521 no_bgp_network_mask_natural_backdoor_cmd,
4522 "no network A.B.C.D backdoor",
4523 NO_STR
4524 "Specify a network to announce via BGP\n"
4525 "Network number\n"
4526 "Specify a BGP backdoor route\n")
4527
4528 #ifdef HAVE_IPV6
4529 DEFUN (ipv6_bgp_network,
4530 ipv6_bgp_network_cmd,
4531 "network X:X::X:X/M",
4532 "Specify a network to announce via BGP\n"
4533 "IPv6 prefix <network>/<length>\n")
4534 {
4535 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4536 NULL, 0);
4537 }
4538
4539 DEFUN (ipv6_bgp_network_route_map,
4540 ipv6_bgp_network_route_map_cmd,
4541 "network X:X::X:X/M route-map WORD",
4542 "Specify a network to announce via BGP\n"
4543 "IPv6 prefix <network>/<length>\n"
4544 "Route-map to modify the attributes\n"
4545 "Name of the route map\n")
4546 {
4547 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4548 bgp_node_safi (vty), argv[1], 0);
4549 }
4550
4551 DEFUN (no_ipv6_bgp_network,
4552 no_ipv6_bgp_network_cmd,
4553 "no network X:X::X:X/M",
4554 NO_STR
4555 "Specify a network to announce via BGP\n"
4556 "IPv6 prefix <network>/<length>\n")
4557 {
4558 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4559 }
4560
4561 ALIAS (no_ipv6_bgp_network,
4562 no_ipv6_bgp_network_route_map_cmd,
4563 "no network X:X::X:X/M route-map WORD",
4564 NO_STR
4565 "Specify a network to announce via BGP\n"
4566 "IPv6 prefix <network>/<length>\n"
4567 "Route-map to modify the attributes\n"
4568 "Name of the route map\n")
4569
4570 ALIAS (ipv6_bgp_network,
4571 old_ipv6_bgp_network_cmd,
4572 "ipv6 bgp network X:X::X:X/M",
4573 IPV6_STR
4574 BGP_STR
4575 "Specify a network to announce via BGP\n"
4576 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4577
4578 ALIAS (no_ipv6_bgp_network,
4579 old_no_ipv6_bgp_network_cmd,
4580 "no ipv6 bgp network X:X::X:X/M",
4581 NO_STR
4582 IPV6_STR
4583 BGP_STR
4584 "Specify a network to announce via BGP\n"
4585 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4586 #endif /* HAVE_IPV6 */
4587
4588 /* Aggreagete address:
4589
4590 advertise-map Set condition to advertise attribute
4591 as-set Generate AS set path information
4592 attribute-map Set attributes of aggregate
4593 route-map Set parameters of aggregate
4594 summary-only Filter more specific routes from updates
4595 suppress-map Conditionally filter more specific routes from updates
4596 <cr>
4597 */
4598 struct bgp_aggregate
4599 {
4600 /* Summary-only flag. */
4601 u_char summary_only;
4602
4603 /* AS set generation. */
4604 u_char as_set;
4605
4606 /* Route-map for aggregated route. */
4607 struct route_map *map;
4608
4609 /* Suppress-count. */
4610 unsigned long count;
4611
4612 /* SAFI configuration. */
4613 safi_t safi;
4614 };
4615
4616 static struct bgp_aggregate *
4617 bgp_aggregate_new (void)
4618 {
4619 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4620 }
4621
4622 static void
4623 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4624 {
4625 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4626 }
4627
4628 /* Update an aggregate as routes are added/removed from the BGP table */
4629 static void
4630 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4631 afi_t afi, safi_t safi, struct bgp_info *del,
4632 struct bgp_aggregate *aggregate)
4633 {
4634 struct bgp_table *table;
4635 struct bgp_node *top;
4636 struct bgp_node *rn;
4637 u_char origin;
4638 struct aspath *aspath = NULL;
4639 struct aspath *asmerge = NULL;
4640 struct community *community = NULL;
4641 struct community *commerge = NULL;
4642 #if defined(AGGREGATE_NEXTHOP_CHECK)
4643 struct in_addr nexthop;
4644 u_int32_t med = 0;
4645 #endif
4646 struct bgp_info *ri;
4647 struct bgp_info *new;
4648 int first = 1;
4649 unsigned long match = 0;
4650 u_char atomic_aggregate = 0;
4651
4652 /* Record adding route's nexthop and med. */
4653 if (rinew)
4654 {
4655 #if defined(AGGREGATE_NEXTHOP_CHECK)
4656 nexthop = rinew->attr->nexthop;
4657 med = rinew->attr->med;
4658 #endif
4659 }
4660
4661 /* ORIGIN attribute: If at least one route among routes that are
4662 aggregated has ORIGIN with the value INCOMPLETE, then the
4663 aggregated route must have the ORIGIN attribute with the value
4664 INCOMPLETE. Otherwise, if at least one route among routes that
4665 are aggregated has ORIGIN with the value EGP, then the aggregated
4666 route must have the origin attribute with the value EGP. In all
4667 other case the value of the ORIGIN attribute of the aggregated
4668 route is INTERNAL. */
4669 origin = BGP_ORIGIN_IGP;
4670
4671 table = bgp->rib[afi][safi];
4672
4673 top = bgp_node_get (table, p);
4674 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4675 if (rn->p.prefixlen > p->prefixlen)
4676 {
4677 match = 0;
4678
4679 for (ri = rn->info; ri; ri = ri->next)
4680 {
4681 if (BGP_INFO_HOLDDOWN (ri))
4682 continue;
4683
4684 if (del && ri == del)
4685 continue;
4686
4687 if (! rinew && first)
4688 {
4689 #if defined(AGGREGATE_NEXTHOP_CHECK)
4690 nexthop = ri->attr->nexthop;
4691 med = ri->attr->med;
4692 #endif
4693 first = 0;
4694 }
4695
4696 #ifdef AGGREGATE_NEXTHOP_CHECK
4697 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4698 || ri->attr->med != med)
4699 {
4700 if (aspath)
4701 aspath_free (aspath);
4702 if (community)
4703 community_free (community);
4704 bgp_unlock_node (rn);
4705 bgp_unlock_node (top);
4706 return;
4707 }
4708 #endif /* AGGREGATE_NEXTHOP_CHECK */
4709
4710 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4711 atomic_aggregate = 1;
4712
4713 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4714 {
4715 if (aggregate->summary_only)
4716 {
4717 (bgp_info_extra_get (ri))->suppress++;
4718 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4719 match++;
4720 }
4721
4722 aggregate->count++;
4723
4724 if (origin < ri->attr->origin)
4725 origin = ri->attr->origin;
4726
4727 if (aggregate->as_set)
4728 {
4729 if (aspath)
4730 {
4731 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4732 aspath_free (aspath);
4733 aspath = asmerge;
4734 }
4735 else
4736 aspath = aspath_dup (ri->attr->aspath);
4737
4738 if (ri->attr->community)
4739 {
4740 if (community)
4741 {
4742 commerge = community_merge (community,
4743 ri->attr->community);
4744 community = community_uniq_sort (commerge);
4745 community_free (commerge);
4746 }
4747 else
4748 community = community_dup (ri->attr->community);
4749 }
4750 }
4751 }
4752 }
4753 if (match)
4754 bgp_process (bgp, rn, afi, safi);
4755 }
4756 bgp_unlock_node (top);
4757
4758 if (rinew)
4759 {
4760 aggregate->count++;
4761
4762 if (aggregate->summary_only)
4763 (bgp_info_extra_get (rinew))->suppress++;
4764
4765 if (origin < rinew->attr->origin)
4766 origin = rinew->attr->origin;
4767
4768 if (aggregate->as_set)
4769 {
4770 if (aspath)
4771 {
4772 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4773 aspath_free (aspath);
4774 aspath = asmerge;
4775 }
4776 else
4777 aspath = aspath_dup (rinew->attr->aspath);
4778
4779 if (rinew->attr->community)
4780 {
4781 if (community)
4782 {
4783 commerge = community_merge (community,
4784 rinew->attr->community);
4785 community = community_uniq_sort (commerge);
4786 community_free (commerge);
4787 }
4788 else
4789 community = community_dup (rinew->attr->community);
4790 }
4791 }
4792 }
4793
4794 if (aggregate->count > 0)
4795 {
4796 rn = bgp_node_get (table, p);
4797 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4798 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4799 aggregate->as_set,
4800 atomic_aggregate), rn);
4801 SET_FLAG (new->flags, BGP_INFO_VALID);
4802
4803 bgp_info_add (rn, new);
4804 bgp_unlock_node (rn);
4805 bgp_process (bgp, rn, afi, safi);
4806 }
4807 else
4808 {
4809 if (aspath)
4810 aspath_free (aspath);
4811 if (community)
4812 community_free (community);
4813 }
4814 }
4815
4816 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4817 struct bgp_aggregate *);
4818
4819 void
4820 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4821 struct bgp_info *ri, afi_t afi, safi_t safi)
4822 {
4823 struct bgp_node *child;
4824 struct bgp_node *rn;
4825 struct bgp_aggregate *aggregate;
4826 struct bgp_table *table;
4827
4828 /* MPLS-VPN aggregation is not yet supported. */
4829 if (safi == SAFI_MPLS_VPN)
4830 return;
4831
4832 table = bgp->aggregate[afi][safi];
4833
4834 /* No aggregates configured. */
4835 if (bgp_table_top_nolock (table) == NULL)
4836 return;
4837
4838 if (p->prefixlen == 0)
4839 return;
4840
4841 if (BGP_INFO_HOLDDOWN (ri))
4842 return;
4843
4844 child = bgp_node_get (table, p);
4845
4846 /* Aggregate address configuration check. */
4847 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4848 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4849 {
4850 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4851 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4852 }
4853 bgp_unlock_node (child);
4854 }
4855
4856 void
4857 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4858 struct bgp_info *del, afi_t afi, safi_t safi)
4859 {
4860 struct bgp_node *child;
4861 struct bgp_node *rn;
4862 struct bgp_aggregate *aggregate;
4863 struct bgp_table *table;
4864
4865 /* MPLS-VPN aggregation is not yet supported. */
4866 if (safi == SAFI_MPLS_VPN)
4867 return;
4868
4869 table = bgp->aggregate[afi][safi];
4870
4871 /* No aggregates configured. */
4872 if (bgp_table_top_nolock (table) == NULL)
4873 return;
4874
4875 if (p->prefixlen == 0)
4876 return;
4877
4878 child = bgp_node_get (table, p);
4879
4880 /* Aggregate address configuration check. */
4881 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4882 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4883 {
4884 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4885 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4886 }
4887 bgp_unlock_node (child);
4888 }
4889
4890 /* Called via bgp_aggregate_set when the user configures aggregate-address */
4891 static void
4892 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4893 struct bgp_aggregate *aggregate)
4894 {
4895 struct bgp_table *table;
4896 struct bgp_node *top;
4897 struct bgp_node *rn;
4898 struct bgp_info *new;
4899 struct bgp_info *ri;
4900 unsigned long match;
4901 u_char origin = BGP_ORIGIN_IGP;
4902 struct aspath *aspath = NULL;
4903 struct aspath *asmerge = NULL;
4904 struct community *community = NULL;
4905 struct community *commerge = NULL;
4906 u_char atomic_aggregate = 0;
4907
4908 table = bgp->rib[afi][safi];
4909
4910 /* Sanity check. */
4911 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4912 return;
4913 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4914 return;
4915
4916 /* If routes exists below this node, generate aggregate routes. */
4917 top = bgp_node_get (table, p);
4918 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4919 if (rn->p.prefixlen > p->prefixlen)
4920 {
4921 match = 0;
4922
4923 for (ri = rn->info; ri; ri = ri->next)
4924 {
4925 if (BGP_INFO_HOLDDOWN (ri))
4926 continue;
4927
4928 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4929 atomic_aggregate = 1;
4930
4931 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4932 {
4933 /* summary-only aggregate route suppress aggregated
4934 route announcement. */
4935 if (aggregate->summary_only)
4936 {
4937 (bgp_info_extra_get (ri))->suppress++;
4938 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4939 match++;
4940 }
4941
4942 /* If at least one route among routes that are aggregated has
4943 * ORIGIN with the value INCOMPLETE, then the aggregated route
4944 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4945 * Otherwise, if at least one route among routes that are
4946 * aggregated has ORIGIN with the value EGP, then the aggregated
4947 * route MUST have the ORIGIN attribute with the value EGP.
4948 */
4949 if (origin < ri->attr->origin)
4950 origin = ri->attr->origin;
4951
4952 /* as-set aggregate route generate origin, as path,
4953 community aggregation. */
4954 if (aggregate->as_set)
4955 {
4956 if (aspath)
4957 {
4958 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4959 aspath_free (aspath);
4960 aspath = asmerge;
4961 }
4962 else
4963 aspath = aspath_dup (ri->attr->aspath);
4964
4965 if (ri->attr->community)
4966 {
4967 if (community)
4968 {
4969 commerge = community_merge (community,
4970 ri->attr->community);
4971 community = community_uniq_sort (commerge);
4972 community_free (commerge);
4973 }
4974 else
4975 community = community_dup (ri->attr->community);
4976 }
4977 }
4978 aggregate->count++;
4979 }
4980 }
4981
4982 /* If this node is suppressed, process the change. */
4983 if (match)
4984 bgp_process (bgp, rn, afi, safi);
4985 }
4986 bgp_unlock_node (top);
4987
4988 /* Add aggregate route to BGP table. */
4989 if (aggregate->count)
4990 {
4991 rn = bgp_node_get (table, p);
4992 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4993 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4994 aggregate->as_set,
4995 atomic_aggregate), rn);
4996 SET_FLAG (new->flags, BGP_INFO_VALID);
4997
4998 bgp_info_add (rn, new);
4999 bgp_unlock_node (rn);
5000
5001 /* Process change. */
5002 bgp_process (bgp, rn, afi, safi);
5003 }
5004 else
5005 {
5006 if (aspath)
5007 aspath_free (aspath);
5008 if (community)
5009 community_free (community);
5010 }
5011 }
5012
5013 void
5014 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5015 safi_t safi, struct bgp_aggregate *aggregate)
5016 {
5017 struct bgp_table *table;
5018 struct bgp_node *top;
5019 struct bgp_node *rn;
5020 struct bgp_info *ri;
5021 unsigned long match;
5022
5023 table = bgp->rib[afi][safi];
5024
5025 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5026 return;
5027 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5028 return;
5029
5030 /* If routes exists below this node, generate aggregate routes. */
5031 top = bgp_node_get (table, p);
5032 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5033 if (rn->p.prefixlen > p->prefixlen)
5034 {
5035 match = 0;
5036
5037 for (ri = rn->info; ri; ri = ri->next)
5038 {
5039 if (BGP_INFO_HOLDDOWN (ri))
5040 continue;
5041
5042 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5043 {
5044 if (aggregate->summary_only && ri->extra)
5045 {
5046 ri->extra->suppress--;
5047
5048 if (ri->extra->suppress == 0)
5049 {
5050 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5051 match++;
5052 }
5053 }
5054 aggregate->count--;
5055 }
5056 }
5057
5058 /* If this node was suppressed, process the change. */
5059 if (match)
5060 bgp_process (bgp, rn, afi, safi);
5061 }
5062 bgp_unlock_node (top);
5063
5064 /* Delete aggregate route from BGP table. */
5065 rn = bgp_node_get (table, p);
5066
5067 for (ri = rn->info; ri; ri = ri->next)
5068 if (ri->peer == bgp->peer_self
5069 && ri->type == ZEBRA_ROUTE_BGP
5070 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5071 break;
5072
5073 /* Withdraw static BGP route from routing table. */
5074 if (ri)
5075 {
5076 bgp_info_delete (rn, ri);
5077 bgp_process (bgp, rn, afi, safi);
5078 }
5079
5080 /* Unlock bgp_node_lookup. */
5081 bgp_unlock_node (rn);
5082 }
5083
5084 /* Aggregate route attribute. */
5085 #define AGGREGATE_SUMMARY_ONLY 1
5086 #define AGGREGATE_AS_SET 1
5087
5088 static int
5089 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5090 afi_t afi, safi_t safi)
5091 {
5092 int ret;
5093 struct prefix p;
5094 struct bgp_node *rn;
5095 struct bgp *bgp;
5096 struct bgp_aggregate *aggregate;
5097
5098 /* Convert string to prefix structure. */
5099 ret = str2prefix (prefix_str, &p);
5100 if (!ret)
5101 {
5102 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5103 return CMD_WARNING;
5104 }
5105 apply_mask (&p);
5106
5107 /* Get BGP structure. */
5108 bgp = vty->index;
5109
5110 /* Old configuration check. */
5111 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5112 if (! rn)
5113 {
5114 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5115 VTY_NEWLINE);
5116 return CMD_WARNING;
5117 }
5118
5119 aggregate = rn->info;
5120 if (aggregate->safi & SAFI_UNICAST)
5121 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5122 if (aggregate->safi & SAFI_MULTICAST)
5123 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5124
5125 /* Unlock aggregate address configuration. */
5126 rn->info = NULL;
5127 bgp_aggregate_free (aggregate);
5128 bgp_unlock_node (rn);
5129 bgp_unlock_node (rn);
5130
5131 return CMD_SUCCESS;
5132 }
5133
5134 static int
5135 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5136 afi_t afi, safi_t safi,
5137 u_char summary_only, u_char as_set)
5138 {
5139 int ret;
5140 struct prefix p;
5141 struct bgp_node *rn;
5142 struct bgp *bgp;
5143 struct bgp_aggregate *aggregate;
5144
5145 /* Convert string to prefix structure. */
5146 ret = str2prefix (prefix_str, &p);
5147 if (!ret)
5148 {
5149 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5150 return CMD_WARNING;
5151 }
5152 apply_mask (&p);
5153
5154 /* Get BGP structure. */
5155 bgp = vty->index;
5156
5157 /* Old configuration check. */
5158 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5159
5160 if (rn->info)
5161 {
5162 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5163 /* try to remove the old entry */
5164 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5165 if (ret)
5166 {
5167 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5168 bgp_unlock_node (rn);
5169 return CMD_WARNING;
5170 }
5171 }
5172
5173 /* Make aggregate address structure. */
5174 aggregate = bgp_aggregate_new ();
5175 aggregate->summary_only = summary_only;
5176 aggregate->as_set = as_set;
5177 aggregate->safi = safi;
5178 rn->info = aggregate;
5179
5180 /* Aggregate address insert into BGP routing table. */
5181 if (safi & SAFI_UNICAST)
5182 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5183 if (safi & SAFI_MULTICAST)
5184 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5185
5186 return CMD_SUCCESS;
5187 }
5188
5189 DEFUN (aggregate_address,
5190 aggregate_address_cmd,
5191 "aggregate-address A.B.C.D/M",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate prefix\n")
5194 {
5195 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5196 }
5197
5198 DEFUN (aggregate_address_mask,
5199 aggregate_address_mask_cmd,
5200 "aggregate-address A.B.C.D A.B.C.D",
5201 "Configure BGP aggregate entries\n"
5202 "Aggregate address\n"
5203 "Aggregate mask\n")
5204 {
5205 int ret;
5206 char prefix_str[BUFSIZ];
5207
5208 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5209
5210 if (! ret)
5211 {
5212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5213 return CMD_WARNING;
5214 }
5215
5216 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5217 0, 0);
5218 }
5219
5220 DEFUN (aggregate_address_summary_only,
5221 aggregate_address_summary_only_cmd,
5222 "aggregate-address A.B.C.D/M summary-only",
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate prefix\n"
5225 "Filter more specific routes from updates\n")
5226 {
5227 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5228 AGGREGATE_SUMMARY_ONLY, 0);
5229 }
5230
5231 DEFUN (aggregate_address_mask_summary_only,
5232 aggregate_address_mask_summary_only_cmd,
5233 "aggregate-address A.B.C.D A.B.C.D summary-only",
5234 "Configure BGP aggregate entries\n"
5235 "Aggregate address\n"
5236 "Aggregate mask\n"
5237 "Filter more specific routes from updates\n")
5238 {
5239 int ret;
5240 char prefix_str[BUFSIZ];
5241
5242 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5243
5244 if (! ret)
5245 {
5246 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5247 return CMD_WARNING;
5248 }
5249
5250 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5251 AGGREGATE_SUMMARY_ONLY, 0);
5252 }
5253
5254 DEFUN (aggregate_address_as_set,
5255 aggregate_address_as_set_cmd,
5256 "aggregate-address A.B.C.D/M as-set",
5257 "Configure BGP aggregate entries\n"
5258 "Aggregate prefix\n"
5259 "Generate AS set path information\n")
5260 {
5261 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5262 0, AGGREGATE_AS_SET);
5263 }
5264
5265 DEFUN (aggregate_address_mask_as_set,
5266 aggregate_address_mask_as_set_cmd,
5267 "aggregate-address A.B.C.D A.B.C.D as-set",
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate address\n"
5270 "Aggregate mask\n"
5271 "Generate AS set path information\n")
5272 {
5273 int ret;
5274 char prefix_str[BUFSIZ];
5275
5276 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5277
5278 if (! ret)
5279 {
5280 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5281 return CMD_WARNING;
5282 }
5283
5284 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5285 0, AGGREGATE_AS_SET);
5286 }
5287
5288
5289 DEFUN (aggregate_address_as_set_summary,
5290 aggregate_address_as_set_summary_cmd,
5291 "aggregate-address A.B.C.D/M as-set summary-only",
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate prefix\n"
5294 "Generate AS set path information\n"
5295 "Filter more specific routes from updates\n")
5296 {
5297 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5298 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5299 }
5300
5301 ALIAS (aggregate_address_as_set_summary,
5302 aggregate_address_summary_as_set_cmd,
5303 "aggregate-address A.B.C.D/M summary-only as-set",
5304 "Configure BGP aggregate entries\n"
5305 "Aggregate prefix\n"
5306 "Filter more specific routes from updates\n"
5307 "Generate AS set path information\n")
5308
5309 DEFUN (aggregate_address_mask_as_set_summary,
5310 aggregate_address_mask_as_set_summary_cmd,
5311 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5312 "Configure BGP aggregate entries\n"
5313 "Aggregate address\n"
5314 "Aggregate mask\n"
5315 "Generate AS set path information\n"
5316 "Filter more specific routes from updates\n")
5317 {
5318 int ret;
5319 char prefix_str[BUFSIZ];
5320
5321 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5322
5323 if (! ret)
5324 {
5325 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5326 return CMD_WARNING;
5327 }
5328
5329 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5330 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5331 }
5332
5333 ALIAS (aggregate_address_mask_as_set_summary,
5334 aggregate_address_mask_summary_as_set_cmd,
5335 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5336 "Configure BGP aggregate entries\n"
5337 "Aggregate address\n"
5338 "Aggregate mask\n"
5339 "Filter more specific routes from updates\n"
5340 "Generate AS set path information\n")
5341
5342 DEFUN (no_aggregate_address,
5343 no_aggregate_address_cmd,
5344 "no aggregate-address A.B.C.D/M",
5345 NO_STR
5346 "Configure BGP aggregate entries\n"
5347 "Aggregate prefix\n")
5348 {
5349 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5350 }
5351
5352 ALIAS (no_aggregate_address,
5353 no_aggregate_address_summary_only_cmd,
5354 "no aggregate-address A.B.C.D/M summary-only",
5355 NO_STR
5356 "Configure BGP aggregate entries\n"
5357 "Aggregate prefix\n"
5358 "Filter more specific routes from updates\n")
5359
5360 ALIAS (no_aggregate_address,
5361 no_aggregate_address_as_set_cmd,
5362 "no aggregate-address A.B.C.D/M as-set",
5363 NO_STR
5364 "Configure BGP aggregate entries\n"
5365 "Aggregate prefix\n"
5366 "Generate AS set path information\n")
5367
5368 ALIAS (no_aggregate_address,
5369 no_aggregate_address_as_set_summary_cmd,
5370 "no aggregate-address A.B.C.D/M as-set summary-only",
5371 NO_STR
5372 "Configure BGP aggregate entries\n"
5373 "Aggregate prefix\n"
5374 "Generate AS set path information\n"
5375 "Filter more specific routes from updates\n")
5376
5377 ALIAS (no_aggregate_address,
5378 no_aggregate_address_summary_as_set_cmd,
5379 "no aggregate-address A.B.C.D/M summary-only as-set",
5380 NO_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Filter more specific routes from updates\n"
5384 "Generate AS set path information\n")
5385
5386 DEFUN (no_aggregate_address_mask,
5387 no_aggregate_address_mask_cmd,
5388 "no aggregate-address A.B.C.D A.B.C.D",
5389 NO_STR
5390 "Configure BGP aggregate entries\n"
5391 "Aggregate address\n"
5392 "Aggregate mask\n")
5393 {
5394 int ret;
5395 char prefix_str[BUFSIZ];
5396
5397 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5398
5399 if (! ret)
5400 {
5401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5402 return CMD_WARNING;
5403 }
5404
5405 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5406 }
5407
5408 ALIAS (no_aggregate_address_mask,
5409 no_aggregate_address_mask_summary_only_cmd,
5410 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5411 NO_STR
5412 "Configure BGP aggregate entries\n"
5413 "Aggregate address\n"
5414 "Aggregate mask\n"
5415 "Filter more specific routes from updates\n")
5416
5417 ALIAS (no_aggregate_address_mask,
5418 no_aggregate_address_mask_as_set_cmd,
5419 "no aggregate-address A.B.C.D A.B.C.D as-set",
5420 NO_STR
5421 "Configure BGP aggregate entries\n"
5422 "Aggregate address\n"
5423 "Aggregate mask\n"
5424 "Generate AS set path information\n")
5425
5426 ALIAS (no_aggregate_address_mask,
5427 no_aggregate_address_mask_as_set_summary_cmd,
5428 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5429 NO_STR
5430 "Configure BGP aggregate entries\n"
5431 "Aggregate address\n"
5432 "Aggregate mask\n"
5433 "Generate AS set path information\n"
5434 "Filter more specific routes from updates\n")
5435
5436 ALIAS (no_aggregate_address_mask,
5437 no_aggregate_address_mask_summary_as_set_cmd,
5438 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5439 NO_STR
5440 "Configure BGP aggregate entries\n"
5441 "Aggregate address\n"
5442 "Aggregate mask\n"
5443 "Filter more specific routes from updates\n"
5444 "Generate AS set path information\n")
5445
5446 #ifdef HAVE_IPV6
5447 DEFUN (ipv6_aggregate_address,
5448 ipv6_aggregate_address_cmd,
5449 "aggregate-address X:X::X:X/M",
5450 "Configure BGP aggregate entries\n"
5451 "Aggregate prefix\n")
5452 {
5453 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5454 }
5455
5456 DEFUN (ipv6_aggregate_address_summary_only,
5457 ipv6_aggregate_address_summary_only_cmd,
5458 "aggregate-address X:X::X:X/M summary-only",
5459 "Configure BGP aggregate entries\n"
5460 "Aggregate prefix\n"
5461 "Filter more specific routes from updates\n")
5462 {
5463 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5464 AGGREGATE_SUMMARY_ONLY, 0);
5465 }
5466
5467 DEFUN (no_ipv6_aggregate_address,
5468 no_ipv6_aggregate_address_cmd,
5469 "no aggregate-address X:X::X:X/M",
5470 NO_STR
5471 "Configure BGP aggregate entries\n"
5472 "Aggregate prefix\n")
5473 {
5474 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5475 }
5476
5477 DEFUN (no_ipv6_aggregate_address_summary_only,
5478 no_ipv6_aggregate_address_summary_only_cmd,
5479 "no aggregate-address X:X::X:X/M summary-only",
5480 NO_STR
5481 "Configure BGP aggregate entries\n"
5482 "Aggregate prefix\n"
5483 "Filter more specific routes from updates\n")
5484 {
5485 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5486 }
5487
5488 ALIAS (ipv6_aggregate_address,
5489 old_ipv6_aggregate_address_cmd,
5490 "ipv6 bgp aggregate-address X:X::X:X/M",
5491 IPV6_STR
5492 BGP_STR
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate prefix\n")
5495
5496 ALIAS (ipv6_aggregate_address_summary_only,
5497 old_ipv6_aggregate_address_summary_only_cmd,
5498 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5499 IPV6_STR
5500 BGP_STR
5501 "Configure BGP aggregate entries\n"
5502 "Aggregate prefix\n"
5503 "Filter more specific routes from updates\n")
5504
5505 ALIAS (no_ipv6_aggregate_address,
5506 old_no_ipv6_aggregate_address_cmd,
5507 "no ipv6 bgp aggregate-address X:X::X:X/M",
5508 NO_STR
5509 IPV6_STR
5510 BGP_STR
5511 "Configure BGP aggregate entries\n"
5512 "Aggregate prefix\n")
5513
5514 ALIAS (no_ipv6_aggregate_address_summary_only,
5515 old_no_ipv6_aggregate_address_summary_only_cmd,
5516 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5517 NO_STR
5518 IPV6_STR
5519 BGP_STR
5520 "Configure BGP aggregate entries\n"
5521 "Aggregate prefix\n"
5522 "Filter more specific routes from updates\n")
5523 #endif /* HAVE_IPV6 */
5524
5525 /* Redistribute route treatment. */
5526 void
5527 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5528 const struct in6_addr *nexthop6, unsigned int ifindex,
5529 u_int32_t metric, u_char type, u_short instance, u_short tag)
5530 {
5531 struct bgp_info *new;
5532 struct bgp_info *bi;
5533 struct bgp_info info;
5534 struct bgp_node *bn;
5535 struct attr attr;
5536 struct attr *new_attr;
5537 afi_t afi;
5538 int ret;
5539 struct bgp_redist *red;
5540
5541 /* Make default attribute. */
5542 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5543 if (nexthop)
5544 attr.nexthop = *nexthop;
5545 attr.nh_ifindex = ifindex;
5546
5547 #ifdef HAVE_IPV6
5548 if (nexthop6)
5549 {
5550 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5551 extra->mp_nexthop_global = *nexthop6;
5552 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5553 }
5554 #endif
5555
5556 attr.med = metric;
5557 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5558 attr.extra->tag = tag;
5559
5560 afi = family2afi (p->family);
5561
5562 red = bgp_redist_lookup(bgp, afi, type, instance);
5563 if (red)
5564 {
5565 struct attr attr_new;
5566 struct attr_extra extra_new;
5567
5568 /* Copy attribute for modification. */
5569 attr_new.extra = &extra_new;
5570 bgp_attr_dup (&attr_new, &attr);
5571
5572 if (red->redist_metric_flag)
5573 attr_new.med = red->redist_metric;
5574
5575 /* Apply route-map. */
5576 if (red->rmap.name)
5577 {
5578 info.peer = bgp->peer_self;
5579 info.attr = &attr_new;
5580
5581 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5582
5583 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5584
5585 bgp->peer_self->rmap_type = 0;
5586
5587 if (ret == RMAP_DENYMATCH)
5588 {
5589 /* Free uninterned attribute. */
5590 bgp_attr_flush (&attr_new);
5591
5592 /* Unintern original. */
5593 aspath_unintern (&attr.aspath);
5594 bgp_attr_extra_free (&attr);
5595 bgp_redistribute_delete (bgp, p, type, instance);
5596 return;
5597 }
5598 }
5599
5600 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5601 afi, SAFI_UNICAST, p, NULL);
5602
5603 new_attr = bgp_attr_intern (&attr_new);
5604
5605 for (bi = bn->info; bi; bi = bi->next)
5606 if (bi->peer == bgp->peer_self
5607 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5608 break;
5609
5610 if (bi)
5611 {
5612 /* Ensure the (source route) type is updated. */
5613 bi->type = type;
5614 if (attrhash_cmp (bi->attr, new_attr) &&
5615 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5616 {
5617 bgp_attr_unintern (&new_attr);
5618 aspath_unintern (&attr.aspath);
5619 bgp_attr_extra_free (&attr);
5620 bgp_unlock_node (bn);
5621 return;
5622 }
5623 else
5624 {
5625 /* The attribute is changed. */
5626 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5627
5628 /* Rewrite BGP route information. */
5629 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5630 bgp_info_restore(bn, bi);
5631 else
5632 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5633 bgp_attr_unintern (&bi->attr);
5634 bi->attr = new_attr;
5635 bi->uptime = bgp_clock ();
5636
5637 /* Process change. */
5638 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5639 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5640 bgp_unlock_node (bn);
5641 aspath_unintern (&attr.aspath);
5642 bgp_attr_extra_free (&attr);
5643 return;
5644 }
5645 }
5646
5647 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5648 new_attr, bn);
5649 SET_FLAG (new->flags, BGP_INFO_VALID);
5650
5651 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5652 bgp_info_add (bn, new);
5653 bgp_unlock_node (bn);
5654 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5655 }
5656
5657 /* Unintern original. */
5658 aspath_unintern (&attr.aspath);
5659 bgp_attr_extra_free (&attr);
5660 }
5661
5662 void
5663 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5664 {
5665 afi_t afi;
5666 struct bgp_node *rn;
5667 struct bgp_info *ri;
5668 struct bgp_redist *red;
5669
5670 afi = family2afi (p->family);
5671
5672 red = bgp_redist_lookup(bgp, afi, type, instance);
5673 if (red)
5674 {
5675 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5676
5677 for (ri = rn->info; ri; ri = ri->next)
5678 if (ri->peer == bgp->peer_self
5679 && ri->type == type)
5680 break;
5681
5682 if (ri)
5683 {
5684 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5685 bgp_info_delete (rn, ri);
5686 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5687 }
5688 bgp_unlock_node (rn);
5689 }
5690 }
5691
5692 /* Withdraw specified route type's route. */
5693 void
5694 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5695 {
5696 struct bgp_node *rn;
5697 struct bgp_info *ri;
5698 struct bgp_table *table;
5699
5700 table = bgp->rib[afi][SAFI_UNICAST];
5701
5702 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5703 {
5704 for (ri = rn->info; ri; ri = ri->next)
5705 if (ri->peer == bgp->peer_self
5706 && ri->type == type
5707 && ri->instance == instance)
5708 break;
5709
5710 if (ri)
5711 {
5712 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5713 bgp_info_delete (rn, ri);
5714 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5715 }
5716 }
5717 }
5718
5719 /* Static function to display route. */
5720 static void
5721 route_vty_out_route (struct prefix *p, struct vty *vty)
5722 {
5723 int len;
5724 u_int32_t destination;
5725 char buf[BUFSIZ];
5726
5727 if (p->family == AF_INET)
5728 {
5729 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5730 destination = ntohl (p->u.prefix4.s_addr);
5731
5732 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5733 || (IN_CLASSB (destination) && p->prefixlen == 16)
5734 || (IN_CLASSA (destination) && p->prefixlen == 8)
5735 || p->u.prefix4.s_addr == 0)
5736 {
5737 /* When mask is natural, mask is not displayed. */
5738 }
5739 else
5740 len += vty_out (vty, "/%d", p->prefixlen);
5741 }
5742 else
5743 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5744 p->prefixlen);
5745
5746 len = 17 - len;
5747 if (len < 1)
5748 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5749 else
5750 vty_out (vty, "%*s", len, " ");
5751 }
5752
5753 enum bgp_display_type
5754 {
5755 normal_list,
5756 };
5757
5758 /* Print the short form route status for a bgp_info */
5759 static void
5760 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5761 json_object *json_path)
5762 {
5763 if (json_path)
5764 {
5765
5766 /* Route status display. */
5767 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5768 json_object_boolean_true_add(json_path, "removed");
5769
5770 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5771 json_object_boolean_true_add(json_path, "stale");
5772
5773 if (binfo->extra && binfo->extra->suppress)
5774 json_object_boolean_true_add(json_path, "suppressed");
5775
5776 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5777 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5778 json_object_boolean_true_add(json_path, "valid");
5779
5780 /* Selected */
5781 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5782 json_object_boolean_true_add(json_path, "history");
5783
5784 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5785 json_object_boolean_true_add(json_path, "damped");
5786
5787 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5788 json_object_boolean_true_add(json_path, "bestpath");
5789
5790 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5791 json_object_boolean_true_add(json_path, "multipath");
5792
5793 /* Internal route. */
5794 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5795 json_object_string_add(json_path, "pathFrom", "internal");
5796 else
5797 json_object_string_add(json_path, "pathFrom", "external");
5798
5799 return;
5800 }
5801
5802 /* Route status display. */
5803 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5804 vty_out (vty, "R");
5805 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5806 vty_out (vty, "S");
5807 else if (binfo->extra && binfo->extra->suppress)
5808 vty_out (vty, "s");
5809 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5810 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5811 vty_out (vty, "*");
5812 else
5813 vty_out (vty, " ");
5814
5815 /* Selected */
5816 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5817 vty_out (vty, "h");
5818 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5819 vty_out (vty, "d");
5820 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5821 vty_out (vty, ">");
5822 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5823 vty_out (vty, "=");
5824 else
5825 vty_out (vty, " ");
5826
5827 /* Internal route. */
5828 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5829 vty_out (vty, "i");
5830 else
5831 vty_out (vty, " ");
5832 }
5833
5834 /* called from terminal list command */
5835 void
5836 route_vty_out (struct vty *vty, struct prefix *p,
5837 struct bgp_info *binfo, int display, safi_t safi,
5838 json_object *json_paths)
5839 {
5840 struct attr *attr;
5841 json_object *json_path = NULL;
5842 json_object *json_nexthops = NULL;
5843 json_object *json_nexthop_global = NULL;
5844 json_object *json_nexthop_ll = NULL;
5845
5846 if (json_paths)
5847 json_path = json_object_new_object();
5848
5849 /* short status lead text */
5850 route_vty_short_status_out (vty, binfo, json_path);
5851
5852 if (!json_paths)
5853 {
5854 /* print prefix and mask */
5855 if (! display)
5856 route_vty_out_route (p, vty);
5857 else
5858 vty_out (vty, "%*s", 17, " ");
5859 }
5860
5861 /* Print attribute */
5862 attr = binfo->attr;
5863 if (attr)
5864 {
5865
5866 /* IPv4 Next Hop */
5867 if (p->family == AF_INET
5868 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5869 {
5870 if (json_paths)
5871 {
5872 json_nexthop_global = json_object_new_object();
5873
5874 if (safi == SAFI_MPLS_VPN)
5875 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
5876 else
5877 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5878
5879 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5880 json_object_boolean_true_add(json_nexthop_global, "used");
5881 }
5882 else
5883 {
5884 if (safi == SAFI_MPLS_VPN)
5885 vty_out (vty, "%-16s",
5886 inet_ntoa (attr->extra->mp_nexthop_global_in));
5887 else
5888 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5889 }
5890 }
5891
5892 #ifdef HAVE_IPV6
5893 /* IPv6 Next Hop */
5894 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5895 {
5896 int len;
5897 char buf[BUFSIZ];
5898
5899 if (json_paths)
5900 {
5901 json_nexthop_global = json_object_new_object();
5902 json_object_string_add(json_nexthop_global, "ip",
5903 inet_ntop (AF_INET6,
5904 &attr->extra->mp_nexthop_global,
5905 buf, BUFSIZ));
5906 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5907 json_object_string_add(json_nexthop_global, "scope", "global");
5908
5909 /* We display both LL & GL if both have been received */
5910 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5911 {
5912 json_nexthop_ll = json_object_new_object();
5913 json_object_string_add(json_nexthop_ll, "ip",
5914 inet_ntop (AF_INET6,
5915 &attr->extra->mp_nexthop_local,
5916 buf, BUFSIZ));
5917 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5918 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5919
5920 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5921 &attr->extra->mp_nexthop_local) != 0)
5922 json_object_boolean_true_add(json_nexthop_ll, "used");
5923 else
5924 json_object_boolean_true_add(json_nexthop_global, "used");
5925 }
5926 else
5927 json_object_boolean_true_add(json_nexthop_global, "used");
5928 }
5929 else
5930 {
5931 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5932 {
5933 if (binfo->peer->conf_if)
5934 {
5935 len = vty_out (vty, "%s",
5936 binfo->peer->conf_if);
5937 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5938
5939 if (len < 1)
5940 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5941 else
5942 vty_out (vty, "%*s", len, " ");
5943 }
5944 else
5945 {
5946 len = vty_out (vty, "%s",
5947 inet_ntop (AF_INET6,
5948 &attr->extra->mp_nexthop_local,
5949 buf, BUFSIZ));
5950 len = 16 - len;
5951
5952 if (len < 1)
5953 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5954 else
5955 vty_out (vty, "%*s", len, " ");
5956 }
5957 }
5958 else
5959 {
5960 len = vty_out (vty, "%s",
5961 inet_ntop (AF_INET6,
5962 &attr->extra->mp_nexthop_global,
5963 buf, BUFSIZ));
5964 len = 16 - len;
5965
5966 if (len < 1)
5967 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5968 else
5969 vty_out (vty, "%*s", len, " ");
5970 }
5971 }
5972 }
5973 #endif /* HAVE_IPV6 */
5974
5975 /* MED/Metric */
5976 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5977 if (json_paths)
5978 json_object_int_add(json_path, "med", attr->med);
5979 else
5980 vty_out (vty, "%10u", attr->med);
5981 else
5982 if (!json_paths)
5983 vty_out (vty, " ");
5984
5985 /* Local Pref */
5986 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5987 if (json_paths)
5988 json_object_int_add(json_path, "localpref", attr->local_pref);
5989 else
5990 vty_out (vty, "%7u", attr->local_pref);
5991 else
5992 if (!json_paths)
5993 vty_out (vty, " ");
5994
5995 if (json_paths)
5996 {
5997 if (attr->extra)
5998 json_object_int_add(json_path, "weight", attr->extra->weight);
5999 else
6000 json_object_int_add(json_path, "weight", 0);
6001 }
6002 else
6003 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6004
6005 /* Print aspath */
6006 if (attr->aspath)
6007 {
6008 if (json_paths)
6009 json_object_string_add(json_path, "aspath", attr->aspath->str);
6010 else
6011 aspath_print_vty (vty, "%s", attr->aspath, " ");
6012 }
6013
6014 /* Print origin */
6015 if (json_paths)
6016 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6017 else
6018 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6019 }
6020 else
6021 {
6022 if (json_paths)
6023 json_object_string_add(json_path, "alert", "No attributes");
6024 else
6025 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6026 }
6027
6028 if (json_paths)
6029 {
6030 if (json_nexthop_global || json_nexthop_ll)
6031 {
6032 json_nexthops = json_object_new_array();
6033
6034 if (json_nexthop_global)
6035 json_object_array_add(json_nexthops, json_nexthop_global);
6036
6037 if (json_nexthop_ll)
6038 json_object_array_add(json_nexthops, json_nexthop_ll);
6039
6040 json_object_object_add(json_path, "nexthops", json_nexthops);
6041 }
6042
6043 json_object_array_add(json_paths, json_path);
6044 }
6045 else
6046 vty_out (vty, "%s", VTY_NEWLINE);
6047 }
6048
6049 /* called from terminal list command */
6050 void
6051 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6052 u_char use_json, json_object *json_ar)
6053 {
6054 json_object *json_status = NULL;
6055 json_object *json_net = NULL;
6056 char buff[BUFSIZ];
6057 /* Route status display. */
6058 if (use_json)
6059 {
6060 json_status = json_object_new_object();
6061 json_net = json_object_new_object();
6062 }
6063 else
6064 {
6065 vty_out (vty, "*");
6066 vty_out (vty, ">");
6067 vty_out (vty, " ");
6068 }
6069
6070 /* print prefix and mask */
6071 if (use_json)
6072 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6073 else
6074 route_vty_out_route (p, vty);
6075
6076 /* Print attribute */
6077 if (attr)
6078 {
6079 if (use_json)
6080 {
6081 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6082 {
6083 if (safi == SAFI_MPLS_VPN)
6084 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6085 else
6086 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6087 }
6088 #ifdef HAVE_IPV6
6089 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6090 {
6091 char buf[BUFSIZ];
6092
6093 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6094 buf, BUFSIZ));
6095 }
6096 #endif /* HAVE_IPV6 */
6097
6098 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6099 json_object_int_add(json_net, "metric", attr->med);
6100
6101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6102 json_object_int_add(json_net, "localPref", attr->local_pref);
6103
6104 if (attr->extra)
6105 json_object_int_add(json_net, "weight", attr->extra->weight);
6106 else
6107 json_object_int_add(json_net, "weight", 0);
6108
6109 /* Print aspath */
6110 if (attr->aspath)
6111 json_object_string_add(json_net, "asPath", attr->aspath->str);
6112
6113 /* Print origin */
6114 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6115 }
6116 else
6117 {
6118 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6119 {
6120 if (safi == SAFI_MPLS_VPN)
6121 vty_out (vty, "%-16s",
6122 inet_ntoa (attr->extra->mp_nexthop_global_in));
6123 else
6124 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6125 }
6126 #ifdef HAVE_IPV6
6127 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6128 {
6129 int len;
6130 char buf[BUFSIZ];
6131
6132 assert (attr->extra);
6133
6134 len = vty_out (vty, "%s",
6135 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6136 buf, BUFSIZ));
6137 len = 16 - len;
6138 if (len < 1)
6139 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6140 else
6141 vty_out (vty, "%*s", len, " ");
6142 }
6143 #endif /* HAVE_IPV6 */
6144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6145 vty_out (vty, "%10u", attr->med);
6146 else
6147 vty_out (vty, " ");
6148
6149 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6150 vty_out (vty, "%7u", attr->local_pref);
6151 else
6152 vty_out (vty, " ");
6153
6154 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6155
6156 /* Print aspath */
6157 if (attr->aspath)
6158 aspath_print_vty (vty, "%s", attr->aspath, " ");
6159
6160 /* Print origin */
6161 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6162 }
6163 }
6164 if (use_json)
6165 {
6166 json_object_boolean_true_add(json_status, "*");
6167 json_object_boolean_true_add(json_status, ">");
6168 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6169 char buf_cut[BUFSIZ];
6170 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6171 }
6172 else
6173 vty_out (vty, "%s", VTY_NEWLINE);
6174 }
6175
6176 void
6177 route_vty_out_tag (struct vty *vty, struct prefix *p,
6178 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6179 {
6180 json_object *json_out = NULL;
6181 struct attr *attr;
6182 u_int32_t label = 0;
6183
6184 if (!binfo->extra)
6185 return;
6186
6187 if (json)
6188 json_out = json_object_new_object();
6189
6190 /* short status lead text */
6191 route_vty_short_status_out (vty, binfo, json_out);
6192
6193 /* print prefix and mask */
6194 if (json == NULL)
6195 {
6196 if (! display)
6197 route_vty_out_route (p, vty);
6198 else
6199 vty_out (vty, "%*s", 17, " ");
6200 }
6201
6202 /* Print attribute */
6203 attr = binfo->attr;
6204 if (attr)
6205 {
6206 if (p->family == AF_INET
6207 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6208 {
6209 if (safi == SAFI_MPLS_VPN)
6210 {
6211 if (json)
6212 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6213 else
6214 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6215 }
6216 else
6217 {
6218 if (json)
6219 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6220 else
6221 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6222 }
6223 }
6224 #ifdef HAVE_IPV6
6225 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6226 {
6227 assert (attr->extra);
6228 char buf_a[BUFSIZ];
6229 char buf_b[BUFSIZ];
6230 char buf_c[BUFSIZ];
6231 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6232 {
6233 if (json)
6234 json_object_string_add(json_out, "mpNexthopGlobalIn",
6235 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6236 else
6237 vty_out (vty, "%s",
6238 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6239 buf_a, BUFSIZ));
6240 }
6241 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6242 {
6243 if (json)
6244 {
6245 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6246 buf_a, BUFSIZ);
6247 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6248 buf_b, BUFSIZ);
6249 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6250 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6251 }
6252 else
6253 vty_out (vty, "%s(%s)",
6254 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6255 buf_a, BUFSIZ),
6256 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6257 buf_b, BUFSIZ));
6258 }
6259
6260 }
6261 #endif /* HAVE_IPV6 */
6262 }
6263
6264 label = decode_label (binfo->extra->tag);
6265
6266 if (json)
6267 {
6268 if (label)
6269 json_object_int_add(json_out, "notag", label);
6270 json_object_array_add(json, json_out);
6271 }
6272 else
6273 {
6274 vty_out (vty, "notag/%d", label);
6275 vty_out (vty, "%s", VTY_NEWLINE);
6276 }
6277 }
6278
6279 /* dampening route */
6280 static void
6281 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6282 int display, safi_t safi, u_char use_json, json_object *json)
6283 {
6284 struct attr *attr;
6285 int len;
6286 char timebuf[BGP_UPTIME_LEN];
6287
6288 /* short status lead text */
6289 route_vty_short_status_out (vty, binfo, json);
6290
6291 /* print prefix and mask */
6292 if (!use_json)
6293 {
6294 if (! display)
6295 route_vty_out_route (p, vty);
6296 else
6297 vty_out (vty, "%*s", 17, " ");
6298 }
6299
6300 len = vty_out (vty, "%s", binfo->peer->host);
6301 len = 17 - len;
6302 if (len < 1)
6303 {
6304 if (!use_json)
6305 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6306 }
6307 else
6308 {
6309 if (use_json)
6310 json_object_int_add(json, "peerHost", len);
6311 else
6312 vty_out (vty, "%*s", len, " ");
6313 }
6314
6315 if (use_json)
6316 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6317 else
6318 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6319
6320 /* Print attribute */
6321 attr = binfo->attr;
6322 if (attr)
6323 {
6324 /* Print aspath */
6325 if (attr->aspath)
6326 {
6327 if (use_json)
6328 json_object_string_add(json, "asPath", attr->aspath->str);
6329 else
6330 aspath_print_vty (vty, "%s", attr->aspath, " ");
6331 }
6332
6333 /* Print origin */
6334 if (use_json)
6335 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6336 else
6337 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6338 }
6339 if (!use_json)
6340 vty_out (vty, "%s", VTY_NEWLINE);
6341 }
6342
6343 /* flap route */
6344 static void
6345 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6346 int display, safi_t safi, u_char use_json, json_object *json)
6347 {
6348 struct attr *attr;
6349 struct bgp_damp_info *bdi;
6350 char timebuf[BGP_UPTIME_LEN];
6351 int len;
6352
6353 if (!binfo->extra)
6354 return;
6355
6356 bdi = binfo->extra->damp_info;
6357
6358 /* short status lead text */
6359 route_vty_short_status_out (vty, binfo, json);
6360
6361 /* print prefix and mask */
6362 if (!use_json)
6363 {
6364 if (! display)
6365 route_vty_out_route (p, vty);
6366 else
6367 vty_out (vty, "%*s", 17, " ");
6368 }
6369
6370 len = vty_out (vty, "%s", binfo->peer->host);
6371 len = 16 - len;
6372 if (len < 1)
6373 {
6374 if (!use_json)
6375 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6376 }
6377 else
6378 {
6379 if (use_json)
6380 json_object_int_add(json, "peerHost", len);
6381 else
6382 vty_out (vty, "%*s", len, " ");
6383 }
6384
6385 len = vty_out (vty, "%d", bdi->flap);
6386 len = 5 - len;
6387 if (len < 1)
6388 {
6389 if (!use_json)
6390 vty_out (vty, " ");
6391 }
6392 else
6393 {
6394 if (use_json)
6395 json_object_int_add(json, "bdiFlap", len);
6396 else
6397 vty_out (vty, "%*s", len, " ");
6398 }
6399
6400 if (use_json)
6401 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6402 else
6403 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6404 timebuf, BGP_UPTIME_LEN, 0, NULL));
6405
6406 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6407 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6408 {
6409 if (use_json)
6410 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6411 else
6412 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6413 }
6414 else
6415 {
6416 if (!use_json)
6417 vty_out (vty, "%*s ", 8, " ");
6418 }
6419
6420 /* Print attribute */
6421 attr = binfo->attr;
6422 if (attr)
6423 {
6424 /* Print aspath */
6425 if (attr->aspath)
6426 {
6427 if (use_json)
6428 json_object_string_add(json, "asPath", attr->aspath->str);
6429 else
6430 aspath_print_vty (vty, "%s", attr->aspath, " ");
6431 }
6432
6433 /* Print origin */
6434 if (use_json)
6435 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6436 else
6437 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6438 }
6439 if (!use_json)
6440 vty_out (vty, "%s", VTY_NEWLINE);
6441 }
6442
6443 static void
6444 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6445 const char *header, json_object *json_adv_to)
6446 {
6447 char buf1[INET6_ADDRSTRLEN];
6448 json_object *json_peer = NULL;
6449
6450 if (json_adv_to)
6451 {
6452 /* 'advertised-to' is a dictionary of peers we have advertised this
6453 * prefix too. The key is the peer's IP or swpX, the value is the
6454 * hostname if we know it and "" if not.
6455 */
6456 json_peer = json_object_new_object();
6457
6458 if (peer->hostname)
6459 json_object_string_add(json_peer, "hostname", peer->hostname);
6460
6461 if (peer->conf_if)
6462 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6463 else
6464 json_object_object_add(json_adv_to,
6465 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6466 json_peer);
6467 }
6468 else
6469 {
6470 if (*first)
6471 {
6472 vty_out (vty, "%s", header);
6473 *first = 0;
6474 }
6475
6476 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6477 {
6478 if (peer->conf_if)
6479 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6480 else
6481 vty_out (vty, " %s(%s)", peer->hostname,
6482 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6483 }
6484 else
6485 {
6486 if (peer->conf_if)
6487 vty_out (vty, " %s", peer->conf_if);
6488 else
6489 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6490 }
6491 }
6492 }
6493
6494 static void
6495 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6496 struct bgp_info *binfo, afi_t afi, safi_t safi,
6497 json_object *json_paths)
6498 {
6499 char buf[INET6_ADDRSTRLEN];
6500 char buf1[BUFSIZ];
6501 struct attr *attr;
6502 int sockunion_vty_out (struct vty *, union sockunion *);
6503 #ifdef HAVE_CLOCK_MONOTONIC
6504 time_t tbuf;
6505 #endif
6506 json_object *json_bestpath = NULL;
6507 json_object *json_cluster_list = NULL;
6508 json_object *json_cluster_list_list = NULL;
6509 json_object *json_ext_community = NULL;
6510 json_object *json_last_update = NULL;
6511 json_object *json_nexthop_global = NULL;
6512 json_object *json_nexthop_ll = NULL;
6513 json_object *json_nexthops = NULL;
6514 json_object *json_path = NULL;
6515 json_object *json_peer = NULL;
6516 json_object *json_string = NULL;
6517 json_object *json_adv_to = NULL;
6518 int first = 0;
6519 struct listnode *node, *nnode;
6520 struct peer *peer;
6521 int addpath_capable;
6522 int has_adj;
6523 int first_as;
6524
6525 if (json_paths)
6526 {
6527 json_path = json_object_new_object();
6528 json_peer = json_object_new_object();
6529 json_nexthop_global = json_object_new_object();
6530 }
6531
6532 attr = binfo->attr;
6533
6534 if (attr)
6535 {
6536 /* Line1 display AS-path, Aggregator */
6537 if (attr->aspath)
6538 {
6539 if (json_paths)
6540 {
6541 json_object_lock(attr->aspath->json);
6542 json_object_object_add(json_path, "aspath", attr->aspath->json);
6543 }
6544 else
6545 {
6546 if (attr->aspath->segments)
6547 aspath_print_vty (vty, " %s", attr->aspath, "");
6548 else
6549 vty_out (vty, " Local");
6550 }
6551 }
6552
6553 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6554 {
6555 if (json_paths)
6556 json_object_boolean_true_add(json_path, "removed");
6557 else
6558 vty_out (vty, ", (removed)");
6559 }
6560
6561 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6562 {
6563 if (json_paths)
6564 json_object_boolean_true_add(json_path, "stale");
6565 else
6566 vty_out (vty, ", (stale)");
6567 }
6568
6569 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6570 {
6571 if (json_paths)
6572 {
6573 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6574 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6575 }
6576 else
6577 {
6578 vty_out (vty, ", (aggregated by %u %s)",
6579 attr->extra->aggregator_as,
6580 inet_ntoa (attr->extra->aggregator_addr));
6581 }
6582 }
6583
6584 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6585 {
6586 if (json_paths)
6587 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6588 else
6589 vty_out (vty, ", (Received from a RR-client)");
6590 }
6591
6592 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6593 {
6594 if (json_paths)
6595 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6596 else
6597 vty_out (vty, ", (Received from a RS-client)");
6598 }
6599
6600 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6601 {
6602 if (json_paths)
6603 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6604 else
6605 vty_out (vty, ", (history entry)");
6606 }
6607 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6608 {
6609 if (json_paths)
6610 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6611 else
6612 vty_out (vty, ", (suppressed due to dampening)");
6613 }
6614
6615 if (!json_paths)
6616 vty_out (vty, "%s", VTY_NEWLINE);
6617
6618 /* Line2 display Next-hop, Neighbor, Router-id */
6619 /* Display the nexthop */
6620 if (p->family == AF_INET
6621 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6622 {
6623 if (safi == SAFI_MPLS_VPN)
6624 {
6625 if (json_paths)
6626 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6627 else
6628 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6629 }
6630 else
6631 {
6632 if (json_paths)
6633 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6634 else
6635 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6636 }
6637
6638 if (json_paths)
6639 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6640 }
6641 #ifdef HAVE_IPV6
6642 else
6643 {
6644 assert (attr->extra);
6645 if (json_paths)
6646 {
6647 json_object_string_add(json_nexthop_global, "ip",
6648 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6649 buf, INET6_ADDRSTRLEN));
6650 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6651 json_object_string_add(json_nexthop_global, "scope", "global");
6652 }
6653 else
6654 {
6655 vty_out (vty, " %s",
6656 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6657 buf, INET6_ADDRSTRLEN));
6658 }
6659 }
6660 #endif /* HAVE_IPV6 */
6661
6662
6663 /* Display the IGP cost or 'inaccessible' */
6664 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6665 {
6666 if (json_paths)
6667 json_object_boolean_false_add(json_nexthop_global, "accessible");
6668 else
6669 vty_out (vty, " (inaccessible)");
6670 }
6671 else
6672 {
6673 if (binfo->extra && binfo->extra->igpmetric)
6674 {
6675 if (json_paths)
6676 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6677 else
6678 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6679 }
6680
6681 /* IGP cost is 0, display this only for json */
6682 else
6683 {
6684 if (json_paths)
6685 json_object_int_add(json_nexthop_global, "metric", 0);
6686 }
6687
6688 if (json_paths)
6689 json_object_boolean_true_add(json_nexthop_global, "accessible");
6690 }
6691
6692 /* Display peer "from" output */
6693 /* This path was originated locally */
6694 if (binfo->peer == bgp->peer_self)
6695 {
6696
6697 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6698 {
6699 if (json_paths)
6700 json_object_string_add(json_peer, "peerId", "0.0.0.0");
6701 else
6702 vty_out (vty, " from 0.0.0.0 ");
6703 }
6704 else
6705 {
6706 if (json_paths)
6707 json_object_string_add(json_peer, "peerId", "::");
6708 else
6709 vty_out (vty, " from :: ");
6710 }
6711
6712 if (json_paths)
6713 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
6714 else
6715 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6716 }
6717
6718 /* We RXed this path from one of our peers */
6719 else
6720 {
6721
6722 if (json_paths)
6723 {
6724 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6725 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6726
6727 if (binfo->peer->hostname)
6728 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6729
6730 if (binfo->peer->domainname)
6731 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6732
6733 if (binfo->peer->conf_if)
6734 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
6735 }
6736 else
6737 {
6738 if (binfo->peer->conf_if)
6739 {
6740 if (binfo->peer->hostname &&
6741 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6742 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6743 binfo->peer->conf_if);
6744 else
6745 vty_out (vty, " from %s", binfo->peer->conf_if);
6746 }
6747 else
6748 {
6749 if (binfo->peer->hostname &&
6750 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6751 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6752 binfo->peer->host);
6753 else
6754 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6755 }
6756
6757 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6758 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6759 else
6760 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6761 }
6762 }
6763
6764 if (!json_paths)
6765 vty_out (vty, "%s", VTY_NEWLINE);
6766
6767 #ifdef HAVE_IPV6
6768 /* display the link-local nexthop */
6769 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6770 {
6771 if (json_paths)
6772 {
6773 json_nexthop_ll = json_object_new_object();
6774 json_object_string_add(json_nexthop_ll, "ip",
6775 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6776 buf, INET6_ADDRSTRLEN));
6777 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6778 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6779
6780 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6781 json_object_boolean_true_add(json_nexthop_ll, "used");
6782 }
6783 else
6784 {
6785 vty_out (vty, " (%s) (used)%s",
6786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6787 buf, INET6_ADDRSTRLEN),
6788 VTY_NEWLINE);
6789 }
6790 }
6791 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6792 else
6793 {
6794 if (json_paths)
6795 json_object_boolean_true_add(json_nexthop_global, "used");
6796 }
6797 #endif /* HAVE_IPV6 */
6798
6799 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6800 if (json_paths)
6801 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6802 else
6803 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6804
6805 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6806 {
6807 if (json_paths)
6808 json_object_int_add(json_path, "med", attr->med);
6809 else
6810 vty_out (vty, ", metric %u", attr->med);
6811 }
6812
6813 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6814 {
6815 if (json_paths)
6816 json_object_int_add(json_path, "localpref", attr->local_pref);
6817 else
6818 vty_out (vty, ", localpref %u", attr->local_pref);
6819 }
6820 else
6821 {
6822 if (json_paths)
6823 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
6824 else
6825 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6826 }
6827
6828 if (attr->extra && attr->extra->weight != 0)
6829 {
6830 if (json_paths)
6831 json_object_int_add(json_path, "weight", attr->extra->weight);
6832 else
6833 vty_out (vty, ", weight %u", attr->extra->weight);
6834 }
6835
6836 if (attr->extra && attr->extra->tag != 0)
6837 {
6838 if (json_paths)
6839 json_object_int_add(json_path, "tag", attr->extra->tag);
6840 else
6841 vty_out (vty, ", tag %d", attr->extra->tag);
6842 }
6843
6844 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6845 {
6846 if (json_paths)
6847 json_object_boolean_false_add(json_path, "valid");
6848 else
6849 vty_out (vty, ", invalid");
6850 }
6851 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6852 {
6853 if (json_paths)
6854 json_object_boolean_true_add(json_path, "valid");
6855 else
6856 vty_out (vty, ", valid");
6857 }
6858
6859 if (binfo->peer != bgp->peer_self)
6860 {
6861 if (binfo->peer->as == binfo->peer->local_as)
6862 {
6863 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6864 {
6865 if (json_paths)
6866 json_object_string_add(json_peer, "type", "confed-internal");
6867 else
6868 vty_out (vty, ", confed-internal");
6869 }
6870 else
6871 {
6872 if (json_paths)
6873 json_object_string_add(json_peer, "type", "internal");
6874 else
6875 vty_out (vty, ", internal");
6876 }
6877 }
6878 else
6879 {
6880 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6881 {
6882 if (json_paths)
6883 json_object_string_add(json_peer, "type", "confed-external");
6884 else
6885 vty_out (vty, ", confed-external");
6886 }
6887 else
6888 {
6889 if (json_paths)
6890 json_object_string_add(json_peer, "type", "external");
6891 else
6892 vty_out (vty, ", external");
6893 }
6894 }
6895 }
6896 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6897 {
6898 if (json_paths)
6899 {
6900 json_object_boolean_true_add(json_path, "aggregated");
6901 json_object_boolean_true_add(json_path, "local");
6902 }
6903 else
6904 {
6905 vty_out (vty, ", aggregated, local");
6906 }
6907 }
6908 else if (binfo->type != ZEBRA_ROUTE_BGP)
6909 {
6910 if (json_paths)
6911 json_object_boolean_true_add(json_path, "sourced");
6912 else
6913 vty_out (vty, ", sourced");
6914 }
6915 else
6916 {
6917 if (json_paths)
6918 {
6919 json_object_boolean_true_add(json_path, "sourced");
6920 json_object_boolean_true_add(json_path, "local");
6921 }
6922 else
6923 {
6924 vty_out (vty, ", sourced, local");
6925 }
6926 }
6927
6928 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6929 {
6930 if (json_paths)
6931 json_object_boolean_true_add(json_path, "atomicAggregate");
6932 else
6933 vty_out (vty, ", atomic-aggregate");
6934 }
6935
6936 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6937 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6938 bgp_info_mpath_count (binfo)))
6939 {
6940 if (json_paths)
6941 json_object_boolean_true_add(json_path, "multipath");
6942 else
6943 vty_out (vty, ", multipath");
6944 }
6945
6946 // Mark the bestpath(s)
6947 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6948 {
6949 first_as = aspath_get_firstas(attr->aspath);
6950
6951 if (json_paths)
6952 {
6953 if (!json_bestpath)
6954 json_bestpath = json_object_new_object();
6955 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6956 }
6957 else
6958 {
6959 if (first_as)
6960 vty_out (vty, ", bestpath-from-AS %d", first_as);
6961 else
6962 vty_out (vty, ", bestpath-from-AS Local");
6963 }
6964 }
6965
6966 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6967 {
6968 if (json_paths)
6969 {
6970 if (!json_bestpath)
6971 json_bestpath = json_object_new_object();
6972 json_object_boolean_true_add(json_bestpath, "overall");
6973 }
6974 else
6975 vty_out (vty, ", best");
6976 }
6977
6978 if (json_bestpath)
6979 json_object_object_add(json_path, "bestpath", json_bestpath);
6980
6981 if (!json_paths)
6982 vty_out (vty, "%s", VTY_NEWLINE);
6983
6984 /* Line 4 display Community */
6985 if (attr->community)
6986 {
6987 if (json_paths)
6988 {
6989 json_object_lock(attr->community->json);
6990 json_object_object_add(json_path, "community", attr->community->json);
6991 }
6992 else
6993 {
6994 vty_out (vty, " Community: %s%s", attr->community->str,
6995 VTY_NEWLINE);
6996 }
6997 }
6998
6999 /* Line 5 display Extended-community */
7000 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7001 {
7002 if (json_paths)
7003 {
7004 json_ext_community = json_object_new_object();
7005 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7006 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7007 }
7008 else
7009 {
7010 vty_out (vty, " Extended Community: %s%s",
7011 attr->extra->ecommunity->str, VTY_NEWLINE);
7012 }
7013 }
7014
7015 /* Line 6 display Originator, Cluster-id */
7016 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7017 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7018 {
7019 assert (attr->extra);
7020 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7021 {
7022 if (json_paths)
7023 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7024 else
7025 vty_out (vty, " Originator: %s",
7026 inet_ntoa (attr->extra->originator_id));
7027 }
7028
7029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7030 {
7031 int i;
7032
7033 if (json_paths)
7034 {
7035 json_cluster_list = json_object_new_object();
7036 json_cluster_list_list = json_object_new_array();
7037
7038 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7039 {
7040 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7041 json_object_array_add(json_cluster_list_list, json_string);
7042 }
7043
7044 /* struct cluster_list does not have "str" variable like
7045 * aspath and community do. Add this someday if someone
7046 * asks for it.
7047 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7048 */
7049 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7050 json_object_object_add(json_path, "clusterList", json_cluster_list);
7051 }
7052 else
7053 {
7054 vty_out (vty, ", Cluster list: ");
7055
7056 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7057 {
7058 vty_out (vty, "%s ",
7059 inet_ntoa (attr->extra->cluster->list[i]));
7060 }
7061 }
7062 }
7063
7064 if (!json_paths)
7065 vty_out (vty, "%s", VTY_NEWLINE);
7066 }
7067
7068 if (binfo->extra && binfo->extra->damp_info)
7069 bgp_damp_info_vty (vty, binfo, json_path);
7070
7071 /* Line 7 display Addpath IDs */
7072 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7073 {
7074 if (json_paths)
7075 {
7076 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7077 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7078 }
7079 else
7080 {
7081 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7082 binfo->addpath_rx_id, binfo->addpath_tx_id,
7083 VTY_NEWLINE);
7084 }
7085 }
7086
7087 /* If we used addpath to TX a non-bestpath we need to display
7088 * "Advertised to" on a path-by-path basis */
7089 if (bgp->addpath_tx_used[afi][safi])
7090 {
7091 first = 1;
7092
7093 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7094 {
7095 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7096 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7097
7098 if ((addpath_capable && has_adj) ||
7099 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7100 {
7101 if (json_path && !json_adv_to)
7102 json_adv_to = json_object_new_object();
7103
7104 route_vty_out_advertised_to(vty, peer, &first,
7105 " Advertised to:",
7106 json_adv_to);
7107 }
7108 }
7109
7110 if (json_path)
7111 {
7112 if (json_adv_to)
7113 {
7114 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7115 }
7116 }
7117 else
7118 {
7119 if (!first)
7120 {
7121 vty_out (vty, "%s", VTY_NEWLINE);
7122 }
7123 }
7124 }
7125
7126 /* Line 8 display Uptime */
7127 #ifdef HAVE_CLOCK_MONOTONIC
7128 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7129 if (json_paths)
7130 {
7131 json_last_update = json_object_new_object();
7132 json_object_int_add(json_last_update, "epoch", tbuf);
7133 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7134 json_object_object_add(json_path, "lastUpdate", json_last_update);
7135 }
7136 else
7137 vty_out (vty, " Last update: %s", ctime(&tbuf));
7138 #else
7139 if (json_paths)
7140 {
7141 json_last_update = json_object_new_object();
7142 json_object_int_add(json_last_update, "epoch", tbuf);
7143 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7144 json_object_object_add(json_path, "lastUpdate", json_last_update);
7145 }
7146 else
7147 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7148 #endif /* HAVE_CLOCK_MONOTONIC */
7149 }
7150
7151 /* We've constructed the json object for this path, add it to the json
7152 * array of paths
7153 */
7154 if (json_paths)
7155 {
7156 if (json_nexthop_global || json_nexthop_ll)
7157 {
7158 json_nexthops = json_object_new_array();
7159
7160 if (json_nexthop_global)
7161 json_object_array_add(json_nexthops, json_nexthop_global);
7162
7163 if (json_nexthop_ll)
7164 json_object_array_add(json_nexthops, json_nexthop_ll);
7165
7166 json_object_object_add(json_path, "nexthops", json_nexthops);
7167 }
7168
7169 json_object_object_add(json_path, "peer", json_peer);
7170 json_object_array_add(json_paths, json_path);
7171 }
7172 else
7173 vty_out (vty, "%s", VTY_NEWLINE);
7174 }
7175
7176 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7177 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7178 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7179
7180 enum bgp_show_type
7181 {
7182 bgp_show_type_normal,
7183 bgp_show_type_regexp,
7184 bgp_show_type_prefix_list,
7185 bgp_show_type_filter_list,
7186 bgp_show_type_route_map,
7187 bgp_show_type_neighbor,
7188 bgp_show_type_cidr_only,
7189 bgp_show_type_prefix_longer,
7190 bgp_show_type_community_all,
7191 bgp_show_type_community,
7192 bgp_show_type_community_exact,
7193 bgp_show_type_community_list,
7194 bgp_show_type_community_list_exact,
7195 bgp_show_type_flap_statistics,
7196 bgp_show_type_flap_address,
7197 bgp_show_type_flap_prefix,
7198 bgp_show_type_flap_cidr_only,
7199 bgp_show_type_flap_regexp,
7200 bgp_show_type_flap_filter_list,
7201 bgp_show_type_flap_prefix_list,
7202 bgp_show_type_flap_prefix_longer,
7203 bgp_show_type_flap_route_map,
7204 bgp_show_type_flap_neighbor,
7205 bgp_show_type_dampend_paths,
7206 bgp_show_type_damp_neighbor
7207 };
7208
7209 static int
7210 bgp_show_prefix_list (struct vty *vty, const char *name,
7211 const char *prefix_list_str, afi_t afi,
7212 safi_t safi, enum bgp_show_type type);
7213 static int
7214 bgp_show_filter_list (struct vty *vty, const char *name,
7215 const char *filter, afi_t afi,
7216 safi_t safi, enum bgp_show_type type);
7217 static int
7218 bgp_show_route_map (struct vty *vty, const char *name,
7219 const char *rmap_str, afi_t afi,
7220 safi_t safi, enum bgp_show_type type);
7221 static int
7222 bgp_show_community_list (struct vty *vty, const char *name,
7223 const char *com, int exact,
7224 afi_t afi, safi_t safi);
7225 static int
7226 bgp_show_prefix_longer (struct vty *vty, const char *name,
7227 const char *prefix, afi_t afi,
7228 safi_t safi, enum bgp_show_type type);
7229
7230 static int
7231 bgp_show_table (struct vty *vty, struct bgp_table *table,
7232 struct in_addr *router_id, enum bgp_show_type type,
7233 void *output_arg, u_char use_json, json_object *json)
7234 {
7235 struct bgp_info *ri;
7236 struct bgp_node *rn;
7237 int header = 1;
7238 int display;
7239 unsigned long output_count;
7240 struct prefix *p;
7241 char buf[BUFSIZ];
7242 char buf2[BUFSIZ];
7243 json_object *json_paths = NULL;
7244 json_object *json_routes = NULL;
7245
7246 if (use_json)
7247 {
7248 if (json == NULL)
7249 json = json_object_new_object();
7250
7251 json_object_int_add(json, "tableVersion", table->version);
7252 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7253 json_routes = json_object_new_object();
7254 }
7255
7256 /* This is first entry point, so reset total line. */
7257 output_count = 0;
7258
7259 /* Start processing of routes. */
7260 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7261 if (rn->info != NULL)
7262 {
7263 display = 0;
7264
7265 if (use_json)
7266 json_paths = json_object_new_array();
7267 else
7268 json_paths = NULL;
7269
7270 for (ri = rn->info; ri; ri = ri->next)
7271 {
7272 if (type == bgp_show_type_flap_statistics
7273 || type == bgp_show_type_flap_address
7274 || type == bgp_show_type_flap_prefix
7275 || type == bgp_show_type_flap_cidr_only
7276 || type == bgp_show_type_flap_regexp
7277 || type == bgp_show_type_flap_filter_list
7278 || type == bgp_show_type_flap_prefix_list
7279 || type == bgp_show_type_flap_prefix_longer
7280 || type == bgp_show_type_flap_route_map
7281 || type == bgp_show_type_flap_neighbor
7282 || type == bgp_show_type_dampend_paths
7283 || type == bgp_show_type_damp_neighbor)
7284 {
7285 if (!(ri->extra && ri->extra->damp_info))
7286 continue;
7287 }
7288 if (type == bgp_show_type_regexp
7289 || type == bgp_show_type_flap_regexp)
7290 {
7291 regex_t *regex = output_arg;
7292
7293 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7294 continue;
7295 }
7296 if (type == bgp_show_type_prefix_list
7297 || type == bgp_show_type_flap_prefix_list)
7298 {
7299 struct prefix_list *plist = output_arg;
7300
7301 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7302 continue;
7303 }
7304 if (type == bgp_show_type_filter_list
7305 || type == bgp_show_type_flap_filter_list)
7306 {
7307 struct as_list *as_list = output_arg;
7308
7309 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7310 continue;
7311 }
7312 if (type == bgp_show_type_route_map
7313 || type == bgp_show_type_flap_route_map)
7314 {
7315 struct route_map *rmap = output_arg;
7316 struct bgp_info binfo;
7317 struct attr dummy_attr;
7318 struct attr_extra dummy_extra;
7319 int ret;
7320
7321 dummy_attr.extra = &dummy_extra;
7322 bgp_attr_dup (&dummy_attr, ri->attr);
7323
7324 binfo.peer = ri->peer;
7325 binfo.attr = &dummy_attr;
7326
7327 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7328 if (ret == RMAP_DENYMATCH)
7329 continue;
7330 }
7331 if (type == bgp_show_type_neighbor
7332 || type == bgp_show_type_flap_neighbor
7333 || type == bgp_show_type_damp_neighbor)
7334 {
7335 union sockunion *su = output_arg;
7336
7337 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7338 continue;
7339 }
7340 if (type == bgp_show_type_cidr_only
7341 || type == bgp_show_type_flap_cidr_only)
7342 {
7343 u_int32_t destination;
7344
7345 destination = ntohl (rn->p.u.prefix4.s_addr);
7346 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7347 continue;
7348 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7349 continue;
7350 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7351 continue;
7352 }
7353 if (type == bgp_show_type_prefix_longer
7354 || type == bgp_show_type_flap_prefix_longer)
7355 {
7356 struct prefix *p = output_arg;
7357
7358 if (! prefix_match (p, &rn->p))
7359 continue;
7360 }
7361 if (type == bgp_show_type_community_all)
7362 {
7363 if (! ri->attr->community)
7364 continue;
7365 }
7366 if (type == bgp_show_type_community)
7367 {
7368 struct community *com = output_arg;
7369
7370 if (! ri->attr->community ||
7371 ! community_match (ri->attr->community, com))
7372 continue;
7373 }
7374 if (type == bgp_show_type_community_exact)
7375 {
7376 struct community *com = output_arg;
7377
7378 if (! ri->attr->community ||
7379 ! community_cmp (ri->attr->community, com))
7380 continue;
7381 }
7382 if (type == bgp_show_type_community_list)
7383 {
7384 struct community_list *list = output_arg;
7385
7386 if (! community_list_match (ri->attr->community, list))
7387 continue;
7388 }
7389 if (type == bgp_show_type_community_list_exact)
7390 {
7391 struct community_list *list = output_arg;
7392
7393 if (! community_list_exact_match (ri->attr->community, list))
7394 continue;
7395 }
7396 if (type == bgp_show_type_flap_address
7397 || type == bgp_show_type_flap_prefix)
7398 {
7399 struct prefix *p = output_arg;
7400
7401 if (! prefix_match (&rn->p, p))
7402 continue;
7403
7404 if (type == bgp_show_type_flap_prefix)
7405 if (p->prefixlen != rn->p.prefixlen)
7406 continue;
7407 }
7408 if (type == bgp_show_type_dampend_paths
7409 || type == bgp_show_type_damp_neighbor)
7410 {
7411 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7412 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7413 continue;
7414 }
7415
7416 if (!use_json && header)
7417 {
7418 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7419 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7420 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7421 if (type == bgp_show_type_dampend_paths
7422 || type == bgp_show_type_damp_neighbor)
7423 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7424 else if (type == bgp_show_type_flap_statistics
7425 || type == bgp_show_type_flap_address
7426 || type == bgp_show_type_flap_prefix
7427 || type == bgp_show_type_flap_cidr_only
7428 || type == bgp_show_type_flap_regexp
7429 || type == bgp_show_type_flap_filter_list
7430 || type == bgp_show_type_flap_prefix_list
7431 || type == bgp_show_type_flap_prefix_longer
7432 || type == bgp_show_type_flap_route_map
7433 || type == bgp_show_type_flap_neighbor)
7434 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7435 else
7436 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7437 header = 0;
7438 }
7439
7440 if (type == bgp_show_type_dampend_paths
7441 || type == bgp_show_type_damp_neighbor)
7442 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7443 else if (type == bgp_show_type_flap_statistics
7444 || type == bgp_show_type_flap_address
7445 || type == bgp_show_type_flap_prefix
7446 || type == bgp_show_type_flap_cidr_only
7447 || type == bgp_show_type_flap_regexp
7448 || type == bgp_show_type_flap_filter_list
7449 || type == bgp_show_type_flap_prefix_list
7450 || type == bgp_show_type_flap_prefix_longer
7451 || type == bgp_show_type_flap_route_map
7452 || type == bgp_show_type_flap_neighbor)
7453 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7454 else
7455 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7456 display++;
7457 }
7458
7459 if (display)
7460 {
7461 output_count++;
7462 if (use_json)
7463 {
7464 p = &rn->p;
7465 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7466 json_object_object_add(json_routes, buf2, json_paths);
7467 }
7468 }
7469 }
7470
7471 if (use_json)
7472 {
7473 json_object_object_add(json, "routes", json_routes);
7474 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7475 json_object_free(json);
7476 }
7477 else
7478 {
7479 /* No route is displayed */
7480 if (output_count == 0)
7481 {
7482 if (type == bgp_show_type_normal)
7483 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7484 }
7485 else
7486 vty_out (vty, "%sTotal number of prefixes %ld%s",
7487 VTY_NEWLINE, output_count, VTY_NEWLINE);
7488 }
7489
7490 return CMD_SUCCESS;
7491 }
7492
7493 static int
7494 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7495 enum bgp_show_type type, void *output_arg, u_char use_json)
7496 {
7497 struct bgp_table *table;
7498
7499 if (bgp == NULL)
7500 {
7501 bgp = bgp_get_default ();
7502 }
7503
7504 if (bgp == NULL)
7505 {
7506 if (!use_json)
7507 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7508 return CMD_WARNING;
7509 }
7510
7511 table = bgp->rib[afi][safi];
7512
7513 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7514 use_json, NULL);
7515 }
7516
7517 static void
7518 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7519 u_char use_json)
7520 {
7521 struct listnode *node, *nnode;
7522 struct bgp *bgp;
7523 struct bgp_table *table;
7524 json_object *json = NULL;
7525 int is_first = 1;
7526
7527 if (use_json)
7528 vty_out (vty, "{%s", VTY_NEWLINE);
7529
7530 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7531 {
7532 if (use_json)
7533 {
7534 if (!(json = json_object_new_object()))
7535 {
7536 zlog_err("Unable to allocate memory for JSON object");
7537 vty_out (vty,
7538 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7539 VTY_NEWLINE);
7540 return;
7541 }
7542 json_object_int_add(json, "vrfId",
7543 (bgp->vrf_id == VRF_UNKNOWN)
7544 ? -1 : bgp->vrf_id);
7545 json_object_string_add(json, "vrfName",
7546 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7547 ? "Default" : bgp->name);
7548 if (! is_first)
7549 vty_out (vty, ",%s", VTY_NEWLINE);
7550 else
7551 is_first = 0;
7552
7553 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7554 ? "Default" : bgp->name);
7555 }
7556 else
7557 {
7558 vty_out (vty, "%sInstance %s:%s",
7559 VTY_NEWLINE,
7560 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7561 ? "Default" : bgp->name,
7562 VTY_NEWLINE);
7563 }
7564 table = bgp->rib[afi][safi];
7565 bgp_show_table (vty, table, &bgp->router_id,
7566 bgp_show_type_normal, NULL, use_json, json);
7567
7568 }
7569
7570 if (use_json)
7571 vty_out (vty, "}%s", VTY_NEWLINE);
7572 }
7573
7574 /* Header of detailed BGP route information */
7575 static void
7576 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7577 struct bgp_node *rn,
7578 struct prefix_rd *prd, afi_t afi, safi_t safi,
7579 json_object *json)
7580 {
7581 struct bgp_info *ri;
7582 struct prefix *p;
7583 struct peer *peer;
7584 struct listnode *node, *nnode;
7585 char buf1[INET6_ADDRSTRLEN];
7586 char buf2[INET6_ADDRSTRLEN];
7587 int count = 0;
7588 int best = 0;
7589 int suppress = 0;
7590 int no_export = 0;
7591 int no_advertise = 0;
7592 int local_as = 0;
7593 int first = 1;
7594 json_object *json_adv_to = NULL;
7595
7596 p = &rn->p;
7597
7598 if (json)
7599 {
7600 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7601 json_object_int_add(json, "prefixlen", p->prefixlen);
7602 }
7603 else
7604 {
7605 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7606 (safi == SAFI_MPLS_VPN ?
7607 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7608 safi == SAFI_MPLS_VPN ? ":" : "",
7609 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7610 p->prefixlen, VTY_NEWLINE);
7611 }
7612
7613 for (ri = rn->info; ri; ri = ri->next)
7614 {
7615 count++;
7616 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7617 {
7618 best = count;
7619 if (ri->extra && ri->extra->suppress)
7620 suppress = 1;
7621 if (ri->attr->community != NULL)
7622 {
7623 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7624 no_advertise = 1;
7625 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7626 no_export = 1;
7627 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7628 local_as = 1;
7629 }
7630 }
7631 }
7632
7633 if (!json)
7634 {
7635 vty_out (vty, "Paths: (%d available", count);
7636 if (best)
7637 {
7638 vty_out (vty, ", best #%d", best);
7639 if (safi == SAFI_UNICAST)
7640 vty_out (vty, ", table Default-IP-Routing-Table");
7641 }
7642 else
7643 vty_out (vty, ", no best path");
7644
7645 if (no_advertise)
7646 vty_out (vty, ", not advertised to any peer");
7647 else if (no_export)
7648 vty_out (vty, ", not advertised to EBGP peer");
7649 else if (local_as)
7650 vty_out (vty, ", not advertised outside local AS");
7651
7652 if (suppress)
7653 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7654 vty_out (vty, ")%s", VTY_NEWLINE);
7655 }
7656
7657 /* If we are not using addpath then we can display Advertised to and that will
7658 * show what peers we advertised the bestpath to. If we are using addpath
7659 * though then we must display Advertised to on a path-by-path basis. */
7660 if (!bgp->addpath_tx_used[afi][safi])
7661 {
7662 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7663 {
7664 if (bgp_adj_out_lookup (peer, rn, 0))
7665 {
7666 if (json && !json_adv_to)
7667 json_adv_to = json_object_new_object();
7668
7669 route_vty_out_advertised_to(vty, peer, &first,
7670 " Advertised to non peer-group peers:\n ",
7671 json_adv_to);
7672 }
7673 }
7674
7675 if (json)
7676 {
7677 if (json_adv_to)
7678 {
7679 json_object_object_add(json, "advertisedTo", json_adv_to);
7680 }
7681 }
7682 else
7683 {
7684 if (first)
7685 vty_out (vty, " Not advertised to any peer");
7686 vty_out (vty, "%s", VTY_NEWLINE);
7687 }
7688 }
7689 }
7690
7691 /* Display specified route of BGP table. */
7692 static int
7693 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7694 struct bgp_table *rib, const char *ip_str,
7695 afi_t afi, safi_t safi, struct prefix_rd *prd,
7696 int prefix_check, enum bgp_path_type pathtype,
7697 u_char use_json)
7698 {
7699 int ret;
7700 int header;
7701 int display = 0;
7702 struct prefix match;
7703 struct bgp_node *rn;
7704 struct bgp_node *rm;
7705 struct bgp_info *ri;
7706 struct bgp_table *table;
7707 json_object *json = NULL;
7708 json_object *json_paths = NULL;
7709
7710 /* Check IP address argument. */
7711 ret = str2prefix (ip_str, &match);
7712 if (! ret)
7713 {
7714 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7715 return CMD_WARNING;
7716 }
7717
7718 match.family = afi2family (afi);
7719
7720 if (use_json)
7721 {
7722 json = json_object_new_object();
7723 json_paths = json_object_new_array();
7724 }
7725
7726 if (safi == SAFI_MPLS_VPN)
7727 {
7728 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7729 {
7730 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7731 continue;
7732
7733 if ((table = rn->info) != NULL)
7734 {
7735 header = 1;
7736
7737 if ((rm = bgp_node_match (table, &match)) != NULL)
7738 {
7739 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7740 {
7741 bgp_unlock_node (rm);
7742 continue;
7743 }
7744
7745 for (ri = rm->info; ri; ri = ri->next)
7746 {
7747 if (header)
7748 {
7749 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7750 AFI_IP, SAFI_MPLS_VPN, json);
7751
7752 header = 0;
7753 }
7754 display++;
7755
7756 if (pathtype == BGP_PATH_ALL ||
7757 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7758 (pathtype == BGP_PATH_MULTIPATH &&
7759 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7760 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
7761 }
7762
7763 bgp_unlock_node (rm);
7764 }
7765 }
7766 }
7767 }
7768 else
7769 {
7770 header = 1;
7771
7772 if ((rn = bgp_node_match (rib, &match)) != NULL)
7773 {
7774 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7775 {
7776 for (ri = rn->info; ri; ri = ri->next)
7777 {
7778 if (header)
7779 {
7780 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
7781 header = 0;
7782 }
7783 display++;
7784
7785 if (pathtype == BGP_PATH_ALL ||
7786 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7787 (pathtype == BGP_PATH_MULTIPATH &&
7788 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7789 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
7790 }
7791 }
7792
7793 bgp_unlock_node (rn);
7794 }
7795 }
7796
7797 if (use_json)
7798 {
7799 if (display)
7800 json_object_object_add(json, "paths", json_paths);
7801
7802 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7803 json_object_free(json);
7804 }
7805 else
7806 {
7807 if (!display)
7808 {
7809 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7810 return CMD_WARNING;
7811 }
7812 }
7813
7814 return CMD_SUCCESS;
7815 }
7816
7817 /* Display specified route of Main RIB */
7818 static int
7819 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7820 afi_t afi, safi_t safi, struct prefix_rd *prd,
7821 int prefix_check, enum bgp_path_type pathtype,
7822 u_char use_json)
7823 {
7824 struct bgp *bgp;
7825
7826 /* BGP structure lookup. */
7827 if (view_name)
7828 {
7829 bgp = bgp_lookup_by_name (view_name);
7830 if (bgp == NULL)
7831 {
7832 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
7833 return CMD_WARNING;
7834 }
7835 }
7836 else
7837 {
7838 bgp = bgp_get_default ();
7839 if (bgp == NULL)
7840 {
7841 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7842 return CMD_WARNING;
7843 }
7844 }
7845
7846 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7847 afi, safi, prd, prefix_check, pathtype,
7848 use_json);
7849 }
7850
7851 /* BGP route print out function. */
7852 DEFUN (show_ip_bgp,
7853 show_ip_bgp_cmd,
7854 "show ip bgp {json}",
7855 SHOW_STR
7856 IP_STR
7857 BGP_STR
7858 "JavaScript Object Notation\n")
7859 {
7860 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7861 }
7862
7863 DEFUN (show_ip_bgp_ipv4,
7864 show_ip_bgp_ipv4_cmd,
7865 "show ip bgp ipv4 (unicast|multicast) {json}",
7866 SHOW_STR
7867 IP_STR
7868 BGP_STR
7869 "Address family\n"
7870 "Address Family modifier\n"
7871 "Address Family modifier\n"
7872 "JavaScript Object Notation\n")
7873 {
7874 u_char uj = use_json(argc, argv);
7875
7876 if (strncmp (argv[0], "m", 1) == 0)
7877 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7878 NULL, uj);
7879
7880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7881 }
7882
7883 ALIAS (show_ip_bgp_ipv4,
7884 show_bgp_ipv4_safi_cmd,
7885 "show bgp ipv4 (unicast|multicast) {json}",
7886 SHOW_STR
7887 BGP_STR
7888 "Address family\n"
7889 "Address Family modifier\n"
7890 "Address Family modifier\n"
7891 "JavaScript Object Notation\n")
7892
7893 DEFUN (show_ip_bgp_route,
7894 show_ip_bgp_route_cmd,
7895 "show ip bgp A.B.C.D {json}",
7896 SHOW_STR
7897 IP_STR
7898 BGP_STR
7899 "Network in the BGP routing table to display\n"
7900 "JavaScript Object Notation\n")
7901 {
7902 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7903 }
7904
7905 DEFUN (show_ip_bgp_route_pathtype,
7906 show_ip_bgp_route_pathtype_cmd,
7907 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
7908 SHOW_STR
7909 IP_STR
7910 BGP_STR
7911 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7912 "Display only the bestpath\n"
7913 "Display only multipaths\n"
7914 "JavaScript Object Notation\n")
7915 {
7916 u_char uj = use_json(argc, argv);
7917
7918 if (strncmp (argv[1], "b", 1) == 0)
7919 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7920 else
7921 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7922 }
7923
7924 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7925 show_bgp_ipv4_safi_route_pathtype_cmd,
7926 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
7927 SHOW_STR
7928 BGP_STR
7929 "Address family\n"
7930 "Address Family modifier\n"
7931 "Address Family modifier\n"
7932 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7933 "Display only the bestpath\n"
7934 "Display only multipaths\n"
7935 "JavaScript Object Notation\n")
7936 {
7937 u_char uj = use_json(argc, argv);
7938
7939 if (strncmp (argv[0], "m", 1) == 0)
7940 if (strncmp (argv[2], "b", 1) == 0)
7941 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7942 else
7943 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7944 else
7945 if (strncmp (argv[2], "b", 1) == 0)
7946 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7947 else
7948 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7949 }
7950
7951 DEFUN (show_ip_bgp_ipv4_route,
7952 show_ip_bgp_ipv4_route_cmd,
7953 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7954 SHOW_STR
7955 IP_STR
7956 BGP_STR
7957 "Address family\n"
7958 "Address Family modifier\n"
7959 "Address Family modifier\n"
7960 "Network in the BGP routing table to display\n"
7961 "JavaScript Object Notation\n")
7962 {
7963 u_char uj = use_json(argc, argv);
7964
7965 if (strncmp (argv[0], "m", 1) == 0)
7966 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
7967
7968 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
7969 }
7970
7971 ALIAS (show_ip_bgp_ipv4_route,
7972 show_bgp_ipv4_safi_route_cmd,
7973 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7974 SHOW_STR
7975 BGP_STR
7976 "Address family\n"
7977 "Address Family modifier\n"
7978 "Address Family modifier\n"
7979 "Network in the BGP routing table to display\n"
7980 "JavaScript Object Notation\n")
7981
7982 DEFUN (show_ip_bgp_vpnv4_all_route,
7983 show_ip_bgp_vpnv4_all_route_cmd,
7984 "show ip bgp vpnv4 all A.B.C.D {json}",
7985 SHOW_STR
7986 IP_STR
7987 BGP_STR
7988 "Display VPNv4 NLRI specific information\n"
7989 "Display information about all VPNv4 NLRIs\n"
7990 "Network in the BGP routing table to display\n"
7991 "JavaScript Object Notation\n")
7992 {
7993 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7994 }
7995
7996
7997 DEFUN (show_ip_bgp_vpnv4_rd_route,
7998 show_ip_bgp_vpnv4_rd_route_cmd,
7999 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8000 SHOW_STR
8001 IP_STR
8002 BGP_STR
8003 "Display VPNv4 NLRI specific information\n"
8004 "Display information for a route distinguisher\n"
8005 "VPN Route Distinguisher\n"
8006 "Network in the BGP routing table to display\n"
8007 "JavaScript Object Notation\n")
8008 {
8009 int ret;
8010 struct prefix_rd prd;
8011 u_char uj= use_json(argc, argv);
8012
8013 ret = str2prefix_rd (argv[0], &prd);
8014 if (! ret)
8015 {
8016 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8017 return CMD_WARNING;
8018 }
8019 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
8020 }
8021
8022 DEFUN (show_ip_bgp_prefix,
8023 show_ip_bgp_prefix_cmd,
8024 "show ip bgp A.B.C.D/M {json}",
8025 SHOW_STR
8026 IP_STR
8027 BGP_STR
8028 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8029 "JavaScript Object Notation\n")
8030 {
8031 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8032 }
8033
8034 DEFUN (show_ip_bgp_prefix_pathtype,
8035 show_ip_bgp_prefix_pathtype_cmd,
8036 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8037 SHOW_STR
8038 IP_STR
8039 BGP_STR
8040 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8041 "Display only the bestpath\n"
8042 "Display only multipaths\n"
8043 "JavaScript Object Notation\n")
8044 {
8045 u_char uj = use_json(argc, argv);
8046 if (strncmp (argv[1], "b", 1) == 0)
8047 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8048 else
8049 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8050 }
8051
8052 DEFUN (show_ip_bgp_ipv4_prefix,
8053 show_ip_bgp_ipv4_prefix_cmd,
8054 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8055 SHOW_STR
8056 IP_STR
8057 BGP_STR
8058 "Address family\n"
8059 "Address Family modifier\n"
8060 "Address Family modifier\n"
8061 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8062 "JavaScript Object Notation\n")
8063 {
8064 u_char uj = use_json(argc, argv);
8065
8066 if (strncmp (argv[0], "m", 1) == 0)
8067 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8068
8069 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8070 }
8071
8072 ALIAS (show_ip_bgp_ipv4_prefix,
8073 show_bgp_ipv4_safi_prefix_cmd,
8074 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8075 SHOW_STR
8076 BGP_STR
8077 "Address family\n"
8078 "Address Family modifier\n"
8079 "Address Family modifier\n"
8080 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8081 "JavaScript Object Notation\n")
8082
8083 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8084 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8085 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8086 SHOW_STR
8087 IP_STR
8088 BGP_STR
8089 "Address family\n"
8090 "Address Family modifier\n"
8091 "Address Family modifier\n"
8092 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8093 "Display only the bestpath\n"
8094 "Display only multipaths\n"
8095 "JavaScript Object Notation\n")
8096 {
8097 u_char uj = use_json(argc, argv);
8098
8099 if (strncmp (argv[0], "m", 1) == 0)
8100 if (strncmp (argv[2], "b", 1) == 0)
8101 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8102 else
8103 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8104 else
8105 if (strncmp (argv[2], "b", 1) == 0)
8106 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8107 else
8108 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8109 }
8110
8111 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8112 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8113 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8114 SHOW_STR
8115 BGP_STR
8116 "Address family\n"
8117 "Address Family modifier\n"
8118 "Address Family modifier\n"
8119 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8120 "Display only the bestpath\n"
8121 "Display only multipaths\n"
8122 "JavaScript Object Notation\n")
8123
8124 DEFUN (show_ip_bgp_vpnv4_all_prefix,
8125 show_ip_bgp_vpnv4_all_prefix_cmd,
8126 "show ip bgp vpnv4 all A.B.C.D/M {json}",
8127 SHOW_STR
8128 IP_STR
8129 BGP_STR
8130 "Display VPNv4 NLRI specific information\n"
8131 "Display information about all VPNv4 NLRIs\n"
8132 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8133 "JavaScript Object Notation\n")
8134 {
8135 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8136 }
8137
8138 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8139 show_ip_bgp_vpnv4_rd_prefix_cmd,
8140 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8141 SHOW_STR
8142 IP_STR
8143 BGP_STR
8144 "Display VPNv4 NLRI specific information\n"
8145 "Display information for a route distinguisher\n"
8146 "VPN Route Distinguisher\n"
8147 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8148 "JavaScript Object Notation\n")
8149 {
8150 int ret;
8151 struct prefix_rd prd;
8152
8153 ret = str2prefix_rd (argv[0], &prd);
8154 if (! ret)
8155 {
8156 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8157 return CMD_WARNING;
8158 }
8159 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
8160 }
8161
8162 DEFUN (show_ip_bgp_view,
8163 show_ip_bgp_instance_cmd,
8164 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8165 SHOW_STR
8166 IP_STR
8167 BGP_STR
8168 BGP_INSTANCE_HELP_STR
8169 "JavaScript Object Notation\n")
8170 {
8171 struct bgp *bgp;
8172
8173 /* BGP structure lookup. */
8174 bgp = bgp_lookup_by_name (argv[1]);
8175 if (bgp == NULL)
8176 {
8177 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8178 return CMD_WARNING;
8179 }
8180
8181 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8182 }
8183
8184 DEFUN (show_ip_bgp_instance_all,
8185 show_ip_bgp_instance_all_cmd,
8186 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8187 SHOW_STR
8188 IP_STR
8189 BGP_STR
8190 BGP_INSTANCE_ALL_HELP_STR
8191 "JavaScript Object Notation\n")
8192 {
8193 u_char uj = use_json(argc, argv);
8194
8195 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8196 return CMD_SUCCESS;
8197 }
8198
8199 DEFUN (show_ip_bgp_instance_route,
8200 show_ip_bgp_instance_route_cmd,
8201 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8202 SHOW_STR
8203 IP_STR
8204 BGP_STR
8205 BGP_INSTANCE_HELP_STR
8206 "Network in the BGP routing table to display\n"
8207 "JavaScript Object Notation\n")
8208 {
8209 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8210 }
8211
8212 DEFUN (show_ip_bgp_instance_route_pathtype,
8213 show_ip_bgp_instance_route_pathtype_cmd,
8214 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8215 SHOW_STR
8216 IP_STR
8217 BGP_STR
8218 BGP_INSTANCE_HELP_STR
8219 "Network in the BGP routing table to display\n"
8220 "Display only the bestpath\n"
8221 "Display only multipaths\n"
8222 "JavaScript Object Notation\n")
8223 {
8224 u_char uj = use_json(argc, argv);
8225
8226 if (strncmp (argv[3], "b", 1) == 0)
8227 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8228 else
8229 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8230 }
8231
8232 DEFUN (show_ip_bgp_instance_prefix,
8233 show_ip_bgp_instance_prefix_cmd,
8234 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8235 SHOW_STR
8236 IP_STR
8237 BGP_STR
8238 BGP_INSTANCE_HELP_STR
8239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8240 "JavaScript Object Notation\n")
8241 {
8242 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8243 }
8244
8245 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8246 show_ip_bgp_instance_prefix_pathtype_cmd,
8247 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8248 SHOW_STR
8249 IP_STR
8250 BGP_STR
8251 BGP_INSTANCE_HELP_STR
8252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8253 "Display only the bestpath\n"
8254 "Display only multipaths\n"
8255 "JavaScript Object Notation\n")
8256 {
8257 u_char uj = use_json(argc, argv);
8258 if (strncmp (argv[3], "b", 1) == 0)
8259 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8260 else
8261 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8262 }
8263
8264 #ifdef HAVE_IPV6
8265 DEFUN (show_bgp,
8266 show_bgp_cmd,
8267 "show bgp {json}",
8268 SHOW_STR
8269 BGP_STR
8270 "JavaScript Object Notation\n")
8271 {
8272 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8273 NULL, use_json(argc, argv));
8274 }
8275
8276 ALIAS (show_bgp,
8277 show_bgp_ipv6_cmd,
8278 "show bgp ipv6 {json}",
8279 SHOW_STR
8280 BGP_STR
8281 "Address family\n"
8282 "JavaScript Object Notation\n")
8283
8284 DEFUN (show_bgp_ipv6_safi,
8285 show_bgp_ipv6_safi_cmd,
8286 "show bgp ipv6 (unicast|multicast) {json}",
8287 SHOW_STR
8288 BGP_STR
8289 "Address family\n"
8290 "Address Family modifier\n"
8291 "Address Family modifier\n"
8292 "JavaScript Object Notation\n")
8293 {
8294 u_char uj = use_json(argc, argv);
8295 if (strncmp (argv[0], "m", 1) == 0)
8296 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8297 NULL, uj);
8298
8299 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8300 }
8301
8302 static void
8303 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8304 {
8305 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8306 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8307 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8308 }
8309
8310 /* old command */
8311 DEFUN (show_ipv6_bgp,
8312 show_ipv6_bgp_cmd,
8313 "show ipv6 bgp {json}",
8314 SHOW_STR
8315 IP_STR
8316 BGP_STR
8317 "JavaScript Object Notation\n")
8318 {
8319 bgp_show_ipv6_bgp_deprecate_warning(vty);
8320 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8321 NULL, use_json(argc, argv));
8322 }
8323
8324 DEFUN (show_bgp_route,
8325 show_bgp_route_cmd,
8326 "show bgp X:X::X:X {json}",
8327 SHOW_STR
8328 BGP_STR
8329 "Network in the BGP routing table to display\n"
8330 "JavaScript Object Notation\n")
8331 {
8332 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8333 }
8334
8335 ALIAS (show_bgp_route,
8336 show_bgp_ipv6_route_cmd,
8337 "show bgp ipv6 X:X::X:X {json}",
8338 SHOW_STR
8339 BGP_STR
8340 "Address family\n"
8341 "Network in the BGP routing table to display\n"
8342 "JavaScript Object Notation\n")
8343
8344 DEFUN (show_bgp_ipv6_safi_route,
8345 show_bgp_ipv6_safi_route_cmd,
8346 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8347 SHOW_STR
8348 BGP_STR
8349 "Address family\n"
8350 "Address Family modifier\n"
8351 "Address Family modifier\n"
8352 "Network in the BGP routing table to display\n"
8353 "JavaScript Object Notation\n")
8354 {
8355 u_char uj = use_json(argc, argv);
8356 if (strncmp (argv[0], "m", 1) == 0)
8357 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8358
8359 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8360 }
8361
8362 DEFUN (show_bgp_route_pathtype,
8363 show_bgp_route_pathtype_cmd,
8364 "show bgp X:X::X:X (bestpath|multipath) {json}",
8365 SHOW_STR
8366 BGP_STR
8367 "Network in the BGP routing table to display\n"
8368 "Display only the bestpath\n"
8369 "Display only multipaths\n"
8370 "JavaScript Object Notation\n")
8371 {
8372 u_char uj = use_json(argc, argv);
8373 if (strncmp (argv[1], "b", 1) == 0)
8374 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8375 else
8376 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8377 }
8378
8379 ALIAS (show_bgp_route_pathtype,
8380 show_bgp_ipv6_route_pathtype_cmd,
8381 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8382 SHOW_STR
8383 BGP_STR
8384 "Address family\n"
8385 "Network in the BGP routing table to display\n"
8386 "Display only the bestpath\n"
8387 "Display only multipaths\n"
8388 "JavaScript Object Notation\n")
8389
8390 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8391 show_bgp_ipv6_safi_route_pathtype_cmd,
8392 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8393 SHOW_STR
8394 BGP_STR
8395 "Address family\n"
8396 "Address Family modifier\n"
8397 "Address Family modifier\n"
8398 "Network in the BGP routing table to display\n"
8399 "Display only the bestpath\n"
8400 "Display only multipaths\n"
8401 "JavaScript Object Notation\n")
8402 {
8403 u_char uj = use_json(argc, argv);
8404 if (strncmp (argv[0], "m", 1) == 0)
8405 if (strncmp (argv[2], "b", 1) == 0)
8406 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8407 else
8408 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8409 else
8410 if (strncmp (argv[2], "b", 1) == 0)
8411 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8412 else
8413 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8414 }
8415
8416 /* old command */
8417 DEFUN (show_ipv6_bgp_route,
8418 show_ipv6_bgp_route_cmd,
8419 "show ipv6 bgp X:X::X:X {json}",
8420 SHOW_STR
8421 IP_STR
8422 BGP_STR
8423 "Network in the BGP routing table to display\n"
8424 "JavaScript Object Notation\n")
8425 {
8426 bgp_show_ipv6_bgp_deprecate_warning(vty);
8427 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8428 }
8429
8430 DEFUN (show_bgp_prefix,
8431 show_bgp_prefix_cmd,
8432 "show bgp X:X::X:X/M {json}",
8433 SHOW_STR
8434 BGP_STR
8435 "IPv6 prefix <network>/<length>\n"
8436 "JavaScript Object Notation\n")
8437 {
8438 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8439 }
8440
8441 ALIAS (show_bgp_prefix,
8442 show_bgp_ipv6_prefix_cmd,
8443 "show bgp ipv6 X:X::X:X/M {json}",
8444 SHOW_STR
8445 BGP_STR
8446 "Address family\n"
8447 "IPv6 prefix <network>/<length>\n"
8448 "JavaScript Object Notation\n")
8449
8450 DEFUN (show_bgp_ipv6_safi_prefix,
8451 show_bgp_ipv6_safi_prefix_cmd,
8452 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8453 SHOW_STR
8454 BGP_STR
8455 "Address family\n"
8456 "Address Family modifier\n"
8457 "Address Family modifier\n"
8458 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8459 "JavaScript Object Notation\n")
8460 {
8461 u_char uj = use_json(argc, argv);
8462 if (strncmp (argv[0], "m", 1) == 0)
8463 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8464
8465 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8466 }
8467
8468 DEFUN (show_bgp_prefix_pathtype,
8469 show_bgp_prefix_pathtype_cmd,
8470 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8471 SHOW_STR
8472 BGP_STR
8473 "IPv6 prefix <network>/<length>\n"
8474 "Display only the bestpath\n"
8475 "Display only multipaths\n"
8476 "JavaScript Object Notation\n")
8477 {
8478 u_char uj = use_json(argc, argv);
8479 if (strncmp (argv[1], "b", 1) == 0)
8480 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8481 else
8482 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8483 }
8484
8485 ALIAS (show_bgp_prefix_pathtype,
8486 show_bgp_ipv6_prefix_pathtype_cmd,
8487 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8488 SHOW_STR
8489 BGP_STR
8490 "Address family\n"
8491 "IPv6 prefix <network>/<length>\n"
8492 "Display only the bestpath\n"
8493 "Display only multipaths\n"
8494 "JavaScript Object Notation\n")
8495
8496 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8497 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8498 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8499 SHOW_STR
8500 BGP_STR
8501 "Address family\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
8504 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8505 "Display only the bestpath\n"
8506 "Display only multipaths\n"
8507 "JavaScript Object Notation\n")
8508 {
8509 u_char uj = use_json(argc, argv);
8510 if (strncmp (argv[0], "m", 1) == 0)
8511 if (strncmp (argv[2], "b", 1) == 0)
8512 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8513 else
8514 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8515 else
8516 if (strncmp (argv[2], "b", 1) == 0)
8517 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8518 else
8519 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8520 }
8521
8522 /* old command */
8523 DEFUN (show_ipv6_bgp_prefix,
8524 show_ipv6_bgp_prefix_cmd,
8525 "show ipv6 bgp X:X::X:X/M {json}",
8526 SHOW_STR
8527 IP_STR
8528 BGP_STR
8529 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8530 "JavaScript Object Notation\n")
8531 {
8532 bgp_show_ipv6_bgp_deprecate_warning(vty);
8533 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8534 }
8535
8536 DEFUN (show_bgp_view,
8537 show_bgp_instance_cmd,
8538 "show bgp " BGP_INSTANCE_CMD " {json}",
8539 SHOW_STR
8540 BGP_STR
8541 BGP_INSTANCE_HELP_STR
8542 "JavaScript Object Notation\n")
8543 {
8544 struct bgp *bgp;
8545
8546 /* BGP structure lookup. */
8547 bgp = bgp_lookup_by_name (argv[1]);
8548 if (bgp == NULL)
8549 {
8550 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8551 return CMD_WARNING;
8552 }
8553
8554 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8555 }
8556
8557 DEFUN (show_bgp_instance_all,
8558 show_bgp_instance_all_cmd,
8559 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8560 SHOW_STR
8561 BGP_STR
8562 BGP_INSTANCE_ALL_HELP_STR
8563 "JavaScript Object Notation\n")
8564 {
8565 u_char uj = use_json(argc, argv);
8566
8567 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8568 return CMD_SUCCESS;
8569 }
8570
8571 ALIAS (show_bgp_view,
8572 show_bgp_instance_ipv6_cmd,
8573 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8574 SHOW_STR
8575 BGP_STR
8576 BGP_INSTANCE_HELP_STR
8577 "Address family\n"
8578 "JavaScript Object Notation\n")
8579
8580 DEFUN (show_bgp_instance_route,
8581 show_bgp_instance_route_cmd,
8582 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8583 SHOW_STR
8584 BGP_STR
8585 BGP_INSTANCE_HELP_STR
8586 "Network in the BGP routing table to display\n"
8587 "JavaScript Object Notation\n")
8588 {
8589 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8590 }
8591
8592 ALIAS (show_bgp_instance_route,
8593 show_bgp_instance_ipv6_route_cmd,
8594 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8595 SHOW_STR
8596 BGP_STR
8597 BGP_INSTANCE_HELP_STR
8598 "Address family\n"
8599 "Network in the BGP routing table to display\n"
8600 "JavaScript Object Notation\n")
8601
8602 DEFUN (show_bgp_instance_route_pathtype,
8603 show_bgp_instance_route_pathtype_cmd,
8604 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8605 SHOW_STR
8606 BGP_STR
8607 BGP_INSTANCE_HELP_STR
8608 "Network in the BGP routing table to display\n"
8609 "Display only the bestpath\n"
8610 "Display only multipaths\n"
8611 "JavaScript Object Notation\n")
8612 {
8613 u_char uj = use_json(argc, argv);
8614 if (strncmp (argv[3], "b", 1) == 0)
8615 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8616 else
8617 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8618 }
8619
8620 ALIAS (show_bgp_instance_route_pathtype,
8621 show_bgp_instance_ipv6_route_pathtype_cmd,
8622 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8623 SHOW_STR
8624 BGP_STR
8625 BGP_INSTANCE_HELP_STR
8626 "Address family\n"
8627 "Network in the BGP routing table to display\n"
8628 "Display only the bestpath\n"
8629 "Display only multipaths\n"
8630 "JavaScript Object Notation\n")
8631
8632 DEFUN (show_bgp_instance_prefix,
8633 show_bgp_instance_prefix_cmd,
8634 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8635 SHOW_STR
8636 BGP_STR
8637 BGP_INSTANCE_HELP_STR
8638 "IPv6 prefix <network>/<length>\n"
8639 "JavaScript Object Notation\n")
8640 {
8641 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8642 }
8643
8644 ALIAS (show_bgp_instance_prefix,
8645 show_bgp_instance_ipv6_prefix_cmd,
8646 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
8647 SHOW_STR
8648 BGP_STR
8649 BGP_INSTANCE_HELP_STR
8650 "Address family\n"
8651 "IPv6 prefix <network>/<length>\n"
8652 "JavaScript Object Notation\n")
8653
8654 DEFUN (show_bgp_instance_prefix_pathtype,
8655 show_bgp_instance_prefix_pathtype_cmd,
8656 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
8657 SHOW_STR
8658 BGP_STR
8659 BGP_INSTANCE_HELP_STR
8660 "IPv6 prefix <network>/<length>\n"
8661 "Display only the bestpath\n"
8662 "Display only multipaths\n"
8663 "JavaScript Object Notation\n")
8664 {
8665 u_char uj = use_json(argc, argv);
8666 if (strncmp (argv[3], "b", 1) == 0)
8667 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8668 else
8669 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8670 }
8671
8672 ALIAS (show_bgp_instance_prefix_pathtype,
8673 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8674 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8675 SHOW_STR
8676 BGP_STR
8677 BGP_INSTANCE_HELP_STR
8678 "Address family\n"
8679 "IPv6 prefix <network>/<length>\n"
8680 "Display only the bestpath\n"
8681 "Display only multipaths\n"
8682 "JavaScript Object Notation\n")
8683
8684 DEFUN (show_bgp_instance_prefix_list,
8685 show_bgp_instance_prefix_list_cmd,
8686 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8687 SHOW_STR
8688 BGP_STR
8689 BGP_INSTANCE_HELP_STR
8690 "Display routes conforming to the prefix-list\n"
8691 "IPv6 prefix-list name\n")
8692 {
8693 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8694 bgp_show_type_prefix_list);
8695 }
8696
8697 ALIAS (show_bgp_instance_prefix_list,
8698 show_bgp_instance_ipv6_prefix_list_cmd,
8699 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
8700 SHOW_STR
8701 BGP_STR
8702 BGP_INSTANCE_HELP_STR
8703 "Address family\n"
8704 "Display routes conforming to the prefix-list\n"
8705 "IPv6 prefix-list name\n")
8706
8707 DEFUN (show_bgp_instance_filter_list,
8708 show_bgp_instance_filter_list_cmd,
8709 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
8710 SHOW_STR
8711 BGP_STR
8712 BGP_INSTANCE_HELP_STR
8713 "Display routes conforming to the filter-list\n"
8714 "Regular expression access list name\n")
8715 {
8716 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8717 bgp_show_type_filter_list);
8718 }
8719
8720 ALIAS (show_bgp_instance_filter_list,
8721 show_bgp_instance_ipv6_filter_list_cmd,
8722 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
8723 SHOW_STR
8724 BGP_STR
8725 BGP_INSTANCE_HELP_STR
8726 "Address family\n"
8727 "Display routes conforming to the filter-list\n"
8728 "Regular expression access list name\n")
8729
8730 DEFUN (show_bgp_instance_route_map,
8731 show_bgp_instance_route_map_cmd,
8732 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
8733 SHOW_STR
8734 BGP_STR
8735 BGP_INSTANCE_HELP_STR
8736 "Display routes matching the route-map\n"
8737 "A route-map to match on\n")
8738 {
8739 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8740 bgp_show_type_route_map);
8741 }
8742
8743 ALIAS (show_bgp_instance_route_map,
8744 show_bgp_instance_ipv6_route_map_cmd,
8745 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
8746 SHOW_STR
8747 BGP_STR
8748 BGP_INSTANCE_HELP_STR
8749 "Address family\n"
8750 "Display routes matching the route-map\n"
8751 "A route-map to match on\n")
8752
8753 DEFUN (show_bgp_instance_community_list,
8754 show_bgp_instance_community_list_cmd,
8755 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
8756 SHOW_STR
8757 BGP_STR
8758 BGP_INSTANCE_HELP_STR
8759 "Display routes matching the community-list\n"
8760 "community-list number\n"
8761 "community-list name\n")
8762 {
8763 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8764 }
8765
8766 ALIAS (show_bgp_instance_community_list,
8767 show_bgp_instance_ipv6_community_list_cmd,
8768 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
8769 SHOW_STR
8770 BGP_STR
8771 BGP_INSTANCE_HELP_STR
8772 "Address family\n"
8773 "Display routes matching the community-list\n"
8774 "community-list number\n"
8775 "community-list name\n")
8776
8777 DEFUN (show_bgp_instance_prefix_longer,
8778 show_bgp_instance_prefix_longer_cmd,
8779 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
8780 SHOW_STR
8781 BGP_STR
8782 BGP_INSTANCE_HELP_STR
8783 "IPv6 prefix <network>/<length>\n"
8784 "Display route and more specific routes\n")
8785 {
8786 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8787 bgp_show_type_prefix_longer);
8788 }
8789
8790 ALIAS (show_bgp_instance_prefix_longer,
8791 show_bgp_instance_ipv6_prefix_longer_cmd,
8792 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
8793 SHOW_STR
8794 BGP_STR
8795 BGP_INSTANCE_HELP_STR
8796 "Address family\n"
8797 "IPv6 prefix <network>/<length>\n"
8798 "Display route and more specific routes\n")
8799
8800 /* old command */
8801 DEFUN (show_ipv6_mbgp,
8802 show_ipv6_mbgp_cmd,
8803 "show ipv6 mbgp {json}",
8804 SHOW_STR
8805 IP_STR
8806 MBGP_STR
8807 "JavaScript Object Notation\n")
8808 {
8809 bgp_show_ipv6_bgp_deprecate_warning(vty);
8810 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8811 NULL, use_json(argc, argv));
8812 }
8813
8814 /* old command */
8815 DEFUN (show_ipv6_mbgp_route,
8816 show_ipv6_mbgp_route_cmd,
8817 "show ipv6 mbgp X:X::X:X {json}",
8818 SHOW_STR
8819 IP_STR
8820 MBGP_STR
8821 "Network in the MBGP routing table to display\n"
8822 "JavaScript Object Notation\n")
8823 {
8824 bgp_show_ipv6_bgp_deprecate_warning(vty);
8825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8826 }
8827
8828 /* old command */
8829 DEFUN (show_ipv6_mbgp_prefix,
8830 show_ipv6_mbgp_prefix_cmd,
8831 "show ipv6 mbgp X:X::X:X/M {json}",
8832 SHOW_STR
8833 IP_STR
8834 MBGP_STR
8835 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8836 "JavaScript Object Notation\n")
8837 {
8838 bgp_show_ipv6_bgp_deprecate_warning(vty);
8839 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8840 }
8841 #endif
8842
8843
8844 static int
8845 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8846 safi_t safi, enum bgp_show_type type)
8847 {
8848 int i;
8849 struct buffer *b;
8850 char *regstr;
8851 int first;
8852 regex_t *regex;
8853 int rc;
8854
8855 first = 0;
8856 b = buffer_new (1024);
8857 for (i = 0; i < argc; i++)
8858 {
8859 if (first)
8860 buffer_putc (b, ' ');
8861 else
8862 {
8863 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8864 continue;
8865 first = 1;
8866 }
8867
8868 buffer_putstr (b, argv[i]);
8869 }
8870 buffer_putc (b, '\0');
8871
8872 regstr = buffer_getstr (b);
8873 buffer_free (b);
8874
8875 regex = bgp_regcomp (regstr);
8876 XFREE(MTYPE_TMP, regstr);
8877 if (! regex)
8878 {
8879 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8880 VTY_NEWLINE);
8881 return CMD_WARNING;
8882 }
8883
8884 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
8885 bgp_regex_free (regex);
8886 return rc;
8887 }
8888
8889 DEFUN (show_ip_bgp_regexp,
8890 show_ip_bgp_regexp_cmd,
8891 "show ip bgp regexp .LINE",
8892 SHOW_STR
8893 IP_STR
8894 BGP_STR
8895 "Display routes matching the AS path regular expression\n"
8896 "A regular-expression to match the BGP AS paths\n")
8897 {
8898 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8899 bgp_show_type_regexp);
8900 }
8901
8902 DEFUN (show_ip_bgp_flap_regexp,
8903 show_ip_bgp_flap_regexp_cmd,
8904 "show ip bgp flap-statistics regexp .LINE",
8905 SHOW_STR
8906 IP_STR
8907 BGP_STR
8908 "Display flap statistics of routes\n"
8909 "Display routes matching the AS path regular expression\n"
8910 "A regular-expression to match the BGP AS paths\n")
8911 {
8912 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8913 bgp_show_type_flap_regexp);
8914 }
8915
8916 ALIAS (show_ip_bgp_flap_regexp,
8917 show_ip_bgp_damp_flap_regexp_cmd,
8918 "show ip bgp dampening flap-statistics regexp .LINE",
8919 SHOW_STR
8920 IP_STR
8921 BGP_STR
8922 "Display detailed information about dampening\n"
8923 "Display flap statistics of routes\n"
8924 "Display routes matching the AS path regular expression\n"
8925 "A regular-expression to match the BGP AS paths\n")
8926
8927 DEFUN (show_ip_bgp_ipv4_regexp,
8928 show_ip_bgp_ipv4_regexp_cmd,
8929 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8930 SHOW_STR
8931 IP_STR
8932 BGP_STR
8933 "Address family\n"
8934 "Address Family modifier\n"
8935 "Address Family modifier\n"
8936 "Display routes matching the AS path regular expression\n"
8937 "A regular-expression to match the BGP AS paths\n")
8938 {
8939 if (strncmp (argv[0], "m", 1) == 0)
8940 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8941 bgp_show_type_regexp);
8942
8943 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8944 bgp_show_type_regexp);
8945 }
8946
8947 #ifdef HAVE_IPV6
8948 DEFUN (show_bgp_regexp,
8949 show_bgp_regexp_cmd,
8950 "show bgp regexp .LINE",
8951 SHOW_STR
8952 BGP_STR
8953 "Display routes matching the AS path regular expression\n"
8954 "A regular-expression to match the BGP AS paths\n")
8955 {
8956 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8957 bgp_show_type_regexp);
8958 }
8959
8960 ALIAS (show_bgp_regexp,
8961 show_bgp_ipv6_regexp_cmd,
8962 "show bgp ipv6 regexp .LINE",
8963 SHOW_STR
8964 BGP_STR
8965 "Address family\n"
8966 "Display routes matching the AS path regular expression\n"
8967 "A regular-expression to match the BGP AS paths\n")
8968
8969 /* old command */
8970 DEFUN (show_ipv6_bgp_regexp,
8971 show_ipv6_bgp_regexp_cmd,
8972 "show ipv6 bgp regexp .LINE",
8973 SHOW_STR
8974 IP_STR
8975 BGP_STR
8976 "Display routes matching the AS path regular expression\n"
8977 "A regular-expression to match the BGP AS paths\n")
8978 {
8979 bgp_show_ipv6_bgp_deprecate_warning(vty);
8980 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8981 bgp_show_type_regexp);
8982 }
8983
8984 /* old command */
8985 DEFUN (show_ipv6_mbgp_regexp,
8986 show_ipv6_mbgp_regexp_cmd,
8987 "show ipv6 mbgp regexp .LINE",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Display routes matching the AS path regular expression\n"
8992 "A regular-expression to match the MBGP AS paths\n")
8993 {
8994 bgp_show_ipv6_bgp_deprecate_warning(vty);
8995 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8996 bgp_show_type_regexp);
8997 }
8998 #endif /* HAVE_IPV6 */
8999
9000 static int
9001 bgp_show_prefix_list (struct vty *vty, const char *name,
9002 const char *prefix_list_str, afi_t afi,
9003 safi_t safi, enum bgp_show_type type)
9004 {
9005 struct prefix_list *plist;
9006 struct bgp *bgp = NULL;
9007
9008 if (name && !(bgp = bgp_lookup_by_name(name)))
9009 {
9010 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9011 return CMD_WARNING;
9012 }
9013
9014 plist = prefix_list_lookup (afi, prefix_list_str);
9015 if (plist == NULL)
9016 {
9017 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9018 prefix_list_str, VTY_NEWLINE);
9019 return CMD_WARNING;
9020 }
9021
9022 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9023 }
9024
9025 DEFUN (show_ip_bgp_prefix_list,
9026 show_ip_bgp_prefix_list_cmd,
9027 "show ip bgp prefix-list WORD",
9028 SHOW_STR
9029 IP_STR
9030 BGP_STR
9031 "Display routes conforming to the prefix-list\n"
9032 "IP prefix-list name\n")
9033 {
9034 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9035 bgp_show_type_prefix_list);
9036 }
9037
9038 DEFUN (show_ip_bgp_instance_prefix_list,
9039 show_ip_bgp_instance_prefix_list_cmd,
9040 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9041 SHOW_STR
9042 IP_STR
9043 BGP_STR
9044 BGP_INSTANCE_HELP_STR
9045 "Display routes conforming to the prefix-list\n"
9046 "IP prefix-list name\n")
9047 {
9048 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9049 bgp_show_type_prefix_list);
9050 }
9051
9052 DEFUN (show_ip_bgp_flap_prefix_list,
9053 show_ip_bgp_flap_prefix_list_cmd,
9054 "show ip bgp flap-statistics prefix-list WORD",
9055 SHOW_STR
9056 IP_STR
9057 BGP_STR
9058 "Display flap statistics of routes\n"
9059 "Display routes conforming to the prefix-list\n"
9060 "IP prefix-list name\n")
9061 {
9062 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9063 bgp_show_type_flap_prefix_list);
9064 }
9065
9066 ALIAS (show_ip_bgp_flap_prefix_list,
9067 show_ip_bgp_damp_flap_prefix_list_cmd,
9068 "show ip bgp dampening flap-statistics prefix-list WORD",
9069 SHOW_STR
9070 IP_STR
9071 BGP_STR
9072 "Display detailed information about dampening\n"
9073 "Display flap statistics of routes\n"
9074 "Display routes conforming to the prefix-list\n"
9075 "IP prefix-list name\n")
9076
9077 DEFUN (show_ip_bgp_ipv4_prefix_list,
9078 show_ip_bgp_ipv4_prefix_list_cmd,
9079 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9080 SHOW_STR
9081 IP_STR
9082 BGP_STR
9083 "Address family\n"
9084 "Address Family modifier\n"
9085 "Address Family modifier\n"
9086 "Display routes conforming to the prefix-list\n"
9087 "IP prefix-list name\n")
9088 {
9089 if (strncmp (argv[0], "m", 1) == 0)
9090 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9091 bgp_show_type_prefix_list);
9092
9093 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9094 bgp_show_type_prefix_list);
9095 }
9096
9097 #ifdef HAVE_IPV6
9098 DEFUN (show_bgp_prefix_list,
9099 show_bgp_prefix_list_cmd,
9100 "show bgp prefix-list WORD",
9101 SHOW_STR
9102 BGP_STR
9103 "Display routes conforming to the prefix-list\n"
9104 "IPv6 prefix-list name\n")
9105 {
9106 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9107 bgp_show_type_prefix_list);
9108 }
9109
9110 ALIAS (show_bgp_prefix_list,
9111 show_bgp_ipv6_prefix_list_cmd,
9112 "show bgp ipv6 prefix-list WORD",
9113 SHOW_STR
9114 BGP_STR
9115 "Address family\n"
9116 "Display routes conforming to the prefix-list\n"
9117 "IPv6 prefix-list name\n")
9118
9119 /* old command */
9120 DEFUN (show_ipv6_bgp_prefix_list,
9121 show_ipv6_bgp_prefix_list_cmd,
9122 "show ipv6 bgp prefix-list WORD",
9123 SHOW_STR
9124 IPV6_STR
9125 BGP_STR
9126 "Display routes matching the prefix-list\n"
9127 "IPv6 prefix-list name\n")
9128 {
9129 bgp_show_ipv6_bgp_deprecate_warning(vty);
9130 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9131 bgp_show_type_prefix_list);
9132 }
9133
9134 /* old command */
9135 DEFUN (show_ipv6_mbgp_prefix_list,
9136 show_ipv6_mbgp_prefix_list_cmd,
9137 "show ipv6 mbgp prefix-list WORD",
9138 SHOW_STR
9139 IPV6_STR
9140 MBGP_STR
9141 "Display routes matching the prefix-list\n"
9142 "IPv6 prefix-list name\n")
9143 {
9144 bgp_show_ipv6_bgp_deprecate_warning(vty);
9145 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9146 bgp_show_type_prefix_list);
9147 }
9148 #endif /* HAVE_IPV6 */
9149
9150 static int
9151 bgp_show_filter_list (struct vty *vty, const char *name,
9152 const char *filter, afi_t afi,
9153 safi_t safi, enum bgp_show_type type)
9154 {
9155 struct as_list *as_list;
9156 struct bgp *bgp = NULL;
9157
9158 if (name && !(bgp = bgp_lookup_by_name(name)))
9159 {
9160 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9161 return CMD_WARNING;
9162 }
9163
9164 as_list = as_list_lookup (filter);
9165 if (as_list == NULL)
9166 {
9167 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9168 return CMD_WARNING;
9169 }
9170
9171 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9172 }
9173
9174 DEFUN (show_ip_bgp_filter_list,
9175 show_ip_bgp_filter_list_cmd,
9176 "show ip bgp filter-list WORD",
9177 SHOW_STR
9178 IP_STR
9179 BGP_STR
9180 "Display routes conforming to the filter-list\n"
9181 "Regular expression access list name\n")
9182 {
9183 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9184 bgp_show_type_filter_list);
9185 }
9186
9187 DEFUN (show_ip_bgp_instance_filter_list,
9188 show_ip_bgp_instance_filter_list_cmd,
9189 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9190 SHOW_STR
9191 IP_STR
9192 BGP_STR
9193 BGP_INSTANCE_HELP_STR
9194 "Display routes conforming to the filter-list\n"
9195 "Regular expression access list name\n")
9196 {
9197 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9198 bgp_show_type_filter_list);
9199 }
9200
9201 DEFUN (show_ip_bgp_flap_filter_list,
9202 show_ip_bgp_flap_filter_list_cmd,
9203 "show ip bgp flap-statistics filter-list WORD",
9204 SHOW_STR
9205 IP_STR
9206 BGP_STR
9207 "Display flap statistics of routes\n"
9208 "Display routes conforming to the filter-list\n"
9209 "Regular expression access list name\n")
9210 {
9211 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9212 bgp_show_type_flap_filter_list);
9213 }
9214
9215 ALIAS (show_ip_bgp_flap_filter_list,
9216 show_ip_bgp_damp_flap_filter_list_cmd,
9217 "show ip bgp dampening flap-statistics filter-list WORD",
9218 SHOW_STR
9219 IP_STR
9220 BGP_STR
9221 "Display detailed information about dampening\n"
9222 "Display flap statistics of routes\n"
9223 "Display routes conforming to the filter-list\n"
9224 "Regular expression access list name\n")
9225
9226 DEFUN (show_ip_bgp_ipv4_filter_list,
9227 show_ip_bgp_ipv4_filter_list_cmd,
9228 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9229 SHOW_STR
9230 IP_STR
9231 BGP_STR
9232 "Address family\n"
9233 "Address Family modifier\n"
9234 "Address Family modifier\n"
9235 "Display routes conforming to the filter-list\n"
9236 "Regular expression access list name\n")
9237 {
9238 if (strncmp (argv[0], "m", 1) == 0)
9239 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9240 bgp_show_type_filter_list);
9241
9242 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9243 bgp_show_type_filter_list);
9244 }
9245
9246 #ifdef HAVE_IPV6
9247 DEFUN (show_bgp_filter_list,
9248 show_bgp_filter_list_cmd,
9249 "show bgp filter-list WORD",
9250 SHOW_STR
9251 BGP_STR
9252 "Display routes conforming to the filter-list\n"
9253 "Regular expression access list name\n")
9254 {
9255 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9256 bgp_show_type_filter_list);
9257 }
9258
9259 ALIAS (show_bgp_filter_list,
9260 show_bgp_ipv6_filter_list_cmd,
9261 "show bgp ipv6 filter-list WORD",
9262 SHOW_STR
9263 BGP_STR
9264 "Address family\n"
9265 "Display routes conforming to the filter-list\n"
9266 "Regular expression access list name\n")
9267
9268 /* old command */
9269 DEFUN (show_ipv6_bgp_filter_list,
9270 show_ipv6_bgp_filter_list_cmd,
9271 "show ipv6 bgp filter-list WORD",
9272 SHOW_STR
9273 IPV6_STR
9274 BGP_STR
9275 "Display routes conforming to the filter-list\n"
9276 "Regular expression access list name\n")
9277 {
9278 bgp_show_ipv6_bgp_deprecate_warning(vty);
9279 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9280 bgp_show_type_filter_list);
9281 }
9282
9283 /* old command */
9284 DEFUN (show_ipv6_mbgp_filter_list,
9285 show_ipv6_mbgp_filter_list_cmd,
9286 "show ipv6 mbgp filter-list WORD",
9287 SHOW_STR
9288 IPV6_STR
9289 MBGP_STR
9290 "Display routes conforming to the filter-list\n"
9291 "Regular expression access list name\n")
9292 {
9293 bgp_show_ipv6_bgp_deprecate_warning(vty);
9294 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9295 bgp_show_type_filter_list);
9296 }
9297 #endif /* HAVE_IPV6 */
9298
9299 DEFUN (show_ip_bgp_dampening_info,
9300 show_ip_bgp_dampening_params_cmd,
9301 "show ip bgp dampening parameters",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Display detailed information about dampening\n"
9306 "Display detail of configured dampening parameters\n")
9307 {
9308 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9309 }
9310
9311 static int
9312 bgp_show_route_map (struct vty *vty, const char *name,
9313 const char *rmap_str, afi_t afi,
9314 safi_t safi, enum bgp_show_type type)
9315 {
9316 struct route_map *rmap;
9317 struct bgp *bgp = NULL;
9318
9319 if (name && !(bgp = bgp_lookup_by_name(name)))
9320 {
9321 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9322 return CMD_WARNING;
9323 }
9324
9325 rmap = route_map_lookup_by_name (rmap_str);
9326 if (! rmap)
9327 {
9328 vty_out (vty, "%% %s is not a valid route-map name%s",
9329 rmap_str, VTY_NEWLINE);
9330 return CMD_WARNING;
9331 }
9332
9333 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9334 }
9335
9336 DEFUN (show_ip_bgp_route_map,
9337 show_ip_bgp_route_map_cmd,
9338 "show ip bgp route-map WORD",
9339 SHOW_STR
9340 IP_STR
9341 BGP_STR
9342 "Display routes matching the route-map\n"
9343 "A route-map to match on\n")
9344 {
9345 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9346 bgp_show_type_route_map);
9347 }
9348
9349 DEFUN (show_ip_bgp_instance_route_map,
9350 show_ip_bgp_instance_route_map_cmd,
9351 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9352 SHOW_STR
9353 IP_STR
9354 BGP_STR
9355 BGP_INSTANCE_HELP_STR
9356 "Display routes matching the route-map\n"
9357 "A route-map to match on\n")
9358 {
9359 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9360 bgp_show_type_route_map);
9361 }
9362
9363 DEFUN (show_ip_bgp_flap_route_map,
9364 show_ip_bgp_flap_route_map_cmd,
9365 "show ip bgp flap-statistics route-map WORD",
9366 SHOW_STR
9367 IP_STR
9368 BGP_STR
9369 "Display flap statistics of routes\n"
9370 "Display routes matching the route-map\n"
9371 "A route-map to match on\n")
9372 {
9373 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9374 bgp_show_type_flap_route_map);
9375 }
9376
9377 ALIAS (show_ip_bgp_flap_route_map,
9378 show_ip_bgp_damp_flap_route_map_cmd,
9379 "show ip bgp dampening flap-statistics route-map WORD",
9380 SHOW_STR
9381 IP_STR
9382 BGP_STR
9383 "Display detailed information about dampening\n"
9384 "Display flap statistics of routes\n"
9385 "Display routes matching the route-map\n"
9386 "A route-map to match on\n")
9387
9388 DEFUN (show_ip_bgp_ipv4_route_map,
9389 show_ip_bgp_ipv4_route_map_cmd,
9390 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9391 SHOW_STR
9392 IP_STR
9393 BGP_STR
9394 "Address family\n"
9395 "Address Family modifier\n"
9396 "Address Family modifier\n"
9397 "Display routes matching the route-map\n"
9398 "A route-map to match on\n")
9399 {
9400 if (strncmp (argv[0], "m", 1) == 0)
9401 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9402 bgp_show_type_route_map);
9403
9404 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9405 bgp_show_type_route_map);
9406 }
9407
9408 DEFUN (show_bgp_route_map,
9409 show_bgp_route_map_cmd,
9410 "show bgp route-map WORD",
9411 SHOW_STR
9412 BGP_STR
9413 "Display routes matching the route-map\n"
9414 "A route-map to match on\n")
9415 {
9416 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9417 bgp_show_type_route_map);
9418 }
9419
9420 ALIAS (show_bgp_route_map,
9421 show_bgp_ipv6_route_map_cmd,
9422 "show bgp ipv6 route-map WORD",
9423 SHOW_STR
9424 BGP_STR
9425 "Address family\n"
9426 "Display routes matching the route-map\n"
9427 "A route-map to match on\n")
9428
9429 DEFUN (show_ip_bgp_cidr_only,
9430 show_ip_bgp_cidr_only_cmd,
9431 "show ip bgp cidr-only",
9432 SHOW_STR
9433 IP_STR
9434 BGP_STR
9435 "Display only routes with non-natural netmasks\n")
9436 {
9437 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9438 bgp_show_type_cidr_only, NULL, 0);
9439 }
9440
9441 DEFUN (show_ip_bgp_flap_cidr_only,
9442 show_ip_bgp_flap_cidr_only_cmd,
9443 "show ip bgp flap-statistics cidr-only",
9444 SHOW_STR
9445 IP_STR
9446 BGP_STR
9447 "Display flap statistics of routes\n"
9448 "Display only routes with non-natural netmasks\n")
9449 {
9450 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9451 bgp_show_type_flap_cidr_only, NULL, 0);
9452 }
9453
9454 ALIAS (show_ip_bgp_flap_cidr_only,
9455 show_ip_bgp_damp_flap_cidr_only_cmd,
9456 "show ip bgp dampening flap-statistics cidr-only",
9457 SHOW_STR
9458 IP_STR
9459 BGP_STR
9460 "Display detailed information about dampening\n"
9461 "Display flap statistics of routes\n"
9462 "Display only routes with non-natural netmasks\n")
9463
9464 DEFUN (show_ip_bgp_ipv4_cidr_only,
9465 show_ip_bgp_ipv4_cidr_only_cmd,
9466 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9467 SHOW_STR
9468 IP_STR
9469 BGP_STR
9470 "Address family\n"
9471 "Address Family modifier\n"
9472 "Address Family modifier\n"
9473 "Display only routes with non-natural netmasks\n")
9474 {
9475 if (strncmp (argv[0], "m", 1) == 0)
9476 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9477 bgp_show_type_cidr_only, NULL, 0);
9478
9479 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9480 bgp_show_type_cidr_only, NULL, 0);
9481 }
9482
9483 DEFUN (show_ip_bgp_community_all,
9484 show_ip_bgp_community_all_cmd,
9485 "show ip bgp community",
9486 SHOW_STR
9487 IP_STR
9488 BGP_STR
9489 "Display routes matching the communities\n")
9490 {
9491 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9492 bgp_show_type_community_all, NULL, 0);
9493 }
9494
9495 DEFUN (show_ip_bgp_ipv4_community_all,
9496 show_ip_bgp_ipv4_community_all_cmd,
9497 "show ip bgp ipv4 (unicast|multicast) community",
9498 SHOW_STR
9499 IP_STR
9500 BGP_STR
9501 "Address family\n"
9502 "Address Family modifier\n"
9503 "Address Family modifier\n"
9504 "Display routes matching the communities\n")
9505 {
9506 if (strncmp (argv[0], "m", 1) == 0)
9507 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9508 bgp_show_type_community_all, NULL, 0);
9509
9510 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9511 bgp_show_type_community_all, NULL, 0);
9512 }
9513
9514 #ifdef HAVE_IPV6
9515 DEFUN (show_bgp_community_all,
9516 show_bgp_community_all_cmd,
9517 "show bgp community",
9518 SHOW_STR
9519 BGP_STR
9520 "Display routes matching the communities\n")
9521 {
9522 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9523 bgp_show_type_community_all, NULL, 0);
9524 }
9525
9526 ALIAS (show_bgp_community_all,
9527 show_bgp_ipv6_community_all_cmd,
9528 "show bgp ipv6 community",
9529 SHOW_STR
9530 BGP_STR
9531 "Address family\n"
9532 "Display routes matching the communities\n")
9533
9534 /* old command */
9535 DEFUN (show_ipv6_bgp_community_all,
9536 show_ipv6_bgp_community_all_cmd,
9537 "show ipv6 bgp community",
9538 SHOW_STR
9539 IPV6_STR
9540 BGP_STR
9541 "Display routes matching the communities\n")
9542 {
9543 bgp_show_ipv6_bgp_deprecate_warning(vty);
9544 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9545 bgp_show_type_community_all, NULL, 0);
9546 }
9547
9548 /* old command */
9549 DEFUN (show_ipv6_mbgp_community_all,
9550 show_ipv6_mbgp_community_all_cmd,
9551 "show ipv6 mbgp community",
9552 SHOW_STR
9553 IPV6_STR
9554 MBGP_STR
9555 "Display routes matching the communities\n")
9556 {
9557 bgp_show_ipv6_bgp_deprecate_warning(vty);
9558 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9559 bgp_show_type_community_all, NULL, 0);
9560 }
9561 #endif /* HAVE_IPV6 */
9562
9563 static int
9564 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9565 const char **argv, int exact, afi_t afi, safi_t safi)
9566 {
9567 struct community *com;
9568 struct buffer *b;
9569 struct bgp *bgp;
9570 int i;
9571 char *str;
9572 int first = 0;
9573
9574 /* BGP structure lookup */
9575 if (view_name)
9576 {
9577 bgp = bgp_lookup_by_name (view_name);
9578 if (bgp == NULL)
9579 {
9580 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9581 return CMD_WARNING;
9582 }
9583 }
9584 else
9585 {
9586 bgp = bgp_get_default ();
9587 if (bgp == NULL)
9588 {
9589 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9590 return CMD_WARNING;
9591 }
9592 }
9593
9594 b = buffer_new (1024);
9595 for (i = 0; i < argc; i++)
9596 {
9597 if (first)
9598 buffer_putc (b, ' ');
9599 else
9600 {
9601 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9602 continue;
9603 first = 1;
9604 }
9605
9606 buffer_putstr (b, argv[i]);
9607 }
9608 buffer_putc (b, '\0');
9609
9610 str = buffer_getstr (b);
9611 buffer_free (b);
9612
9613 com = community_str2com (str);
9614 XFREE (MTYPE_TMP, str);
9615 if (! com)
9616 {
9617 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9618 return CMD_WARNING;
9619 }
9620
9621 return bgp_show (vty, bgp, afi, safi,
9622 (exact ? bgp_show_type_community_exact :
9623 bgp_show_type_community), com, 0);
9624 }
9625
9626 DEFUN (show_ip_bgp_community,
9627 show_ip_bgp_community_cmd,
9628 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9629 SHOW_STR
9630 IP_STR
9631 BGP_STR
9632 "Display routes matching the communities\n"
9633 COMMUNITY_AANN_STR
9634 "Do not send outside local AS (well-known community)\n"
9635 "Do not advertise to any peer (well-known community)\n"
9636 "Do not export to next AS (well-known community)\n")
9637 {
9638 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9639 }
9640
9641 ALIAS (show_ip_bgp_community,
9642 show_ip_bgp_community2_cmd,
9643 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9644 SHOW_STR
9645 IP_STR
9646 BGP_STR
9647 "Display routes matching the communities\n"
9648 COMMUNITY_AANN_STR
9649 "Do not send outside local AS (well-known community)\n"
9650 "Do not advertise to any peer (well-known community)\n"
9651 "Do not export to next AS (well-known community)\n"
9652 COMMUNITY_AANN_STR
9653 "Do not send outside local AS (well-known community)\n"
9654 "Do not advertise to any peer (well-known community)\n"
9655 "Do not export to next AS (well-known community)\n")
9656
9657 ALIAS (show_ip_bgp_community,
9658 show_ip_bgp_community3_cmd,
9659 "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)",
9660 SHOW_STR
9661 IP_STR
9662 BGP_STR
9663 "Display routes matching the communities\n"
9664 COMMUNITY_AANN_STR
9665 "Do not send outside local AS (well-known community)\n"
9666 "Do not advertise to any peer (well-known community)\n"
9667 "Do not export to next AS (well-known community)\n"
9668 COMMUNITY_AANN_STR
9669 "Do not send outside local AS (well-known community)\n"
9670 "Do not advertise to any peer (well-known community)\n"
9671 "Do not export to next AS (well-known community)\n"
9672 COMMUNITY_AANN_STR
9673 "Do not send outside local AS (well-known community)\n"
9674 "Do not advertise to any peer (well-known community)\n"
9675 "Do not export to next AS (well-known community)\n")
9676
9677 ALIAS (show_ip_bgp_community,
9678 show_ip_bgp_community4_cmd,
9679 "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)",
9680 SHOW_STR
9681 IP_STR
9682 BGP_STR
9683 "Display routes matching the communities\n"
9684 COMMUNITY_AANN_STR
9685 "Do not send outside local AS (well-known community)\n"
9686 "Do not advertise to any peer (well-known community)\n"
9687 "Do not export to next AS (well-known community)\n"
9688 COMMUNITY_AANN_STR
9689 "Do not send outside local AS (well-known community)\n"
9690 "Do not advertise to any peer (well-known community)\n"
9691 "Do not export to next AS (well-known community)\n"
9692 COMMUNITY_AANN_STR
9693 "Do not send outside local AS (well-known community)\n"
9694 "Do not advertise to any peer (well-known community)\n"
9695 "Do not export to next AS (well-known community)\n"
9696 COMMUNITY_AANN_STR
9697 "Do not send outside local AS (well-known community)\n"
9698 "Do not advertise to any peer (well-known community)\n"
9699 "Do not export to next AS (well-known community)\n")
9700
9701 DEFUN (show_ip_bgp_ipv4_community,
9702 show_ip_bgp_ipv4_community_cmd,
9703 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9704 SHOW_STR
9705 IP_STR
9706 BGP_STR
9707 "Address family\n"
9708 "Address Family modifier\n"
9709 "Address Family modifier\n"
9710 "Display routes matching the communities\n"
9711 COMMUNITY_AANN_STR
9712 "Do not send outside local AS (well-known community)\n"
9713 "Do not advertise to any peer (well-known community)\n"
9714 "Do not export to next AS (well-known community)\n")
9715 {
9716 if (strncmp (argv[0], "m", 1) == 0)
9717 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9718
9719 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9720 }
9721
9722 ALIAS (show_ip_bgp_ipv4_community,
9723 show_ip_bgp_ipv4_community2_cmd,
9724 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9725 SHOW_STR
9726 IP_STR
9727 BGP_STR
9728 "Address family\n"
9729 "Address Family modifier\n"
9730 "Address Family modifier\n"
9731 "Display routes matching the communities\n"
9732 COMMUNITY_AANN_STR
9733 "Do not send outside local AS (well-known community)\n"
9734 "Do not advertise to any peer (well-known community)\n"
9735 "Do not export to next AS (well-known community)\n"
9736 COMMUNITY_AANN_STR
9737 "Do not send outside local AS (well-known community)\n"
9738 "Do not advertise to any peer (well-known community)\n"
9739 "Do not export to next AS (well-known community)\n")
9740
9741 ALIAS (show_ip_bgp_ipv4_community,
9742 show_ip_bgp_ipv4_community3_cmd,
9743 "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)",
9744 SHOW_STR
9745 IP_STR
9746 BGP_STR
9747 "Address family\n"
9748 "Address Family modifier\n"
9749 "Address Family modifier\n"
9750 "Display routes matching the communities\n"
9751 COMMUNITY_AANN_STR
9752 "Do not send outside local AS (well-known community)\n"
9753 "Do not advertise to any peer (well-known community)\n"
9754 "Do not export to next AS (well-known community)\n"
9755 COMMUNITY_AANN_STR
9756 "Do not send outside local AS (well-known community)\n"
9757 "Do not advertise to any peer (well-known community)\n"
9758 "Do not export to next AS (well-known community)\n"
9759 COMMUNITY_AANN_STR
9760 "Do not send outside local AS (well-known community)\n"
9761 "Do not advertise to any peer (well-known community)\n"
9762 "Do not export to next AS (well-known community)\n")
9763
9764 ALIAS (show_ip_bgp_ipv4_community,
9765 show_ip_bgp_ipv4_community4_cmd,
9766 "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)",
9767 SHOW_STR
9768 IP_STR
9769 BGP_STR
9770 "Address family\n"
9771 "Address Family modifier\n"
9772 "Address Family modifier\n"
9773 "Display routes matching the communities\n"
9774 COMMUNITY_AANN_STR
9775 "Do not send outside local AS (well-known community)\n"
9776 "Do not advertise to any peer (well-known community)\n"
9777 "Do not export to next AS (well-known community)\n"
9778 COMMUNITY_AANN_STR
9779 "Do not send outside local AS (well-known community)\n"
9780 "Do not advertise to any peer (well-known community)\n"
9781 "Do not export to next AS (well-known community)\n"
9782 COMMUNITY_AANN_STR
9783 "Do not send outside local AS (well-known community)\n"
9784 "Do not advertise to any peer (well-known community)\n"
9785 "Do not export to next AS (well-known community)\n"
9786 COMMUNITY_AANN_STR
9787 "Do not send outside local AS (well-known community)\n"
9788 "Do not advertise to any peer (well-known community)\n"
9789 "Do not export to next AS (well-known community)\n")
9790
9791 DEFUN (show_bgp_instance_afi_safi_community_all,
9792 show_bgp_instance_afi_safi_community_all_cmd,
9793 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
9794 SHOW_STR
9795 BGP_STR
9796 BGP_INSTANCE_HELP_STR
9797 "Address family\n"
9798 "Address family\n"
9799 "Address Family modifier\n"
9800 "Address Family modifier\n"
9801 "Display routes matching the communities\n")
9802 {
9803 int afi;
9804 int safi;
9805 struct bgp *bgp;
9806
9807 /* BGP structure lookup. */
9808 bgp = bgp_lookup_by_name (argv[1]);
9809 if (bgp == NULL)
9810 {
9811 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
9812 return CMD_WARNING;
9813 }
9814
9815 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9816 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9817 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
9818 }
9819
9820 DEFUN (show_bgp_instance_afi_safi_community,
9821 show_bgp_instance_afi_safi_community_cmd,
9822 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9823 SHOW_STR
9824 BGP_STR
9825 BGP_INSTANCE_HELP_STR
9826 "Address family\n"
9827 "Address family\n"
9828 "Address family modifier\n"
9829 "Address family modifier\n"
9830 "Display routes matching the communities\n"
9831 COMMUNITY_AANN_STR
9832 "Do not send outside local AS (well-known community)\n"
9833 "Do not advertise to any peer (well-known community)\n"
9834 "Do not export to next AS (well-known community)\n")
9835 {
9836 int afi;
9837 int safi;
9838
9839 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9840 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9841 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
9842 }
9843
9844 ALIAS (show_bgp_instance_afi_safi_community,
9845 show_bgp_instance_afi_safi_community2_cmd,
9846 "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)",
9847 SHOW_STR
9848 BGP_STR
9849 BGP_INSTANCE_HELP_STR
9850 "Address family\n"
9851 "Address family\n"
9852 "Address family modifier\n"
9853 "Address family modifier\n"
9854 "Display routes matching the communities\n"
9855 COMMUNITY_AANN_STR
9856 "Do not send outside local AS (well-known community)\n"
9857 "Do not advertise to any peer (well-known community)\n"
9858 "Do not export to next AS (well-known community)\n"
9859 COMMUNITY_AANN_STR
9860 "Do not send outside local AS (well-known community)\n"
9861 "Do not advertise to any peer (well-known community)\n"
9862 "Do not export to next AS (well-known community)\n")
9863
9864 ALIAS (show_bgp_instance_afi_safi_community,
9865 show_bgp_instance_afi_safi_community3_cmd,
9866 "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)",
9867 SHOW_STR
9868 BGP_STR
9869 BGP_INSTANCE_HELP_STR
9870 "Address family\n"
9871 "Address family\n"
9872 "Address family modifier\n"
9873 "Address family modifier\n"
9874 "Display routes matching the communities\n"
9875 COMMUNITY_AANN_STR
9876 "Do not send outside local AS (well-known community)\n"
9877 "Do not advertise to any peer (well-known community)\n"
9878 "Do not export to next AS (well-known community)\n"
9879 COMMUNITY_AANN_STR
9880 "Do not send outside local AS (well-known community)\n"
9881 "Do not advertise to any peer (well-known community)\n"
9882 "Do not export to next AS (well-known community)\n"
9883 COMMUNITY_AANN_STR
9884 "Do not send outside local AS (well-known community)\n"
9885 "Do not advertise to any peer (well-known community)\n"
9886 "Do not export to next AS (well-known community)\n")
9887
9888 ALIAS (show_bgp_instance_afi_safi_community,
9889 show_bgp_instance_afi_safi_community4_cmd,
9890 "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)",
9891 SHOW_STR
9892 BGP_STR
9893 BGP_INSTANCE_HELP_STR
9894 "Address family\n"
9895 "Address family\n"
9896 "Address family modifier\n"
9897 "Address family modifier\n"
9898 "Display routes matching the communities\n"
9899 COMMUNITY_AANN_STR
9900 "Do not send outside local AS (well-known community)\n"
9901 "Do not advertise to any peer (well-known community)\n"
9902 "Do not export to next AS (well-known community)\n"
9903 COMMUNITY_AANN_STR
9904 "Do not send outside local AS (well-known community)\n"
9905 "Do not advertise to any peer (well-known community)\n"
9906 "Do not export to next AS (well-known community)\n"
9907 COMMUNITY_AANN_STR
9908 "Do not send outside local AS (well-known community)\n"
9909 "Do not advertise to any peer (well-known community)\n"
9910 "Do not export to next AS (well-known community)\n"
9911 COMMUNITY_AANN_STR
9912 "Do not send outside local AS (well-known community)\n"
9913 "Do not advertise to any peer (well-known community)\n"
9914 "Do not export to next AS (well-known community)\n")
9915
9916 DEFUN (show_ip_bgp_community_exact,
9917 show_ip_bgp_community_exact_cmd,
9918 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9919 SHOW_STR
9920 IP_STR
9921 BGP_STR
9922 "Display routes matching the communities\n"
9923 COMMUNITY_AANN_STR
9924 "Do not send outside local AS (well-known community)\n"
9925 "Do not advertise to any peer (well-known community)\n"
9926 "Do not export to next AS (well-known community)\n"
9927 "Exact match of the communities")
9928 {
9929 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9930 }
9931
9932 ALIAS (show_ip_bgp_community_exact,
9933 show_ip_bgp_community2_exact_cmd,
9934 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9935 SHOW_STR
9936 IP_STR
9937 BGP_STR
9938 "Display routes matching the communities\n"
9939 COMMUNITY_AANN_STR
9940 "Do not send outside local AS (well-known community)\n"
9941 "Do not advertise to any peer (well-known community)\n"
9942 "Do not export to next AS (well-known community)\n"
9943 COMMUNITY_AANN_STR
9944 "Do not send outside local AS (well-known community)\n"
9945 "Do not advertise to any peer (well-known community)\n"
9946 "Do not export to next AS (well-known community)\n"
9947 "Exact match of the communities")
9948
9949 ALIAS (show_ip_bgp_community_exact,
9950 show_ip_bgp_community3_exact_cmd,
9951 "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",
9952 SHOW_STR
9953 IP_STR
9954 BGP_STR
9955 "Display routes matching the communities\n"
9956 COMMUNITY_AANN_STR
9957 "Do not send outside local AS (well-known community)\n"
9958 "Do not advertise to any peer (well-known community)\n"
9959 "Do not export to next AS (well-known community)\n"
9960 COMMUNITY_AANN_STR
9961 "Do not send outside local AS (well-known community)\n"
9962 "Do not advertise to any peer (well-known community)\n"
9963 "Do not export to next AS (well-known community)\n"
9964 COMMUNITY_AANN_STR
9965 "Do not send outside local AS (well-known community)\n"
9966 "Do not advertise to any peer (well-known community)\n"
9967 "Do not export to next AS (well-known community)\n"
9968 "Exact match of the communities")
9969
9970 ALIAS (show_ip_bgp_community_exact,
9971 show_ip_bgp_community4_exact_cmd,
9972 "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",
9973 SHOW_STR
9974 IP_STR
9975 BGP_STR
9976 "Display routes matching the communities\n"
9977 COMMUNITY_AANN_STR
9978 "Do not send outside local AS (well-known community)\n"
9979 "Do not advertise to any peer (well-known community)\n"
9980 "Do not export to next AS (well-known community)\n"
9981 COMMUNITY_AANN_STR
9982 "Do not send outside local AS (well-known community)\n"
9983 "Do not advertise to any peer (well-known community)\n"
9984 "Do not export to next AS (well-known community)\n"
9985 COMMUNITY_AANN_STR
9986 "Do not send outside local AS (well-known community)\n"
9987 "Do not advertise to any peer (well-known community)\n"
9988 "Do not export to next AS (well-known community)\n"
9989 COMMUNITY_AANN_STR
9990 "Do not send outside local AS (well-known community)\n"
9991 "Do not advertise to any peer (well-known community)\n"
9992 "Do not export to next AS (well-known community)\n"
9993 "Exact match of the communities")
9994
9995 DEFUN (show_ip_bgp_ipv4_community_exact,
9996 show_ip_bgp_ipv4_community_exact_cmd,
9997 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9998 SHOW_STR
9999 IP_STR
10000 BGP_STR
10001 "Address family\n"
10002 "Address Family modifier\n"
10003 "Address Family modifier\n"
10004 "Display routes matching the communities\n"
10005 COMMUNITY_AANN_STR
10006 "Do not send outside local AS (well-known community)\n"
10007 "Do not advertise to any peer (well-known community)\n"
10008 "Do not export to next AS (well-known community)\n"
10009 "Exact match of the communities")
10010 {
10011 if (strncmp (argv[0], "m", 1) == 0)
10012 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
10013
10014 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10015 }
10016
10017 ALIAS (show_ip_bgp_ipv4_community_exact,
10018 show_ip_bgp_ipv4_community2_exact_cmd,
10019 "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",
10020 SHOW_STR
10021 IP_STR
10022 BGP_STR
10023 "Address family\n"
10024 "Address Family modifier\n"
10025 "Address Family modifier\n"
10026 "Display routes matching the communities\n"
10027 COMMUNITY_AANN_STR
10028 "Do not send outside local AS (well-known community)\n"
10029 "Do not advertise to any peer (well-known community)\n"
10030 "Do not export to next AS (well-known community)\n"
10031 COMMUNITY_AANN_STR
10032 "Do not send outside local AS (well-known community)\n"
10033 "Do not advertise to any peer (well-known community)\n"
10034 "Do not export to next AS (well-known community)\n"
10035 "Exact match of the communities")
10036
10037 ALIAS (show_ip_bgp_ipv4_community_exact,
10038 show_ip_bgp_ipv4_community3_exact_cmd,
10039 "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",
10040 SHOW_STR
10041 IP_STR
10042 BGP_STR
10043 "Address family\n"
10044 "Address Family modifier\n"
10045 "Address Family modifier\n"
10046 "Display routes matching the communities\n"
10047 COMMUNITY_AANN_STR
10048 "Do not send outside local AS (well-known community)\n"
10049 "Do not advertise to any peer (well-known community)\n"
10050 "Do not export to next AS (well-known community)\n"
10051 COMMUNITY_AANN_STR
10052 "Do not send outside local AS (well-known community)\n"
10053 "Do not advertise to any peer (well-known community)\n"
10054 "Do not export to next AS (well-known community)\n"
10055 COMMUNITY_AANN_STR
10056 "Do not send outside local AS (well-known community)\n"
10057 "Do not advertise to any peer (well-known community)\n"
10058 "Do not export to next AS (well-known community)\n"
10059 "Exact match of the communities")
10060
10061 ALIAS (show_ip_bgp_ipv4_community_exact,
10062 show_ip_bgp_ipv4_community4_exact_cmd,
10063 "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",
10064 SHOW_STR
10065 IP_STR
10066 BGP_STR
10067 "Address family\n"
10068 "Address Family modifier\n"
10069 "Address Family modifier\n"
10070 "Display routes matching the communities\n"
10071 COMMUNITY_AANN_STR
10072 "Do not send outside local AS (well-known community)\n"
10073 "Do not advertise to any peer (well-known community)\n"
10074 "Do not export to next AS (well-known community)\n"
10075 COMMUNITY_AANN_STR
10076 "Do not send outside local AS (well-known community)\n"
10077 "Do not advertise to any peer (well-known community)\n"
10078 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10088
10089 #ifdef HAVE_IPV6
10090 DEFUN (show_bgp_community,
10091 show_bgp_community_cmd,
10092 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10093 SHOW_STR
10094 BGP_STR
10095 "Display routes matching the communities\n"
10096 COMMUNITY_AANN_STR
10097 "Do not send outside local AS (well-known community)\n"
10098 "Do not advertise to any peer (well-known community)\n"
10099 "Do not export to next AS (well-known community)\n")
10100 {
10101 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10102 }
10103
10104 ALIAS (show_bgp_community,
10105 show_bgp_ipv6_community_cmd,
10106 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10107 SHOW_STR
10108 BGP_STR
10109 "Address family\n"
10110 "Display routes matching the communities\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 ALIAS (show_bgp_community,
10117 show_bgp_community2_cmd,
10118 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10119 SHOW_STR
10120 BGP_STR
10121 "Display routes matching the communities\n"
10122 COMMUNITY_AANN_STR
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n"
10126 COMMUNITY_AANN_STR
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n")
10130
10131 ALIAS (show_bgp_community,
10132 show_bgp_ipv6_community2_cmd,
10133 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10134 SHOW_STR
10135 BGP_STR
10136 "Address family\n"
10137 "Display routes matching the communities\n"
10138 COMMUNITY_AANN_STR
10139 "Do not send outside local AS (well-known community)\n"
10140 "Do not advertise to any peer (well-known community)\n"
10141 "Do not export to next AS (well-known community)\n"
10142 COMMUNITY_AANN_STR
10143 "Do not send outside local AS (well-known community)\n"
10144 "Do not advertise to any peer (well-known community)\n"
10145 "Do not export to next AS (well-known community)\n")
10146
10147 ALIAS (show_bgp_community,
10148 show_bgp_community3_cmd,
10149 "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)",
10150 SHOW_STR
10151 BGP_STR
10152 "Display routes matching the communities\n"
10153 COMMUNITY_AANN_STR
10154 "Do not send outside local AS (well-known community)\n"
10155 "Do not advertise to any peer (well-known community)\n"
10156 "Do not export to next AS (well-known community)\n"
10157 COMMUNITY_AANN_STR
10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n"
10161 COMMUNITY_AANN_STR
10162 "Do not send outside local AS (well-known community)\n"
10163 "Do not advertise to any peer (well-known community)\n"
10164 "Do not export to next AS (well-known community)\n")
10165
10166 ALIAS (show_bgp_community,
10167 show_bgp_ipv6_community3_cmd,
10168 "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)",
10169 SHOW_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Display routes matching the communities\n"
10173 COMMUNITY_AANN_STR
10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n"
10177 COMMUNITY_AANN_STR
10178 "Do not send outside local AS (well-known community)\n"
10179 "Do not advertise to any peer (well-known community)\n"
10180 "Do not export to next AS (well-known community)\n"
10181 COMMUNITY_AANN_STR
10182 "Do not send outside local AS (well-known community)\n"
10183 "Do not advertise to any peer (well-known community)\n"
10184 "Do not export to next AS (well-known community)\n")
10185
10186 ALIAS (show_bgp_community,
10187 show_bgp_community4_cmd,
10188 "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)",
10189 SHOW_STR
10190 BGP_STR
10191 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10205 "Do not send outside local AS (well-known community)\n"
10206 "Do not advertise to any peer (well-known community)\n"
10207 "Do not export to next AS (well-known community)\n")
10208
10209 ALIAS (show_bgp_community,
10210 show_bgp_ipv6_community4_cmd,
10211 "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)",
10212 SHOW_STR
10213 BGP_STR
10214 "Address family\n"
10215 "Display routes matching the communities\n"
10216 COMMUNITY_AANN_STR
10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\n"
10220 COMMUNITY_AANN_STR
10221 "Do not send outside local AS (well-known community)\n"
10222 "Do not advertise to any peer (well-known community)\n"
10223 "Do not export to next AS (well-known community)\n"
10224 COMMUNITY_AANN_STR
10225 "Do not send outside local AS (well-known community)\n"
10226 "Do not advertise to any peer (well-known community)\n"
10227 "Do not export to next AS (well-known community)\n"
10228 COMMUNITY_AANN_STR
10229 "Do not send outside local AS (well-known community)\n"
10230 "Do not advertise to any peer (well-known community)\n"
10231 "Do not export to next AS (well-known community)\n")
10232
10233 /* old command */
10234 DEFUN (show_ipv6_bgp_community,
10235 show_ipv6_bgp_community_cmd,
10236 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10237 SHOW_STR
10238 IPV6_STR
10239 BGP_STR
10240 "Display routes matching the communities\n"
10241 COMMUNITY_AANN_STR
10242 "Do not send outside local AS (well-known community)\n"
10243 "Do not advertise to any peer (well-known community)\n"
10244 "Do not export to next AS (well-known community)\n")
10245 {
10246 bgp_show_ipv6_bgp_deprecate_warning(vty);
10247 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10248 }
10249
10250 /* old command */
10251 ALIAS (show_ipv6_bgp_community,
10252 show_ipv6_bgp_community2_cmd,
10253 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10254 SHOW_STR
10255 IPV6_STR
10256 BGP_STR
10257 "Display routes matching the communities\n"
10258 COMMUNITY_AANN_STR
10259 "Do not send outside local AS (well-known community)\n"
10260 "Do not advertise to any peer (well-known community)\n"
10261 "Do not export to next AS (well-known community)\n"
10262 COMMUNITY_AANN_STR
10263 "Do not send outside local AS (well-known community)\n"
10264 "Do not advertise to any peer (well-known community)\n"
10265 "Do not export to next AS (well-known community)\n")
10266
10267 /* old command */
10268 ALIAS (show_ipv6_bgp_community,
10269 show_ipv6_bgp_community3_cmd,
10270 "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)",
10271 SHOW_STR
10272 IPV6_STR
10273 BGP_STR
10274 "Display routes matching the communities\n"
10275 COMMUNITY_AANN_STR
10276 "Do not send outside local AS (well-known community)\n"
10277 "Do not advertise to any peer (well-known community)\n"
10278 "Do not export to next AS (well-known community)\n"
10279 COMMUNITY_AANN_STR
10280 "Do not send outside local AS (well-known community)\n"
10281 "Do not advertise to any peer (well-known community)\n"
10282 "Do not export to next AS (well-known community)\n"
10283 COMMUNITY_AANN_STR
10284 "Do not send outside local AS (well-known community)\n"
10285 "Do not advertise to any peer (well-known community)\n"
10286 "Do not export to next AS (well-known community)\n")
10287
10288 /* old command */
10289 ALIAS (show_ipv6_bgp_community,
10290 show_ipv6_bgp_community4_cmd,
10291 "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)",
10292 SHOW_STR
10293 IPV6_STR
10294 BGP_STR
10295 "Display routes matching the communities\n"
10296 COMMUNITY_AANN_STR
10297 "Do not send outside local AS (well-known community)\n"
10298 "Do not advertise to any peer (well-known community)\n"
10299 "Do not export to next AS (well-known community)\n"
10300 COMMUNITY_AANN_STR
10301 "Do not send outside local AS (well-known community)\n"
10302 "Do not advertise to any peer (well-known community)\n"
10303 "Do not export to next AS (well-known community)\n"
10304 COMMUNITY_AANN_STR
10305 "Do not send outside local AS (well-known community)\n"
10306 "Do not advertise to any peer (well-known community)\n"
10307 "Do not export to next AS (well-known community)\n"
10308 COMMUNITY_AANN_STR
10309 "Do not send outside local AS (well-known community)\n"
10310 "Do not advertise to any peer (well-known community)\n"
10311 "Do not export to next AS (well-known community)\n")
10312
10313 DEFUN (show_bgp_community_exact,
10314 show_bgp_community_exact_cmd,
10315 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10316 SHOW_STR
10317 BGP_STR
10318 "Display routes matching the communities\n"
10319 COMMUNITY_AANN_STR
10320 "Do not send outside local AS (well-known community)\n"
10321 "Do not advertise to any peer (well-known community)\n"
10322 "Do not export to next AS (well-known community)\n"
10323 "Exact match of the communities")
10324 {
10325 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10326 }
10327
10328 ALIAS (show_bgp_community_exact,
10329 show_bgp_ipv6_community_exact_cmd,
10330 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10331 SHOW_STR
10332 BGP_STR
10333 "Address family\n"
10334 "Display routes matching the communities\n"
10335 COMMUNITY_AANN_STR
10336 "Do not send outside local AS (well-known community)\n"
10337 "Do not advertise to any peer (well-known community)\n"
10338 "Do not export to next AS (well-known community)\n"
10339 "Exact match of the communities")
10340
10341 ALIAS (show_bgp_community_exact,
10342 show_bgp_community2_exact_cmd,
10343 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10344 SHOW_STR
10345 BGP_STR
10346 "Display routes matching the communities\n"
10347 COMMUNITY_AANN_STR
10348 "Do not send outside local AS (well-known community)\n"
10349 "Do not advertise to any peer (well-known community)\n"
10350 "Do not export to next AS (well-known community)\n"
10351 COMMUNITY_AANN_STR
10352 "Do not send outside local AS (well-known community)\n"
10353 "Do not advertise to any peer (well-known community)\n"
10354 "Do not export to next AS (well-known community)\n"
10355 "Exact match of the communities")
10356
10357 ALIAS (show_bgp_community_exact,
10358 show_bgp_ipv6_community2_exact_cmd,
10359 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10360 SHOW_STR
10361 BGP_STR
10362 "Address family\n"
10363 "Display routes matching the communities\n"
10364 COMMUNITY_AANN_STR
10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
10368 COMMUNITY_AANN_STR
10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "Exact match of the communities")
10373
10374 ALIAS (show_bgp_community_exact,
10375 show_bgp_community3_exact_cmd,
10376 "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",
10377 SHOW_STR
10378 BGP_STR
10379 "Display routes matching the communities\n"
10380 COMMUNITY_AANN_STR
10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
10384 COMMUNITY_AANN_STR
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n"
10388 COMMUNITY_AANN_STR
10389 "Do not send outside local AS (well-known community)\n"
10390 "Do not advertise to any peer (well-known community)\n"
10391 "Do not export to next AS (well-known community)\n"
10392 "Exact match of the communities")
10393
10394 ALIAS (show_bgp_community_exact,
10395 show_bgp_ipv6_community3_exact_cmd,
10396 "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",
10397 SHOW_STR
10398 BGP_STR
10399 "Address family\n"
10400 "Display routes matching the communities\n"
10401 COMMUNITY_AANN_STR
10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n"
10405 COMMUNITY_AANN_STR
10406 "Do not send outside local AS (well-known community)\n"
10407 "Do not advertise to any peer (well-known community)\n"
10408 "Do not export to next AS (well-known community)\n"
10409 COMMUNITY_AANN_STR
10410 "Do not send outside local AS (well-known community)\n"
10411 "Do not advertise to any peer (well-known community)\n"
10412 "Do not export to next AS (well-known community)\n"
10413 "Exact match of the communities")
10414
10415 ALIAS (show_bgp_community_exact,
10416 show_bgp_community4_exact_cmd,
10417 "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",
10418 SHOW_STR
10419 BGP_STR
10420 "Display routes matching the communities\n"
10421 COMMUNITY_AANN_STR
10422 "Do not send outside local AS (well-known community)\n"
10423 "Do not advertise to any peer (well-known community)\n"
10424 "Do not export to next AS (well-known community)\n"
10425 COMMUNITY_AANN_STR
10426 "Do not send outside local AS (well-known community)\n"
10427 "Do not advertise to any peer (well-known community)\n"
10428 "Do not export to next AS (well-known community)\n"
10429 COMMUNITY_AANN_STR
10430 "Do not send outside local AS (well-known community)\n"
10431 "Do not advertise to any peer (well-known community)\n"
10432 "Do not export to next AS (well-known community)\n"
10433 COMMUNITY_AANN_STR
10434 "Do not send outside local AS (well-known community)\n"
10435 "Do not advertise to any peer (well-known community)\n"
10436 "Do not export to next AS (well-known community)\n"
10437 "Exact match of the communities")
10438
10439 ALIAS (show_bgp_community_exact,
10440 show_bgp_ipv6_community4_exact_cmd,
10441 "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",
10442 SHOW_STR
10443 BGP_STR
10444 "Address family\n"
10445 "Display routes matching the communities\n"
10446 COMMUNITY_AANN_STR
10447 "Do not send outside local AS (well-known community)\n"
10448 "Do not advertise to any peer (well-known community)\n"
10449 "Do not export to next AS (well-known community)\n"
10450 COMMUNITY_AANN_STR
10451 "Do not send outside local AS (well-known community)\n"
10452 "Do not advertise to any peer (well-known community)\n"
10453 "Do not export to next AS (well-known community)\n"
10454 COMMUNITY_AANN_STR
10455 "Do not send outside local AS (well-known community)\n"
10456 "Do not advertise to any peer (well-known community)\n"
10457 "Do not export to next AS (well-known community)\n"
10458 COMMUNITY_AANN_STR
10459 "Do not send outside local AS (well-known community)\n"
10460 "Do not advertise to any peer (well-known community)\n"
10461 "Do not export to next AS (well-known community)\n"
10462 "Exact match of the communities")
10463
10464 /* old command */
10465 DEFUN (show_ipv6_bgp_community_exact,
10466 show_ipv6_bgp_community_exact_cmd,
10467 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10468 SHOW_STR
10469 IPV6_STR
10470 BGP_STR
10471 "Display routes matching the communities\n"
10472 COMMUNITY_AANN_STR
10473 "Do not send outside local AS (well-known community)\n"
10474 "Do not advertise to any peer (well-known community)\n"
10475 "Do not export to next AS (well-known community)\n"
10476 "Exact match of the communities")
10477 {
10478 bgp_show_ipv6_bgp_deprecate_warning(vty);
10479 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10480 }
10481
10482 /* old command */
10483 ALIAS (show_ipv6_bgp_community_exact,
10484 show_ipv6_bgp_community2_exact_cmd,
10485 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10486 SHOW_STR
10487 IPV6_STR
10488 BGP_STR
10489 "Display routes matching the communities\n"
10490 COMMUNITY_AANN_STR
10491 "Do not send outside local AS (well-known community)\n"
10492 "Do not advertise to any peer (well-known community)\n"
10493 "Do not export to next AS (well-known community)\n"
10494 COMMUNITY_AANN_STR
10495 "Do not send outside local AS (well-known community)\n"
10496 "Do not advertise to any peer (well-known community)\n"
10497 "Do not export to next AS (well-known community)\n"
10498 "Exact match of the communities")
10499
10500 /* old command */
10501 ALIAS (show_ipv6_bgp_community_exact,
10502 show_ipv6_bgp_community3_exact_cmd,
10503 "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",
10504 SHOW_STR
10505 IPV6_STR
10506 BGP_STR
10507 "Display routes matching the communities\n"
10508 COMMUNITY_AANN_STR
10509 "Do not send outside local AS (well-known community)\n"
10510 "Do not advertise to any peer (well-known community)\n"
10511 "Do not export to next AS (well-known community)\n"
10512 COMMUNITY_AANN_STR
10513 "Do not send outside local AS (well-known community)\n"
10514 "Do not advertise to any peer (well-known community)\n"
10515 "Do not export to next AS (well-known community)\n"
10516 COMMUNITY_AANN_STR
10517 "Do not send outside local AS (well-known community)\n"
10518 "Do not advertise to any peer (well-known community)\n"
10519 "Do not export to next AS (well-known community)\n"
10520 "Exact match of the communities")
10521
10522 /* old command */
10523 ALIAS (show_ipv6_bgp_community_exact,
10524 show_ipv6_bgp_community4_exact_cmd,
10525 "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",
10526 SHOW_STR
10527 IPV6_STR
10528 BGP_STR
10529 "Display routes matching the communities\n"
10530 COMMUNITY_AANN_STR
10531 "Do not send outside local AS (well-known community)\n"
10532 "Do not advertise to any peer (well-known community)\n"
10533 "Do not export to next AS (well-known community)\n"
10534 COMMUNITY_AANN_STR
10535 "Do not send outside local AS (well-known community)\n"
10536 "Do not advertise to any peer (well-known community)\n"
10537 "Do not export to next AS (well-known community)\n"
10538 COMMUNITY_AANN_STR
10539 "Do not send outside local AS (well-known community)\n"
10540 "Do not advertise to any peer (well-known community)\n"
10541 "Do not export to next AS (well-known community)\n"
10542 COMMUNITY_AANN_STR
10543 "Do not send outside local AS (well-known community)\n"
10544 "Do not advertise to any peer (well-known community)\n"
10545 "Do not export to next AS (well-known community)\n"
10546 "Exact match of the communities")
10547
10548 /* old command */
10549 DEFUN (show_ipv6_mbgp_community,
10550 show_ipv6_mbgp_community_cmd,
10551 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10552 SHOW_STR
10553 IPV6_STR
10554 MBGP_STR
10555 "Display routes matching the communities\n"
10556 COMMUNITY_AANN_STR
10557 "Do not send outside local AS (well-known community)\n"
10558 "Do not advertise to any peer (well-known community)\n"
10559 "Do not export to next AS (well-known community)\n")
10560 {
10561 bgp_show_ipv6_bgp_deprecate_warning(vty);
10562 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10563 }
10564
10565 /* old command */
10566 ALIAS (show_ipv6_mbgp_community,
10567 show_ipv6_mbgp_community2_cmd,
10568 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10569 SHOW_STR
10570 IPV6_STR
10571 MBGP_STR
10572 "Display routes matching the communities\n"
10573 COMMUNITY_AANN_STR
10574 "Do not send outside local AS (well-known community)\n"
10575 "Do not advertise to any peer (well-known community)\n"
10576 "Do not export to next AS (well-known community)\n"
10577 COMMUNITY_AANN_STR
10578 "Do not send outside local AS (well-known community)\n"
10579 "Do not advertise to any peer (well-known community)\n"
10580 "Do not export to next AS (well-known community)\n")
10581
10582 /* old command */
10583 ALIAS (show_ipv6_mbgp_community,
10584 show_ipv6_mbgp_community3_cmd,
10585 "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)",
10586 SHOW_STR
10587 IPV6_STR
10588 MBGP_STR
10589 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10599 "Do not send outside local AS (well-known community)\n"
10600 "Do not advertise to any peer (well-known community)\n"
10601 "Do not export to next AS (well-known community)\n")
10602
10603 /* old command */
10604 ALIAS (show_ipv6_mbgp_community,
10605 show_ipv6_mbgp_community4_cmd,
10606 "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)",
10607 SHOW_STR
10608 IPV6_STR
10609 MBGP_STR
10610 "Display routes matching the communities\n"
10611 COMMUNITY_AANN_STR
10612 "Do not send outside local AS (well-known community)\n"
10613 "Do not advertise to any peer (well-known community)\n"
10614 "Do not export to next AS (well-known community)\n"
10615 COMMUNITY_AANN_STR
10616 "Do not send outside local AS (well-known community)\n"
10617 "Do not advertise to any peer (well-known community)\n"
10618 "Do not export to next AS (well-known community)\n"
10619 COMMUNITY_AANN_STR
10620 "Do not send outside local AS (well-known community)\n"
10621 "Do not advertise to any peer (well-known community)\n"
10622 "Do not export to next AS (well-known community)\n"
10623 COMMUNITY_AANN_STR
10624 "Do not send outside local AS (well-known community)\n"
10625 "Do not advertise to any peer (well-known community)\n"
10626 "Do not export to next AS (well-known community)\n")
10627
10628 /* old command */
10629 DEFUN (show_ipv6_mbgp_community_exact,
10630 show_ipv6_mbgp_community_exact_cmd,
10631 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10632 SHOW_STR
10633 IPV6_STR
10634 MBGP_STR
10635 "Display routes matching the communities\n"
10636 COMMUNITY_AANN_STR
10637 "Do not send outside local AS (well-known community)\n"
10638 "Do not advertise to any peer (well-known community)\n"
10639 "Do not export to next AS (well-known community)\n"
10640 "Exact match of the communities")
10641 {
10642 bgp_show_ipv6_bgp_deprecate_warning(vty);
10643 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10644 }
10645
10646 /* old command */
10647 ALIAS (show_ipv6_mbgp_community_exact,
10648 show_ipv6_mbgp_community2_exact_cmd,
10649 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10650 SHOW_STR
10651 IPV6_STR
10652 MBGP_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 COMMUNITY_AANN_STR
10659 "Do not send outside local AS (well-known community)\n"
10660 "Do not advertise to any peer (well-known community)\n"
10661 "Do not export to next AS (well-known community)\n"
10662 "Exact match of the communities")
10663
10664 /* old command */
10665 ALIAS (show_ipv6_mbgp_community_exact,
10666 show_ipv6_mbgp_community3_exact_cmd,
10667 "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",
10668 SHOW_STR
10669 IPV6_STR
10670 MBGP_STR
10671 "Display routes matching the communities\n"
10672 COMMUNITY_AANN_STR
10673 "Do not send outside local AS (well-known community)\n"
10674 "Do not advertise to any peer (well-known community)\n"
10675 "Do not export to next AS (well-known community)\n"
10676 COMMUNITY_AANN_STR
10677 "Do not send outside local AS (well-known community)\n"
10678 "Do not advertise to any peer (well-known community)\n"
10679 "Do not export to next AS (well-known community)\n"
10680 COMMUNITY_AANN_STR
10681 "Do not send outside local AS (well-known community)\n"
10682 "Do not advertise to any peer (well-known community)\n"
10683 "Do not export to next AS (well-known community)\n"
10684 "Exact match of the communities")
10685
10686 /* old command */
10687 ALIAS (show_ipv6_mbgp_community_exact,
10688 show_ipv6_mbgp_community4_exact_cmd,
10689 "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",
10690 SHOW_STR
10691 IPV6_STR
10692 MBGP_STR
10693 "Display routes matching the communities\n"
10694 COMMUNITY_AANN_STR
10695 "Do not send outside local AS (well-known community)\n"
10696 "Do not advertise to any peer (well-known community)\n"
10697 "Do not export to next AS (well-known community)\n"
10698 COMMUNITY_AANN_STR
10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
10702 COMMUNITY_AANN_STR
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 COMMUNITY_AANN_STR
10707 "Do not send outside local AS (well-known community)\n"
10708 "Do not advertise to any peer (well-known community)\n"
10709 "Do not export to next AS (well-known community)\n"
10710 "Exact match of the communities")
10711 #endif /* HAVE_IPV6 */
10712
10713 static int
10714 bgp_show_community_list (struct vty *vty, const char *name,
10715 const char *com, int exact,
10716 afi_t afi, safi_t safi)
10717 {
10718 struct community_list *list;
10719 struct bgp *bgp = NULL;
10720
10721 if (name && !(bgp = bgp_lookup_by_name(name)))
10722 {
10723 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10724 return CMD_WARNING;
10725 }
10726
10727 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
10728 if (list == NULL)
10729 {
10730 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10731 VTY_NEWLINE);
10732 return CMD_WARNING;
10733 }
10734
10735 return bgp_show (vty, bgp, afi, safi,
10736 (exact ? bgp_show_type_community_list_exact :
10737 bgp_show_type_community_list), list, 0);
10738 }
10739
10740 DEFUN (show_ip_bgp_community_list,
10741 show_ip_bgp_community_list_cmd,
10742 "show ip bgp community-list (<1-500>|WORD)",
10743 SHOW_STR
10744 IP_STR
10745 BGP_STR
10746 "Display routes matching the community-list\n"
10747 "community-list number\n"
10748 "community-list name\n")
10749 {
10750 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10751 }
10752
10753 DEFUN (show_ip_bgp_instance_community_list,
10754 show_ip_bgp_instance_community_list_cmd,
10755 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
10756 SHOW_STR
10757 IP_STR
10758 BGP_STR
10759 BGP_INSTANCE_HELP_STR
10760 "Display routes matching the community-list\n"
10761 "community-list number\n"
10762 "community-list name\n")
10763 {
10764 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
10765 }
10766
10767 DEFUN (show_ip_bgp_ipv4_community_list,
10768 show_ip_bgp_ipv4_community_list_cmd,
10769 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10770 SHOW_STR
10771 IP_STR
10772 BGP_STR
10773 "Address family\n"
10774 "Address Family modifier\n"
10775 "Address Family modifier\n"
10776 "Display routes matching the community-list\n"
10777 "community-list number\n"
10778 "community-list name\n")
10779 {
10780 if (strncmp (argv[0], "m", 1) == 0)
10781 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10782
10783 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
10784 }
10785
10786 DEFUN (show_ip_bgp_community_list_exact,
10787 show_ip_bgp_community_list_exact_cmd,
10788 "show ip bgp community-list (<1-500>|WORD) exact-match",
10789 SHOW_STR
10790 IP_STR
10791 BGP_STR
10792 "Display routes matching the community-list\n"
10793 "community-list number\n"
10794 "community-list name\n"
10795 "Exact match of the communities\n")
10796 {
10797 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
10798 }
10799
10800 DEFUN (show_ip_bgp_ipv4_community_list_exact,
10801 show_ip_bgp_ipv4_community_list_exact_cmd,
10802 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10803 SHOW_STR
10804 IP_STR
10805 BGP_STR
10806 "Address family\n"
10807 "Address Family modifier\n"
10808 "Address Family modifier\n"
10809 "Display routes matching the community-list\n"
10810 "community-list number\n"
10811 "community-list name\n"
10812 "Exact match of the communities\n")
10813 {
10814 if (strncmp (argv[0], "m", 1) == 0)
10815 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10816
10817 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
10818 }
10819
10820 #ifdef HAVE_IPV6
10821 DEFUN (show_bgp_community_list,
10822 show_bgp_community_list_cmd,
10823 "show bgp community-list (<1-500>|WORD)",
10824 SHOW_STR
10825 BGP_STR
10826 "Display routes matching the community-list\n"
10827 "community-list number\n"
10828 "community-list name\n")
10829 {
10830 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10831 }
10832
10833 ALIAS (show_bgp_community_list,
10834 show_bgp_ipv6_community_list_cmd,
10835 "show bgp ipv6 community-list (<1-500>|WORD)",
10836 SHOW_STR
10837 BGP_STR
10838 "Address family\n"
10839 "Display routes matching the community-list\n"
10840 "community-list number\n"
10841 "community-list name\n")
10842
10843 /* old command */
10844 DEFUN (show_ipv6_bgp_community_list,
10845 show_ipv6_bgp_community_list_cmd,
10846 "show ipv6 bgp community-list WORD",
10847 SHOW_STR
10848 IPV6_STR
10849 BGP_STR
10850 "Display routes matching the community-list\n"
10851 "community-list name\n")
10852 {
10853 bgp_show_ipv6_bgp_deprecate_warning(vty);
10854 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10855 }
10856
10857 /* old command */
10858 DEFUN (show_ipv6_mbgp_community_list,
10859 show_ipv6_mbgp_community_list_cmd,
10860 "show ipv6 mbgp community-list WORD",
10861 SHOW_STR
10862 IPV6_STR
10863 MBGP_STR
10864 "Display routes matching the community-list\n"
10865 "community-list name\n")
10866 {
10867 bgp_show_ipv6_bgp_deprecate_warning(vty);
10868 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10869 }
10870
10871 DEFUN (show_bgp_community_list_exact,
10872 show_bgp_community_list_exact_cmd,
10873 "show bgp community-list (<1-500>|WORD) exact-match",
10874 SHOW_STR
10875 BGP_STR
10876 "Display routes matching the community-list\n"
10877 "community-list number\n"
10878 "community-list name\n"
10879 "Exact match of the communities\n")
10880 {
10881 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10882 }
10883
10884 ALIAS (show_bgp_community_list_exact,
10885 show_bgp_ipv6_community_list_exact_cmd,
10886 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10887 SHOW_STR
10888 BGP_STR
10889 "Address family\n"
10890 "Display routes matching the community-list\n"
10891 "community-list number\n"
10892 "community-list name\n"
10893 "Exact match of the communities\n")
10894
10895 /* old command */
10896 DEFUN (show_ipv6_bgp_community_list_exact,
10897 show_ipv6_bgp_community_list_exact_cmd,
10898 "show ipv6 bgp community-list WORD exact-match",
10899 SHOW_STR
10900 IPV6_STR
10901 BGP_STR
10902 "Display routes matching the community-list\n"
10903 "community-list name\n"
10904 "Exact match of the communities\n")
10905 {
10906 bgp_show_ipv6_bgp_deprecate_warning(vty);
10907 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10908 }
10909
10910 /* old command */
10911 DEFUN (show_ipv6_mbgp_community_list_exact,
10912 show_ipv6_mbgp_community_list_exact_cmd,
10913 "show ipv6 mbgp community-list WORD exact-match",
10914 SHOW_STR
10915 IPV6_STR
10916 MBGP_STR
10917 "Display routes matching the community-list\n"
10918 "community-list name\n"
10919 "Exact match of the communities\n")
10920 {
10921 bgp_show_ipv6_bgp_deprecate_warning(vty);
10922 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10923 }
10924 #endif /* HAVE_IPV6 */
10925
10926 static int
10927 bgp_show_prefix_longer (struct vty *vty, const char *name,
10928 const char *prefix, afi_t afi,
10929 safi_t safi, enum bgp_show_type type)
10930 {
10931 int ret;
10932 struct prefix *p;
10933 struct bgp *bgp = NULL;
10934
10935 if (name && !(bgp = bgp_lookup_by_name(name)))
10936 {
10937 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10938 return CMD_WARNING;
10939 }
10940
10941 p = prefix_new();
10942
10943 ret = str2prefix (prefix, p);
10944 if (! ret)
10945 {
10946 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10947 return CMD_WARNING;
10948 }
10949
10950 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
10951 prefix_free(p);
10952 return ret;
10953 }
10954
10955 DEFUN (show_ip_bgp_prefix_longer,
10956 show_ip_bgp_prefix_longer_cmd,
10957 "show ip bgp A.B.C.D/M longer-prefixes",
10958 SHOW_STR
10959 IP_STR
10960 BGP_STR
10961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10962 "Display route and more specific routes\n")
10963 {
10964 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10965 bgp_show_type_prefix_longer);
10966 }
10967
10968 DEFUN (show_ip_bgp_instance_prefix_longer,
10969 show_ip_bgp_instance_prefix_longer_cmd,
10970 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
10971 SHOW_STR
10972 IP_STR
10973 BGP_STR
10974 BGP_INSTANCE_HELP_STR
10975 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10976 "Display route and more specific routes\n")
10977 {
10978 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
10979 bgp_show_type_prefix_longer);
10980 }
10981
10982 DEFUN (show_ip_bgp_flap_prefix_longer,
10983 show_ip_bgp_flap_prefix_longer_cmd,
10984 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10985 SHOW_STR
10986 IP_STR
10987 BGP_STR
10988 "Display flap statistics of routes\n"
10989 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10990 "Display route and more specific routes\n")
10991 {
10992 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10993 bgp_show_type_flap_prefix_longer);
10994 }
10995
10996 ALIAS (show_ip_bgp_flap_prefix_longer,
10997 show_ip_bgp_damp_flap_prefix_longer_cmd,
10998 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
10999 SHOW_STR
11000 IP_STR
11001 BGP_STR
11002 "Display detailed information about dampening\n"
11003 "Display flap statistics of routes\n"
11004 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11005 "Display route and more specific routes\n")
11006
11007 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11008 show_ip_bgp_ipv4_prefix_longer_cmd,
11009 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11010 SHOW_STR
11011 IP_STR
11012 BGP_STR
11013 "Address family\n"
11014 "Address Family modifier\n"
11015 "Address Family modifier\n"
11016 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11017 "Display route and more specific routes\n")
11018 {
11019 if (strncmp (argv[0], "m", 1) == 0)
11020 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
11021 bgp_show_type_prefix_longer);
11022
11023 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
11024 bgp_show_type_prefix_longer);
11025 }
11026
11027 DEFUN (show_ip_bgp_flap_address,
11028 show_ip_bgp_flap_address_cmd,
11029 "show ip bgp flap-statistics A.B.C.D",
11030 SHOW_STR
11031 IP_STR
11032 BGP_STR
11033 "Display flap statistics of routes\n"
11034 "Network in the BGP routing table to display\n")
11035 {
11036 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11037 bgp_show_type_flap_address);
11038 }
11039
11040 ALIAS (show_ip_bgp_flap_address,
11041 show_ip_bgp_damp_flap_address_cmd,
11042 "show ip bgp dampening flap-statistics A.B.C.D",
11043 SHOW_STR
11044 IP_STR
11045 BGP_STR
11046 "Display detailed information about dampening\n"
11047 "Display flap statistics of routes\n"
11048 "Network in the BGP routing table to display\n")
11049
11050 DEFUN (show_ip_bgp_flap_prefix,
11051 show_ip_bgp_flap_prefix_cmd,
11052 "show ip bgp flap-statistics A.B.C.D/M",
11053 SHOW_STR
11054 IP_STR
11055 BGP_STR
11056 "Display flap statistics of routes\n"
11057 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11058 {
11059 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11060 bgp_show_type_flap_prefix);
11061 }
11062
11063 ALIAS (show_ip_bgp_flap_prefix,
11064 show_ip_bgp_damp_flap_prefix_cmd,
11065 "show ip bgp dampening flap-statistics A.B.C.D/M",
11066 SHOW_STR
11067 IP_STR
11068 BGP_STR
11069 "Display detailed information about dampening\n"
11070 "Display flap statistics of routes\n"
11071 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11072
11073 #ifdef HAVE_IPV6
11074 DEFUN (show_bgp_prefix_longer,
11075 show_bgp_prefix_longer_cmd,
11076 "show bgp X:X::X:X/M longer-prefixes",
11077 SHOW_STR
11078 BGP_STR
11079 "IPv6 prefix <network>/<length>\n"
11080 "Display route and more specific routes\n")
11081 {
11082 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11083 bgp_show_type_prefix_longer);
11084 }
11085
11086 ALIAS (show_bgp_prefix_longer,
11087 show_bgp_ipv6_prefix_longer_cmd,
11088 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11089 SHOW_STR
11090 BGP_STR
11091 "Address family\n"
11092 "IPv6 prefix <network>/<length>\n"
11093 "Display route and more specific routes\n")
11094
11095 /* old command */
11096 DEFUN (show_ipv6_bgp_prefix_longer,
11097 show_ipv6_bgp_prefix_longer_cmd,
11098 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11099 SHOW_STR
11100 IPV6_STR
11101 BGP_STR
11102 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11103 "Display route and more specific routes\n")
11104 {
11105 bgp_show_ipv6_bgp_deprecate_warning(vty);
11106 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11107 bgp_show_type_prefix_longer);
11108 }
11109
11110 /* old command */
11111 DEFUN (show_ipv6_mbgp_prefix_longer,
11112 show_ipv6_mbgp_prefix_longer_cmd,
11113 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11114 SHOW_STR
11115 IPV6_STR
11116 MBGP_STR
11117 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11118 "Display route and more specific routes\n")
11119 {
11120 bgp_show_ipv6_bgp_deprecate_warning(vty);
11121 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11122 bgp_show_type_prefix_longer);
11123 }
11124 #endif /* HAVE_IPV6 */
11125
11126 static struct peer *
11127 peer_lookup_in_view (struct vty *vty, const char *view_name,
11128 const char *ip_str, u_char use_json)
11129 {
11130 int ret;
11131 struct bgp *bgp;
11132 struct peer *peer;
11133 union sockunion su;
11134
11135 /* BGP structure lookup. */
11136 if (view_name)
11137 {
11138 bgp = bgp_lookup_by_name (view_name);
11139 if (! bgp)
11140 {
11141 if (use_json)
11142 {
11143 json_object *json_no = NULL;
11144 json_no = json_object_new_object();
11145 json_object_string_add(json_no, "warning", "Can't find BGP view");
11146 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11147 json_object_free(json_no);
11148 }
11149 else
11150 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11151 return NULL;
11152 }
11153 }
11154 else
11155 {
11156 bgp = bgp_get_default ();
11157 if (! bgp)
11158 {
11159 if (use_json)
11160 {
11161 json_object *json_no = NULL;
11162 json_no = json_object_new_object();
11163 json_object_string_add(json_no, "warning", "No BGP process configured");
11164 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11165 json_object_free(json_no);
11166 }
11167 else
11168 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11169 return NULL;
11170 }
11171 }
11172
11173 /* Get peer sockunion. */
11174 ret = str2sockunion (ip_str, &su);
11175 if (ret < 0)
11176 {
11177 peer = peer_lookup_by_conf_if (bgp, ip_str);
11178 if (!peer)
11179 {
11180 peer = peer_lookup_by_hostname(bgp, ip_str);
11181
11182 if (!peer)
11183 {
11184 if (use_json)
11185 {
11186 json_object *json_no = NULL;
11187 json_no = json_object_new_object();
11188 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11189 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11190 json_object_free(json_no);
11191 }
11192 else
11193 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11194 return NULL;
11195 }
11196 }
11197 return peer;
11198 }
11199
11200 /* Peer structure lookup. */
11201 peer = peer_lookup (bgp, &su);
11202 if (! peer)
11203 {
11204 if (use_json)
11205 {
11206 json_object *json_no = NULL;
11207 json_no = json_object_new_object();
11208 json_object_string_add(json_no, "warning","No such neighbor");
11209 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11210 json_object_free(json_no);
11211 }
11212 else
11213 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11214 return NULL;
11215 }
11216
11217 return peer;
11218 }
11219
11220 enum bgp_stats
11221 {
11222 BGP_STATS_MAXBITLEN = 0,
11223 BGP_STATS_RIB,
11224 BGP_STATS_PREFIXES,
11225 BGP_STATS_TOTPLEN,
11226 BGP_STATS_UNAGGREGATEABLE,
11227 BGP_STATS_MAX_AGGREGATEABLE,
11228 BGP_STATS_AGGREGATES,
11229 BGP_STATS_SPACE,
11230 BGP_STATS_ASPATH_COUNT,
11231 BGP_STATS_ASPATH_MAXHOPS,
11232 BGP_STATS_ASPATH_TOTHOPS,
11233 BGP_STATS_ASPATH_MAXSIZE,
11234 BGP_STATS_ASPATH_TOTSIZE,
11235 BGP_STATS_ASN_HIGHEST,
11236 BGP_STATS_MAX,
11237 };
11238
11239 static const char *table_stats_strs[] =
11240 {
11241 [BGP_STATS_PREFIXES] = "Total Prefixes",
11242 [BGP_STATS_TOTPLEN] = "Average prefix length",
11243 [BGP_STATS_RIB] = "Total Advertisements",
11244 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11245 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11246 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11247 [BGP_STATS_SPACE] = "Address space advertised",
11248 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11249 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11250 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11251 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11252 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11253 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11254 [BGP_STATS_MAX] = NULL,
11255 };
11256
11257 struct bgp_table_stats
11258 {
11259 struct bgp_table *table;
11260 unsigned long long counts[BGP_STATS_MAX];
11261 };
11262
11263 #if 0
11264 #define TALLY_SIGFIG 100000
11265 static unsigned long
11266 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11267 {
11268 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11269 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11270 unsigned long ret = newtot / count;
11271
11272 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11273 return ret + 1;
11274 else
11275 return ret;
11276 }
11277 #endif
11278
11279 static int
11280 bgp_table_stats_walker (struct thread *t)
11281 {
11282 struct bgp_node *rn;
11283 struct bgp_node *top;
11284 struct bgp_table_stats *ts = THREAD_ARG (t);
11285 unsigned int space = 0;
11286
11287 if (!(top = bgp_table_top (ts->table)))
11288 return 0;
11289
11290 switch (top->p.family)
11291 {
11292 case AF_INET:
11293 space = IPV4_MAX_BITLEN;
11294 break;
11295 case AF_INET6:
11296 space = IPV6_MAX_BITLEN;
11297 break;
11298 }
11299
11300 ts->counts[BGP_STATS_MAXBITLEN] = space;
11301
11302 for (rn = top; rn; rn = bgp_route_next (rn))
11303 {
11304 struct bgp_info *ri;
11305 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11306 unsigned int rinum = 0;
11307
11308 if (rn == top)
11309 continue;
11310
11311 if (!rn->info)
11312 continue;
11313
11314 ts->counts[BGP_STATS_PREFIXES]++;
11315 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11316
11317 #if 0
11318 ts->counts[BGP_STATS_AVGPLEN]
11319 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11320 ts->counts[BGP_STATS_AVGPLEN],
11321 rn->p.prefixlen);
11322 #endif
11323
11324 /* check if the prefix is included by any other announcements */
11325 while (prn && !prn->info)
11326 prn = bgp_node_parent_nolock (prn);
11327
11328 if (prn == NULL || prn == top)
11329 {
11330 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11331 /* announced address space */
11332 if (space)
11333 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11334 }
11335 else if (prn->info)
11336 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11337
11338 for (ri = rn->info; ri; ri = ri->next)
11339 {
11340 rinum++;
11341 ts->counts[BGP_STATS_RIB]++;
11342
11343 if (ri->attr &&
11344 (CHECK_FLAG (ri->attr->flag,
11345 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11346 ts->counts[BGP_STATS_AGGREGATES]++;
11347
11348 /* as-path stats */
11349 if (ri->attr && ri->attr->aspath)
11350 {
11351 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11352 unsigned int size = aspath_size (ri->attr->aspath);
11353 as_t highest = aspath_highest (ri->attr->aspath);
11354
11355 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11356
11357 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11358 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11359
11360 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11361 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11362
11363 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11364 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11365 #if 0
11366 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11367 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11368 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11369 hops);
11370 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11371 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11372 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11373 size);
11374 #endif
11375 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11376 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11377 }
11378 }
11379 }
11380 return 0;
11381 }
11382
11383 static int
11384 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11385 {
11386 struct bgp_table_stats ts;
11387 unsigned int i;
11388
11389 if (!bgp->rib[afi][safi])
11390 {
11391 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11392 afi, safi, VTY_NEWLINE);
11393 return CMD_WARNING;
11394 }
11395
11396 memset (&ts, 0, sizeof (ts));
11397 ts.table = bgp->rib[afi][safi];
11398 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11399
11400 vty_out (vty, "BGP %s RIB statistics%s%s",
11401 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11402
11403 for (i = 0; i < BGP_STATS_MAX; i++)
11404 {
11405 if (!table_stats_strs[i])
11406 continue;
11407
11408 switch (i)
11409 {
11410 #if 0
11411 case BGP_STATS_ASPATH_AVGHOPS:
11412 case BGP_STATS_ASPATH_AVGSIZE:
11413 case BGP_STATS_AVGPLEN:
11414 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11415 vty_out (vty, "%12.2f",
11416 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11417 break;
11418 #endif
11419 case BGP_STATS_ASPATH_TOTHOPS:
11420 case BGP_STATS_ASPATH_TOTSIZE:
11421 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11422 vty_out (vty, "%12.2f",
11423 ts.counts[i] ?
11424 (float)ts.counts[i] /
11425 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11426 : 0);
11427 break;
11428 case BGP_STATS_TOTPLEN:
11429 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11430 vty_out (vty, "%12.2f",
11431 ts.counts[i] ?
11432 (float)ts.counts[i] /
11433 (float)ts.counts[BGP_STATS_PREFIXES]
11434 : 0);
11435 break;
11436 case BGP_STATS_SPACE:
11437 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11438 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11439 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11440 break;
11441 vty_out (vty, "%30s: ", "%% announced ");
11442 vty_out (vty, "%12.2f%s",
11443 100 * (float)ts.counts[BGP_STATS_SPACE] /
11444 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11445 VTY_NEWLINE);
11446 vty_out (vty, "%30s: ", "/8 equivalent ");
11447 vty_out (vty, "%12.2f%s",
11448 (float)ts.counts[BGP_STATS_SPACE] /
11449 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11450 VTY_NEWLINE);
11451 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11452 break;
11453 vty_out (vty, "%30s: ", "/24 equivalent ");
11454 vty_out (vty, "%12.2f",
11455 (float)ts.counts[BGP_STATS_SPACE] /
11456 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11457 break;
11458 default:
11459 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11460 vty_out (vty, "%12llu", ts.counts[i]);
11461 }
11462
11463 vty_out (vty, "%s", VTY_NEWLINE);
11464 }
11465 return CMD_SUCCESS;
11466 }
11467
11468 static int
11469 bgp_table_stats_vty (struct vty *vty, const char *name,
11470 const char *afi_str, const char *safi_str)
11471 {
11472 struct bgp *bgp;
11473 afi_t afi;
11474 safi_t safi;
11475
11476 if (name)
11477 bgp = bgp_lookup_by_name (name);
11478 else
11479 bgp = bgp_get_default ();
11480
11481 if (!bgp)
11482 {
11483 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11484 return CMD_WARNING;
11485 }
11486 if (strncmp (afi_str, "ipv", 3) == 0)
11487 {
11488 if (strncmp (afi_str, "ipv4", 4) == 0)
11489 afi = AFI_IP;
11490 else if (strncmp (afi_str, "ipv6", 4) == 0)
11491 afi = AFI_IP6;
11492 else
11493 {
11494 vty_out (vty, "%% Invalid address family %s%s",
11495 afi_str, VTY_NEWLINE);
11496 return CMD_WARNING;
11497 }
11498 if (strncmp (safi_str, "m", 1) == 0)
11499 safi = SAFI_MULTICAST;
11500 else if (strncmp (safi_str, "u", 1) == 0)
11501 safi = SAFI_UNICAST;
11502 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11503 safi = SAFI_MPLS_VPN;
11504 else
11505 {
11506 vty_out (vty, "%% Invalid subsequent address family %s%s",
11507 safi_str, VTY_NEWLINE);
11508 return CMD_WARNING;
11509 }
11510 }
11511 else
11512 {
11513 vty_out (vty, "%% Invalid address family %s%s",
11514 afi_str, VTY_NEWLINE);
11515 return CMD_WARNING;
11516 }
11517
11518 return bgp_table_stats (vty, bgp, afi, safi);
11519 }
11520
11521 DEFUN (show_bgp_statistics,
11522 show_bgp_statistics_cmd,
11523 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11524 SHOW_STR
11525 BGP_STR
11526 "Address family\n"
11527 "Address family\n"
11528 "Address Family modifier\n"
11529 "Address Family modifier\n"
11530 "BGP RIB advertisement statistics\n")
11531 {
11532 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11533 }
11534
11535 ALIAS (show_bgp_statistics,
11536 show_bgp_statistics_vpnv4_cmd,
11537 "show bgp (ipv4) (vpnv4) statistics",
11538 SHOW_STR
11539 BGP_STR
11540 "Address family\n"
11541 "Address Family modifier\n"
11542 "BGP RIB advertisement statistics\n")
11543
11544 DEFUN (show_bgp_statistics_view,
11545 show_bgp_statistics_view_cmd,
11546 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) statistics",
11547 SHOW_STR
11548 BGP_STR
11549 BGP_INSTANCE_HELP_STR
11550 "Address family\n"
11551 "Address family\n"
11552 "Address Family modifier\n"
11553 "Address Family modifier\n"
11554 "BGP RIB advertisement statistics\n")
11555 {
11556 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11557 }
11558
11559 ALIAS (show_bgp_statistics_view,
11560 show_bgp_statistics_view_vpnv4_cmd,
11561 "show bgp " BGP_INSTANCE_CMD " (ipv4) (vpnv4) statistics",
11562 SHOW_STR
11563 BGP_STR
11564 BGP_INSTANCE_HELP_STR
11565 "Address family\n"
11566 "Address Family modifier\n"
11567 "BGP RIB advertisement statistics\n")
11568
11569 enum bgp_pcounts
11570 {
11571 PCOUNT_ADJ_IN = 0,
11572 PCOUNT_DAMPED,
11573 PCOUNT_REMOVED,
11574 PCOUNT_HISTORY,
11575 PCOUNT_STALE,
11576 PCOUNT_VALID,
11577 PCOUNT_ALL,
11578 PCOUNT_COUNTED,
11579 PCOUNT_PFCNT, /* the figure we display to users */
11580 PCOUNT_MAX,
11581 };
11582
11583 static const char *pcount_strs[] =
11584 {
11585 [PCOUNT_ADJ_IN] = "Adj-in",
11586 [PCOUNT_DAMPED] = "Damped",
11587 [PCOUNT_REMOVED] = "Removed",
11588 [PCOUNT_HISTORY] = "History",
11589 [PCOUNT_STALE] = "Stale",
11590 [PCOUNT_VALID] = "Valid",
11591 [PCOUNT_ALL] = "All RIB",
11592 [PCOUNT_COUNTED] = "PfxCt counted",
11593 [PCOUNT_PFCNT] = "Useable",
11594 [PCOUNT_MAX] = NULL,
11595 };
11596
11597 struct peer_pcounts
11598 {
11599 unsigned int count[PCOUNT_MAX];
11600 const struct peer *peer;
11601 const struct bgp_table *table;
11602 };
11603
11604 static int
11605 bgp_peer_count_walker (struct thread *t)
11606 {
11607 struct bgp_node *rn;
11608 struct peer_pcounts *pc = THREAD_ARG (t);
11609 const struct peer *peer = pc->peer;
11610
11611 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11612 {
11613 struct bgp_adj_in *ain;
11614 struct bgp_info *ri;
11615
11616 for (ain = rn->adj_in; ain; ain = ain->next)
11617 if (ain->peer == peer)
11618 pc->count[PCOUNT_ADJ_IN]++;
11619
11620 for (ri = rn->info; ri; ri = ri->next)
11621 {
11622 char buf[SU_ADDRSTRLEN];
11623
11624 if (ri->peer != peer)
11625 continue;
11626
11627 pc->count[PCOUNT_ALL]++;
11628
11629 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11630 pc->count[PCOUNT_DAMPED]++;
11631 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11632 pc->count[PCOUNT_HISTORY]++;
11633 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11634 pc->count[PCOUNT_REMOVED]++;
11635 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11636 pc->count[PCOUNT_STALE]++;
11637 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11638 pc->count[PCOUNT_VALID]++;
11639 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11640 pc->count[PCOUNT_PFCNT]++;
11641
11642 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11643 {
11644 pc->count[PCOUNT_COUNTED]++;
11645 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11646 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
11647 peer->host,
11648 inet_ntop(rn->p.family, &rn->p.u.prefix,
11649 buf, SU_ADDRSTRLEN),
11650 rn->p.prefixlen,
11651 ri->flags);
11652 }
11653 else
11654 {
11655 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11656 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
11657 peer->host,
11658 inet_ntop(rn->p.family, &rn->p.u.prefix,
11659 buf, SU_ADDRSTRLEN),
11660 rn->p.prefixlen,
11661 ri->flags);
11662 }
11663 }
11664 }
11665 return 0;
11666 }
11667
11668 static int
11669 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
11670 {
11671 struct peer_pcounts pcounts = { .peer = peer };
11672 unsigned int i;
11673 json_object *json = NULL;
11674 json_object *json_loop = NULL;
11675
11676 if (use_json)
11677 {
11678 json = json_object_new_object();
11679 json_loop = json_object_new_object();
11680 }
11681
11682 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11683 || !peer->bgp->rib[afi][safi])
11684 {
11685 if (use_json)
11686 {
11687 json_object_string_add(json, "warning", "No such neighbor or address family");
11688 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11689 json_object_free(json);
11690 }
11691 else
11692 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11693
11694 return CMD_WARNING;
11695 }
11696
11697 memset (&pcounts, 0, sizeof(pcounts));
11698 pcounts.peer = peer;
11699 pcounts.table = peer->bgp->rib[afi][safi];
11700
11701 /* in-place call via thread subsystem so as to record execution time
11702 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11703 * * on just vty_read()).
11704 * */
11705 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11706
11707 if (use_json)
11708 {
11709 json_object_string_add(json, "prefixCountsFor", peer->host);
11710 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11711 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11712
11713 for (i = 0; i < PCOUNT_MAX; i++)
11714 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
11715
11716 json_object_object_add(json, "ribTableWalkCounters", json_loop);
11717
11718 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11719 {
11720 json_object_string_add(json, "pfxctDriftFor", peer->host);
11721 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11722 }
11723 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11724 json_object_free(json);
11725 }
11726 else
11727 {
11728
11729 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11730 {
11731 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11732 peer->hostname, peer->host, afi_safi_print (afi, safi),
11733 VTY_NEWLINE);
11734 }
11735 else
11736 {
11737 vty_out (vty, "Prefix counts for %s, %s%s",
11738 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11739 }
11740
11741 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11742 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11743 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11744
11745 for (i = 0; i < PCOUNT_MAX; i++)
11746 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11747
11748 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11749 {
11750 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11751 peer->host, VTY_NEWLINE);
11752 vty_out (vty, "Please report this bug, with the above command output%s",
11753 VTY_NEWLINE);
11754 }
11755 }
11756
11757 return CMD_SUCCESS;
11758 }
11759
11760 DEFUN (show_ip_bgp_neighbor_prefix_counts,
11761 show_ip_bgp_neighbor_prefix_counts_cmd,
11762 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11763 SHOW_STR
11764 IP_STR
11765 BGP_STR
11766 "Detailed information on TCP and BGP neighbor connections\n"
11767 "Neighbor to display information about\n"
11768 "Neighbor to display information about\n"
11769 "Neighbor on bgp configured interface\n"
11770 "Display detailed prefix count information\n"
11771 "JavaScript Object Notation\n")
11772 {
11773 struct peer *peer;
11774 u_char uj = use_json(argc, argv);
11775
11776 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11777 if (! peer)
11778 return CMD_WARNING;
11779
11780 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11781 }
11782
11783 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11784 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11785 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11786 SHOW_STR
11787 IP_STR
11788 BGP_STR
11789 BGP_INSTANCE_HELP_STR
11790 "Detailed information on TCP and BGP neighbor connections\n"
11791 "Neighbor to display information about\n"
11792 "Neighbor to display information about\n"
11793 "Neighbor on bgp configured interface\n"
11794 "Display detailed prefix count information\n"
11795 "JavaScript Object Notation\n")
11796 {
11797 struct peer *peer;
11798 u_char uj = use_json(argc, argv);
11799
11800 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11801 if (! peer)
11802 return CMD_WARNING;
11803
11804 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11805 }
11806
11807 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11808 show_bgp_ipv6_neighbor_prefix_counts_cmd,
11809 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11810 SHOW_STR
11811 BGP_STR
11812 "Address family\n"
11813 "Detailed information on TCP and BGP neighbor connections\n"
11814 "Neighbor to display information about\n"
11815 "Neighbor to display information about\n"
11816 "Neighbor on bgp configured interface\n"
11817 "Display detailed prefix count information\n"
11818 "JavaScript Object Notation\n")
11819 {
11820 struct peer *peer;
11821 u_char uj = use_json(argc, argv);
11822
11823 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11824 if (! peer)
11825 return CMD_WARNING;
11826
11827 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11828 }
11829
11830 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11831 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11832 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11833 SHOW_STR
11834 BGP_STR
11835 BGP_INSTANCE_HELP_STR
11836 "Address family\n"
11837 "Detailed information on TCP and BGP neighbor connections\n"
11838 "Neighbor to display information about\n"
11839 "Neighbor to display information about\n"
11840 "Neighbor on bgp configured interface\n"
11841 "Display detailed prefix count information\n"
11842 "JavaScript Object Notation\n")
11843 {
11844 struct peer *peer;
11845 u_char uj = use_json(argc, argv);
11846
11847 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11848 if (! peer)
11849 return CMD_WARNING;
11850
11851 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11852 }
11853
11854 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11855 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
11856 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11857 SHOW_STR
11858 IP_STR
11859 BGP_STR
11860 "Address family\n"
11861 "Address Family modifier\n"
11862 "Address Family modifier\n"
11863 "Detailed information on TCP and BGP neighbor connections\n"
11864 "Neighbor to display information about\n"
11865 "Neighbor to display information about\n"
11866 "Neighbor on bgp configured interface\n"
11867 "Display detailed prefix count information\n"
11868 "JavaScript Object Notation\n")
11869 {
11870 struct peer *peer;
11871 u_char uj = use_json(argc, argv);
11872
11873 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11874 if (! peer)
11875 return CMD_WARNING;
11876
11877 if (strncmp (argv[0], "m", 1) == 0)
11878 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
11879
11880 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11881 }
11882
11883 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11884 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
11885 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11886 SHOW_STR
11887 IP_STR
11888 BGP_STR
11889 "Address family\n"
11890 "Address Family modifier\n"
11891 "Address Family modifier\n"
11892 "Detailed information on TCP and BGP neighbor connections\n"
11893 "Neighbor to display information about\n"
11894 "Neighbor to display information about\n"
11895 "Neighbor on bgp configured interface\n"
11896 "Display detailed prefix count information\n"
11897 "JavaScript Object Notation\n")
11898 {
11899 struct peer *peer;
11900 u_char uj = use_json(argc, argv);
11901
11902 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11903 if (! peer)
11904 return CMD_WARNING;
11905
11906 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
11907 }
11908
11909 static void
11910 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11911 int in, const char *rmap_name, u_char use_json, json_object *json)
11912 {
11913 struct bgp_table *table;
11914 struct bgp_adj_in *ain;
11915 struct bgp_adj_out *adj;
11916 unsigned long output_count;
11917 unsigned long filtered_count;
11918 struct bgp_node *rn;
11919 int header1 = 1;
11920 struct bgp *bgp;
11921 int header2 = 1;
11922 struct attr attr;
11923 struct attr_extra extra;
11924 int ret;
11925 struct update_subgroup *subgrp;
11926 json_object *json_scode = NULL;
11927 json_object *json_ocode = NULL;
11928 json_object *json_ar = NULL;
11929 struct peer_af *paf;
11930
11931 if (use_json)
11932 {
11933 json_scode = json_object_new_object();
11934 json_ocode = json_object_new_object();
11935 json_ar = json_object_new_object();
11936
11937 json_object_string_add(json_scode, "suppressed", "s");
11938 json_object_string_add(json_scode, "damped", "d");
11939 json_object_string_add(json_scode, "history", "h");
11940 json_object_string_add(json_scode, "valid", "*");
11941 json_object_string_add(json_scode, "best", ">");
11942 json_object_string_add(json_scode, "multipath", "=");
11943 json_object_string_add(json_scode, "internal", "i");
11944 json_object_string_add(json_scode, "ribFailure", "r");
11945 json_object_string_add(json_scode, "stale", "S");
11946 json_object_string_add(json_scode, "removed", "R");
11947
11948 json_object_string_add(json_ocode, "igp", "i");
11949 json_object_string_add(json_ocode, "egp", "e");
11950 json_object_string_add(json_ocode, "incomplete", "?");
11951 }
11952
11953 bgp = peer->bgp;
11954
11955 if (! bgp)
11956 {
11957 if (use_json)
11958 {
11959 json_object_string_add(json, "alert", "no BGP");
11960 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11961 json_object_free(json);
11962 }
11963 else
11964 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11965 return;
11966 }
11967
11968 table = bgp->rib[afi][safi];
11969
11970 output_count = filtered_count = 0;
11971 subgrp = peer_subgroup(peer, afi, safi);
11972
11973 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
11974 {
11975 if (use_json)
11976 {
11977 json_object_int_add(json, "bgpTableVersion", table->version);
11978 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11979 json_object_object_add(json, "bgpStatusCodes", json_scode);
11980 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11981 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11982 }
11983 else
11984 {
11985 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11986 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11987 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11988
11989 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11990 VTY_NEWLINE, VTY_NEWLINE);
11991 }
11992 header1 = 0;
11993 }
11994
11995 attr.extra = &extra;
11996 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11997 {
11998 if (in)
11999 {
12000 for (ain = rn->adj_in; ain; ain = ain->next)
12001 {
12002 if (ain->peer == peer)
12003 {
12004 if (header1)
12005 {
12006 if (use_json)
12007 {
12008 json_object_int_add(json, "bgpTableVersion", 0);
12009 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12010 json_object_object_add(json, "bgpStatusCodes", json_scode);
12011 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12012 }
12013 else
12014 {
12015 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12016 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12017 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12018 }
12019 header1 = 0;
12020 }
12021 if (header2)
12022 {
12023 if (!use_json)
12024 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12025 header2 = 0;
12026 }
12027 if (ain->attr)
12028 {
12029 bgp_attr_dup(&attr, ain->attr);
12030 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12031 {
12032 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12033 output_count++;
12034 }
12035 else
12036 filtered_count++;
12037 }
12038 }
12039 }
12040 }
12041 else
12042 {
12043 for (adj = rn->adj_out; adj; adj = adj->next)
12044 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12045 if (paf->peer == peer)
12046 {
12047 if (header1)
12048 {
12049 if (use_json)
12050 {
12051 json_object_int_add(json, "bgpTableVersion", table->version);
12052 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12053 json_object_object_add(json, "bgpStatusCodes", json_scode);
12054 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12055 }
12056 else
12057 {
12058 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12059 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12060 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12061 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12062 }
12063 header1 = 0;
12064 }
12065
12066 if (header2)
12067 {
12068 if (!use_json)
12069 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12070 header2 = 0;
12071 }
12072
12073 if (adj->attr)
12074 {
12075 bgp_attr_dup(&attr, adj->attr);
12076 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12077 if (ret != RMAP_DENY)
12078 {
12079 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12080 output_count++;
12081 }
12082 else
12083 filtered_count++;
12084 }
12085 }
12086 }
12087 }
12088 if (use_json)
12089 json_object_object_add(json, "advertisedRoutes", json_ar);
12090
12091 if (output_count != 0)
12092 {
12093 if (use_json)
12094 json_object_int_add(json, "totalPrefixCounter", output_count);
12095 else
12096 vty_out (vty, "%sTotal number of prefixes %ld%s",
12097 VTY_NEWLINE, output_count, VTY_NEWLINE);
12098 }
12099 if (use_json)
12100 {
12101 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12102 json_object_free(json);
12103 }
12104
12105 }
12106
12107 static int
12108 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12109 int in, const char *rmap_name, u_char use_json)
12110 {
12111 json_object *json = NULL;
12112
12113 if (use_json)
12114 json = json_object_new_object();
12115
12116 if (!peer || !peer->afc[afi][safi])
12117 {
12118 if (use_json)
12119 {
12120 json_object_string_add(json, "warning", "No such neighbor or address family");
12121 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12122 json_object_free(json);
12123 }
12124 else
12125 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12126
12127 return CMD_WARNING;
12128 }
12129
12130 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12131 {
12132 if (use_json)
12133 {
12134 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12135 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12136 json_object_free(json);
12137 }
12138 else
12139 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12140
12141 return CMD_WARNING;
12142 }
12143
12144 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12145
12146 return CMD_SUCCESS;
12147 }
12148
12149 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12150 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12151 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12152 SHOW_STR
12153 IP_STR
12154 BGP_STR
12155 BGP_INSTANCE_HELP_STR
12156 "Detailed information on TCP and BGP neighbor connections\n"
12157 "Neighbor to display information about\n"
12158 "Neighbor to display information about\n"
12159 "Display the routes advertised to a BGP neighbor\n"
12160 "JavaScript Object Notation\n")
12161 {
12162 struct peer *peer;
12163 u_char uj = use_json(argc, argv);
12164
12165 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12166 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12167 else
12168 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12169
12170 if (! peer)
12171 return CMD_WARNING;
12172
12173 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12174 }
12175
12176 DEFUN (show_ip_bgp_neighbor_advertised_route,
12177 show_ip_bgp_neighbor_advertised_route_cmd,
12178 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12179 SHOW_STR
12180 IP_STR
12181 BGP_STR
12182 "Detailed information on TCP and BGP neighbor connections\n"
12183 "Neighbor to display information about\n"
12184 "Neighbor to display information about\n"
12185 "Neighbor on bgp configured interface\n"
12186 "Display the routes advertised to a BGP neighbor\n"
12187 "JavaScript Object Notation\n")
12188
12189 {
12190 struct peer *peer;
12191 const char *rmap_name = NULL;
12192 u_char uj = use_json(argc, argv);
12193
12194 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12195
12196 if (! peer)
12197 return CMD_WARNING;
12198
12199 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12200 || (argc == 3))
12201 rmap_name = argv[1];
12202
12203 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12204 }
12205
12206 ALIAS (show_ip_bgp_neighbor_advertised_route,
12207 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12208 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12209 SHOW_STR
12210 IP_STR
12211 BGP_STR
12212 "Detailed information on TCP and BGP neighbor connections\n"
12213 "Neighbor to display information about\n"
12214 "Neighbor to display information about\n"
12215 "Neighbor on bgp configured interface\n"
12216 "Display the routes advertised to a BGP neighbor\n"
12217 "JavaScript Object Notation\n")
12218
12219 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12220 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12221 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12222 SHOW_STR
12223 IP_STR
12224 BGP_STR
12225 BGP_INSTANCE_HELP_STR
12226 "Detailed information on TCP and BGP neighbor connections\n"
12227 "Neighbor to display information about\n"
12228 "Neighbor to display information about\n"
12229 "Neighbor on bgp configured interface\n"
12230 "Display the routes advertised to a BGP neighbor\n"
12231 "JavaScript Object Notation\n")
12232 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12233 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12234 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12235 SHOW_STR
12236 IP_STR
12237 BGP_STR
12238 "Address family\n"
12239 "Address Family modifier\n"
12240 "Address Family modifier\n"
12241 "Detailed information on TCP and BGP neighbor connections\n"
12242 "Neighbor to display information about\n"
12243 "Neighbor to display information about\n"
12244 "Neighbor on bgp configured interface\n"
12245 "Display the routes advertised to a BGP neighbor\n"
12246 "JavaScript Object Notation\n")
12247 {
12248 struct peer *peer;
12249 const char *rmap_name = NULL;
12250 u_char uj = use_json(argc, argv);
12251
12252 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12253 if (! peer)
12254 return CMD_WARNING;
12255
12256 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12257 rmap_name = argv[2];
12258
12259 if (strncmp (argv[0], "m", 1) == 0)
12260 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
12261 else
12262 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12263 }
12264
12265 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12266 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12267 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12268 SHOW_STR
12269 IP_STR
12270 BGP_STR
12271 "Address family\n"
12272 "Address Family modifier\n"
12273 "Address Family modifier\n"
12274 "Detailed information on TCP and BGP neighbor connections\n"
12275 "Neighbor to display information about\n"
12276 "Neighbor to display information about\n"
12277 "Neighbor on bgp configured interface\n"
12278 "Display the routes advertised to a BGP neighbor\n"
12279 "Route-map to control what is displayed\n"
12280 "JavaScript Object Notation\n")
12281
12282 #ifdef HAVE_IPV6
12283 DEFUN (show_bgp_instance_neighbor_advertised_route,
12284 show_bgp_instance_neighbor_advertised_route_cmd,
12285 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12286 SHOW_STR
12287 BGP_STR
12288 BGP_INSTANCE_HELP_STR
12289 "Detailed information on TCP and BGP neighbor connections\n"
12290 "Neighbor to display information about\n"
12291 "Neighbor to display information about\n"
12292 "Neighbor on bgp configured interface\n"
12293 "Display the routes advertised to a BGP neighbor\n"
12294 "JavaScript Object Notation\n")
12295 {
12296 struct peer *peer;
12297 u_char uj = use_json(argc, argv);
12298
12299 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12300 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12301 else
12302 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12303
12304 if (! peer)
12305 return CMD_WARNING;
12306
12307 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12308 }
12309
12310 ALIAS (show_bgp_instance_neighbor_advertised_route,
12311 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12312 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12313 SHOW_STR
12314 BGP_STR
12315 BGP_INSTANCE_HELP_STR
12316 "Address family\n"
12317 "Detailed information on TCP and BGP neighbor connections\n"
12318 "Neighbor to display information about\n"
12319 "Neighbor to display information about\n"
12320 "Neighbor on bgp configured interface\n"
12321 "Display the routes advertised to a BGP neighbor\n"
12322 "JavaScript Object Notation\n")
12323
12324 DEFUN (show_bgp_neighbor_advertised_route,
12325 show_bgp_neighbor_advertised_route_cmd,
12326 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12327 SHOW_STR
12328 BGP_STR
12329 "Detailed information on TCP and BGP neighbor connections\n"
12330 "Neighbor to display information about\n"
12331 "Neighbor to display information about\n"
12332 "Neighbor on bgp configured interface\n"
12333 "Display the routes advertised to a BGP neighbor\n"
12334 "JavaScript Object Notation\n")
12335
12336 {
12337 struct peer *peer;
12338 const char *rmap_name = NULL;
12339 u_char uj = use_json(argc, argv);
12340
12341 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12342
12343 if (!peer)
12344 return CMD_WARNING;
12345
12346 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12347 rmap_name = argv[1];
12348
12349 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12350 }
12351
12352 ALIAS (show_bgp_neighbor_advertised_route,
12353 show_bgp_ipv6_neighbor_advertised_route_cmd,
12354 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12355 SHOW_STR
12356 BGP_STR
12357 "Address family\n"
12358 "Detailed information on TCP and BGP neighbor connections\n"
12359 "Neighbor to display information about\n"
12360 "Neighbor to display information about\n"
12361 "Neighbor on bgp configured interface\n"
12362 "Display the routes advertised to a BGP neighbor\n"
12363 "JavaScript Object Notation\n")
12364
12365 /* old command */
12366 ALIAS (show_bgp_neighbor_advertised_route,
12367 ipv6_bgp_neighbor_advertised_route_cmd,
12368 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12369 SHOW_STR
12370 IPV6_STR
12371 BGP_STR
12372 "Detailed information on TCP and BGP neighbor connections\n"
12373 "Neighbor to display information about\n"
12374 "Neighbor to display information about\n"
12375 "Neighbor on bgp configured interface\n"
12376 "Display the routes advertised to a BGP neighbor\n"
12377 "JavaScript Object Notation\n")
12378
12379 /* old command */
12380 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12381 ipv6_mbgp_neighbor_advertised_route_cmd,
12382 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12383 SHOW_STR
12384 IPV6_STR
12385 MBGP_STR
12386 "Detailed information on TCP and BGP neighbor connections\n"
12387 "Neighbor to display information about\n"
12388 "Neighbor to display information about\n"
12389 "Neighbor on bgp configured interface\n"
12390 "Neighbor on bgp configured interface\n"
12391 "Display the routes advertised to a BGP neighbor\n"
12392 "JavaScript Object Notation\n")
12393 {
12394 struct peer *peer;
12395 u_char uj = use_json(argc, argv);
12396
12397 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12398 if (! peer)
12399 return CMD_WARNING;
12400
12401 bgp_show_ipv6_bgp_deprecate_warning(vty);
12402 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12403 }
12404 #endif /* HAVE_IPV6 */
12405
12406 DEFUN (show_bgp_instance_neighbor_received_routes,
12407 show_bgp_instance_neighbor_received_routes_cmd,
12408 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12409 SHOW_STR
12410 BGP_STR
12411 BGP_INSTANCE_HELP_STR
12412 "Detailed information on TCP and BGP neighbor connections\n"
12413 "Neighbor to display information about\n"
12414 "Neighbor to display information about\n"
12415 "Neighbor on bgp configured interface\n"
12416 "Display the received routes from neighbor\n"
12417 "JavaScript Object Notation\n")
12418 {
12419 struct peer *peer;
12420 u_char uj = use_json(argc, argv);
12421
12422 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12423 if (! peer)
12424 return CMD_WARNING;
12425
12426 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12427 }
12428
12429 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12430 show_ip_bgp_instance_neighbor_received_routes_cmd,
12431 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12432 SHOW_STR
12433 IP_STR
12434 BGP_STR
12435 BGP_INSTANCE_HELP_STR
12436 "Detailed information on TCP and BGP neighbor connections\n"
12437 "Neighbor to display information about\n"
12438 "Neighbor to display information about\n"
12439 "Neighbor on bgp configured interface\n"
12440 "Display the received routes from neighbor\n"
12441 "JavaScript Object Notation\n")
12442 {
12443 struct peer *peer;
12444 u_char uj = use_json(argc, argv);
12445
12446 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12447 if (! peer)
12448 return CMD_WARNING;
12449
12450 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12451 }
12452
12453 ALIAS (show_bgp_instance_neighbor_received_routes,
12454 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12455 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12456 SHOW_STR
12457 BGP_STR
12458 BGP_INSTANCE_HELP_STR
12459 "Address family\n"
12460 "Detailed information on TCP and BGP neighbor connections\n"
12461 "Neighbor to display information about\n"
12462 "Neighbor to display information about\n"
12463 "Neighbor on bgp configured interface\n"
12464 "Display the received routes from neighbor\n"
12465 "JavaScript Object Notation\n")
12466
12467 DEFUN (show_ip_bgp_neighbor_received_routes,
12468 show_ip_bgp_neighbor_received_routes_cmd,
12469 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12470 SHOW_STR
12471 IP_STR
12472 BGP_STR
12473 "Detailed information on TCP and BGP neighbor connections\n"
12474 "Neighbor to display information about\n"
12475 "Neighbor to display information about\n"
12476 "Neighbor on bgp configured interface\n"
12477 "Display the received routes from neighbor\n"
12478 "JavaScript Object Notation\n")
12479
12480 {
12481 struct peer *peer;
12482 const char *rmap_name = NULL;
12483 u_char uj = use_json(argc, argv);
12484
12485 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12486
12487 if (! peer)
12488 return CMD_WARNING;
12489
12490 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12491 rmap_name = argv[1];
12492
12493 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12494 }
12495
12496 ALIAS (show_ip_bgp_neighbor_received_routes,
12497 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12498 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12499 SHOW_STR
12500 IP_STR
12501 BGP_STR
12502 "Detailed information on TCP and BGP neighbor connections\n"
12503 "Neighbor to display information about\n"
12504 "Neighbor to display information about\n"
12505 "Neighbor on bgp configured interface\n"
12506 "Display the received routes from neighbor\n"
12507 "JavaScript Object Notation\n")
12508
12509 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12510 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12511 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12512 SHOW_STR
12513 IP_STR
12514 BGP_STR
12515 BGP_INSTANCE_HELP_STR
12516 "Detailed information on TCP and BGP neighbor connections\n"
12517 "Neighbor to display information about\n"
12518 "Neighbor to display information about\n"
12519 "Neighbor on bgp configured interface\n"
12520 "Display the received routes from neighbor\n"
12521 "JavaScript Object Notation\n")
12522
12523 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12524 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12525 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12526 SHOW_STR
12527 IP_STR
12528 BGP_STR
12529 "Address family\n"
12530 "Address Family modifier\n"
12531 "Address Family modifier\n"
12532 "Detailed information on TCP and BGP neighbor connections\n"
12533 "Neighbor to display information about\n"
12534 "Neighbor to display information about\n"
12535 "Neighbor on bgp configured interface\n"
12536 "Display the received routes from neighbor\n"
12537 "JavaScript Object Notation\n")
12538 {
12539 struct peer *peer;
12540 const char *rmap_name = NULL;
12541 u_char uj = use_json(argc, argv);
12542
12543 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12544 if (! peer)
12545 return CMD_WARNING;
12546
12547 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12548 rmap_name = argv[2];
12549
12550 if (strncmp (argv[0], "m", 1) == 0)
12551 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
12552 else
12553 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12554 }
12555
12556 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12557 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12558 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12559 SHOW_STR
12560 IP_STR
12561 BGP_STR
12562 "Address family\n"
12563 "Address Family modifier\n"
12564 "Address Family modifier\n"
12565 "Detailed information on TCP and BGP neighbor connections\n"
12566 "Neighbor to display information about\n"
12567 "Neighbor to display information about\n"
12568 "Neighbor on bgp configured interface\n"
12569 "Display the received routes from neighbor\n"
12570 "JavaScript Object Notation\n")
12571
12572 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12573 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12574 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12575 SHOW_STR
12576 BGP_STR
12577 BGP_INSTANCE_HELP_STR
12578 "Address family\n"
12579 "Address family\n"
12580 "Address family modifier\n"
12581 "Address family modifier\n"
12582 "Detailed information on TCP and BGP neighbor connections\n"
12583 "Neighbor to display information about\n"
12584 "Neighbor to display information about\n"
12585 "Neighbor on bgp configured interface\n"
12586 "Display the advertised routes to neighbor\n"
12587 "Display the received routes from neighbor\n"
12588 "JavaScript Object Notation\n")
12589 {
12590 int afi;
12591 int safi;
12592 int in;
12593 struct peer *peer;
12594 u_char uj = use_json(argc, argv);
12595
12596 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12597
12598 if (! peer)
12599 return CMD_WARNING;
12600
12601 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12602 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12603 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12604
12605 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12606 }
12607
12608 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12609 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12610 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12611 SHOW_STR
12612 IP_STR
12613 BGP_STR
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 information received from a BGP neighbor\n"
12619 "Display the prefixlist filter\n"
12620 "JavaScript Object Notation\n")
12621 {
12622 char name[BUFSIZ];
12623 union sockunion su;
12624 struct peer *peer;
12625 int count, ret;
12626 u_char uj = use_json(argc, argv);
12627
12628 ret = str2sockunion (argv[0], &su);
12629 if (ret < 0)
12630 {
12631 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12632 if (! peer)
12633 {
12634 if (uj)
12635 {
12636 json_object *json_no = NULL;
12637 json_object *json_sub = NULL;
12638 json_no = json_object_new_object();
12639 json_sub = json_object_new_object();
12640 json_object_string_add(json_no, "warning", "Malformed address or name");
12641 json_object_string_add(json_sub, "warningCause", argv[0]);
12642 json_object_object_add(json_no, "detail", json_sub);
12643 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12644 json_object_free(json_no);
12645 }
12646 else
12647 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12648 return CMD_WARNING;
12649 }
12650 }
12651 else
12652 {
12653 peer = peer_lookup (NULL, &su);
12654 if (! peer)
12655 {
12656 if (uj)
12657 {
12658 json_object *json_no = NULL;
12659 json_no = json_object_new_object();
12660 json_object_string_add(json_no, "warning", "Peer not found");
12661 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12662 json_object_free(json_no);
12663 }
12664 else
12665 vty_out (vty, "No peer%s", VTY_NEWLINE);
12666 return CMD_WARNING;
12667 }
12668 }
12669
12670 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12671 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12672 if (count)
12673 {
12674 if (!uj)
12675 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12676 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12677 }
12678 else
12679 {
12680 if (uj)
12681 {
12682 json_object *json_no = NULL;
12683 json_no = json_object_new_object();
12684 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12685 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12686 json_object_free(json_no);
12687 }
12688 else
12689 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12690 }
12691
12692 return CMD_SUCCESS;
12693 }
12694
12695 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12696 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
12697 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12698 SHOW_STR
12699 IP_STR
12700 BGP_STR
12701 "Address family\n"
12702 "Address Family modifier\n"
12703 "Address Family modifier\n"
12704 "Detailed information on TCP and BGP neighbor connections\n"
12705 "Neighbor to display information about\n"
12706 "Neighbor to display information about\n"
12707 "Neighbor on bgp configured interface\n"
12708 "Display information received from a BGP neighbor\n"
12709 "Display the prefixlist filter\n"
12710 "JavaScript Object Notation\n")
12711 {
12712 char name[BUFSIZ];
12713 union sockunion su;
12714 struct peer *peer;
12715 int count, ret;
12716 u_char uj = use_json(argc, argv);
12717
12718 ret = str2sockunion (argv[1], &su);
12719 if (ret < 0)
12720 {
12721 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12722 if (! peer)
12723 {
12724 if (uj)
12725 {
12726 json_object *json_no = NULL;
12727 json_object *json_sub = NULL;
12728 json_no = json_object_new_object();
12729 json_sub = json_object_new_object();
12730 json_object_string_add(json_no, "warning", "Malformed address or name");
12731 json_object_string_add(json_sub, "warningCause", argv[1]);
12732 json_object_object_add(json_no, "detail", json_sub);
12733 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12734 json_object_free(json_no);
12735 }
12736 else
12737 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12738 return CMD_WARNING;
12739 }
12740 }
12741 else
12742 {
12743 peer = peer_lookup (NULL, &su);
12744 if (! peer)
12745 {
12746 if (uj)
12747 {
12748 json_object *json_no = NULL;
12749 json_no = json_object_new_object();
12750 json_object_string_add(json_no, "warning", "Peer not found");
12751 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12752 json_object_free(json_no);
12753 }
12754 else
12755 vty_out (vty, "No peer%s", VTY_NEWLINE);
12756 return CMD_WARNING;
12757 }
12758 }
12759
12760 if (strncmp (argv[0], "m", 1) == 0)
12761 {
12762 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12763 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12764 if (count)
12765 {
12766 if (!uj)
12767 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12768 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12769 }
12770 else
12771 {
12772 if (uj)
12773 {
12774 json_object *json_no = NULL;
12775 json_no = json_object_new_object();
12776 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12777 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12778 json_object_free(json_no);
12779 }
12780 else
12781 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12782 }
12783 }
12784 else
12785 {
12786 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12787 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12788 if (count)
12789 {
12790 if (!uj)
12791 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12792 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12793 }
12794 else
12795 {
12796 if (uj)
12797 {
12798 json_object *json_no = NULL;
12799 json_no = json_object_new_object();
12800 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12801 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12802 json_object_free(json_no);
12803 }
12804 else
12805 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12806 }
12807 }
12808
12809 return CMD_SUCCESS;
12810 }
12811 #ifdef HAVE_IPV6
12812 DEFUN (show_bgp_neighbor_received_routes,
12813 show_bgp_neighbor_received_routes_cmd,
12814 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12815 SHOW_STR
12816 BGP_STR
12817 "Detailed information on TCP and BGP neighbor connections\n"
12818 "Neighbor to display information about\n"
12819 "Neighbor to display information about\n"
12820 "Neighbor on bgp configured interface\n"
12821 "Display the received routes from neighbor\n"
12822 "JavaScript Object Notation\n")
12823 {
12824 struct peer *peer;
12825 const char *rmap_name = NULL;
12826 u_char uj = use_json(argc, argv);
12827
12828 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12829
12830 if (! peer)
12831 return CMD_WARNING;
12832
12833 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12834 rmap_name = argv[1];
12835
12836 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12837 }
12838
12839 ALIAS (show_bgp_neighbor_received_routes,
12840 show_bgp_ipv6_neighbor_received_routes_cmd,
12841 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12842 SHOW_STR
12843 BGP_STR
12844 "Address family\n"
12845 "Detailed information on TCP and BGP neighbor connections\n"
12846 "Neighbor to display information about\n"
12847 "Neighbor to display information about\n"
12848 "Neighbor on bgp configured interface\n"
12849 "Display the received routes from neighbor\n"
12850 "JavaScript Object Notation\n")
12851
12852 DEFUN (show_bgp_neighbor_received_prefix_filter,
12853 show_bgp_neighbor_received_prefix_filter_cmd,
12854 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12855 SHOW_STR
12856 BGP_STR
12857 "Detailed information on TCP and BGP neighbor connections\n"
12858 "Neighbor to display information about\n"
12859 "Neighbor to display information about\n"
12860 "Neighbor on bgp configured interface\n"
12861 "Display information received from a BGP neighbor\n"
12862 "Display the prefixlist filter\n"
12863 "JavaScript Object Notation\n")
12864 {
12865 char name[BUFSIZ];
12866 union sockunion su;
12867 struct peer *peer;
12868 int count, ret;
12869 u_char uj = use_json(argc, argv);
12870
12871 ret = str2sockunion (argv[0], &su);
12872 if (ret < 0)
12873 {
12874 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12875 if (! peer)
12876 {
12877 if (uj)
12878 {
12879 json_object *json_no = NULL;
12880 json_object *json_sub = NULL;
12881 json_no = json_object_new_object();
12882 json_sub = json_object_new_object();
12883 json_object_string_add(json_no, "warning", "Malformed address or name");
12884 json_object_string_add(json_sub, "warningCause", argv[0]);
12885 json_object_object_add(json_no, "detail", json_sub);
12886 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12887 json_object_free(json_no);
12888 }
12889 else
12890 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12891 return CMD_WARNING;
12892 }
12893 }
12894 else
12895 {
12896 peer = peer_lookup (NULL, &su);
12897 if (! peer)
12898 {
12899 if (uj)
12900 {
12901 json_object *json_no = NULL;
12902 json_no = json_object_new_object();
12903 json_object_string_add(json_no, "warning", "No Peer");
12904 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12905 json_object_free(json_no);
12906 }
12907 else
12908 vty_out (vty, "No peer%s", VTY_NEWLINE);
12909 return CMD_WARNING;
12910 }
12911 }
12912
12913 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12914 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12915 if (count)
12916 {
12917 if (!uj)
12918 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12919 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12920 }
12921 else
12922 {
12923 if (uj)
12924 {
12925 json_object *json_no = NULL;
12926 json_no = json_object_new_object();
12927 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12928 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12929 json_object_free(json_no);
12930 }
12931 else
12932 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12933 }
12934
12935 return CMD_SUCCESS;
12936 }
12937
12938 ALIAS (show_bgp_neighbor_received_prefix_filter,
12939 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
12940 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12941 SHOW_STR
12942 BGP_STR
12943 "Address family\n"
12944 "Detailed information on TCP and BGP neighbor connections\n"
12945 "Neighbor to display information about\n"
12946 "Neighbor to display information about\n"
12947 "Neighbor on bgp configured interface\n"
12948 "Display information received from a BGP neighbor\n"
12949 "Display the prefixlist filter\n"
12950 "JavaScript Object Notation\n")
12951
12952 /* old command */
12953 ALIAS (show_bgp_neighbor_received_routes,
12954 ipv6_bgp_neighbor_received_routes_cmd,
12955 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12956 SHOW_STR
12957 IPV6_STR
12958 BGP_STR
12959 "Detailed information on TCP and BGP neighbor connections\n"
12960 "Neighbor to display information about\n"
12961 "Neighbor to display information about\n"
12962 "Neighbor on bgp configured interface\n"
12963 "Display the received routes from neighbor\n"
12964 "JavaScript Object Notation\n")
12965
12966 /* old command */
12967 DEFUN (ipv6_mbgp_neighbor_received_routes,
12968 ipv6_mbgp_neighbor_received_routes_cmd,
12969 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12970 SHOW_STR
12971 IPV6_STR
12972 MBGP_STR
12973 "Detailed information on TCP and BGP neighbor connections\n"
12974 "Neighbor to display information about\n"
12975 "Neighbor to display information about\n"
12976 "Neighbor on bgp configured interface\n"
12977 "Display the received routes from neighbor\n"
12978 "JavaScript Object Notation\n")
12979 {
12980 struct peer *peer;
12981 u_char uj = use_json(argc, argv);
12982
12983 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12984 if (! peer)
12985 return CMD_WARNING;
12986
12987 bgp_show_ipv6_bgp_deprecate_warning(vty);
12988 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
12989 }
12990
12991 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
12992 show_bgp_instance_neighbor_received_prefix_filter_cmd,
12993 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12994 SHOW_STR
12995 BGP_STR
12996 BGP_INSTANCE_HELP_STR
12997 "Detailed information on TCP and BGP neighbor connections\n"
12998 "Neighbor to display information about\n"
12999 "Neighbor to display information about\n"
13000 "Neighbor on bgp configured interface\n"
13001 "Display information received from a BGP neighbor\n"
13002 "Display the prefixlist filter\n"
13003 "JavaScript Object Notation\n")
13004 {
13005 char name[BUFSIZ];
13006 union sockunion su;
13007 struct peer *peer;
13008 struct bgp *bgp;
13009 int count, ret;
13010 u_char uj = use_json(argc, argv);
13011
13012 /* BGP structure lookup. */
13013 bgp = bgp_lookup_by_name (argv[1]);
13014 if (bgp == NULL)
13015 {
13016 if (uj)
13017 {
13018 json_object *json_no = NULL;
13019 json_no = json_object_new_object();
13020 json_object_string_add(json_no, "warning", "Can't find BGP view");
13021 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13022 json_object_free(json_no);
13023 }
13024 else
13025 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13026 return CMD_WARNING;
13027 }
13028
13029 ret = str2sockunion (argv[2], &su);
13030 if (ret < 0)
13031 {
13032 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13033 if (! peer)
13034 {
13035 if (uj)
13036 {
13037 json_object *json_no = NULL;
13038 json_object *json_sub = NULL;
13039 json_no = json_object_new_object();
13040 json_sub = json_object_new_object();
13041 json_object_string_add(json_no, "warning", "Malformed address or name");
13042 json_object_string_add(json_sub, "warningCause", argv[2]);
13043 json_object_object_add(json_no, "detail", json_sub);
13044 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13045 json_object_free(json_no);
13046 }
13047 else
13048 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13049 return CMD_WARNING;
13050 }
13051 }
13052 else
13053 {
13054 peer = peer_lookup (bgp, &su);
13055 if (! peer)
13056 {
13057 if (uj)
13058 {
13059 json_object *json_no = NULL;
13060 json_no = json_object_new_object();
13061 json_object_boolean_true_add(json_no, "noPeer");
13062 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13063 json_object_free(json_no);
13064 }
13065 else
13066 vty_out (vty, "No peer%s", VTY_NEWLINE);
13067 return CMD_WARNING;
13068 }
13069
13070 }
13071
13072 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13073 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13074 if (count)
13075 {
13076 if (!uj)
13077 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13078 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13079 }
13080
13081 return CMD_SUCCESS;
13082 }
13083 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13084 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13085 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13086 SHOW_STR
13087 BGP_STR
13088 BGP_INSTANCE_HELP_STR
13089 "Address family\n"
13090 "Detailed information on TCP and BGP neighbor connections\n"
13091 "Neighbor to display information about\n"
13092 "Neighbor to display information about\n"
13093 "Neighbor on bgp configured interface\n"
13094 "Display information received from a BGP neighbor\n"
13095 "Display the prefixlist filter\n"
13096 "JavaScript Object NOtation\n")
13097 #endif /* HAVE_IPV6 */
13098
13099 static int
13100 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13101 safi_t safi, enum bgp_show_type type, u_char use_json)
13102 {
13103 if (! peer || ! peer->afc[afi][safi])
13104 {
13105 if (use_json)
13106 {
13107 json_object *json_no = NULL;
13108 json_no = json_object_new_object();
13109 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13110 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13111 json_object_free(json_no);
13112 }
13113 else
13114 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13115 return CMD_WARNING;
13116 }
13117
13118 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13119 }
13120
13121 DEFUN (show_ip_bgp_neighbor_routes,
13122 show_ip_bgp_neighbor_routes_cmd,
13123 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13124 SHOW_STR
13125 IP_STR
13126 BGP_STR
13127 "Detailed information on TCP and BGP neighbor connections\n"
13128 "Neighbor to display information about\n"
13129 "Neighbor to display information about\n"
13130 "Neighbor on bgp configured interface\n"
13131 "Display routes learned from neighbor\n"
13132 "JavaScript Object Notation\n")
13133 {
13134 struct peer *peer;
13135 u_char uj = use_json(argc, argv);
13136
13137 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13138 if (! peer)
13139 return CMD_WARNING;
13140
13141 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13142 bgp_show_type_neighbor, uj);
13143 }
13144
13145 DEFUN (show_ip_bgp_instance_neighbor_routes,
13146 show_ip_bgp_instance_neighbor_routes_cmd,
13147 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13148 SHOW_STR
13149 IP_STR
13150 BGP_STR
13151 BGP_INSTANCE_HELP_STR
13152 "Detailed information on TCP and BGP neighbor connections\n"
13153 "Neighbor to display information about\n"
13154 "Neighbor to display information about\n"
13155 "Neighbor on bgp configured interface\n"
13156 "Display routes learned from neighbor\n"
13157 "JavaScript Object Notation\n")
13158 {
13159 struct peer *peer;
13160 u_char uj = use_json(argc, argv);
13161
13162 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13163 if (! peer)
13164 return CMD_WARNING;
13165
13166 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13167 bgp_show_type_neighbor, uj);
13168 }
13169
13170 DEFUN (show_ip_bgp_neighbor_flap,
13171 show_ip_bgp_neighbor_flap_cmd,
13172 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13173 SHOW_STR
13174 IP_STR
13175 BGP_STR
13176 "Detailed information on TCP and BGP neighbor connections\n"
13177 "Neighbor to display information about\n"
13178 "Neighbor to display information about\n"
13179 "Neighbor on bgp configured interface\n"
13180 "Display flap statistics of the routes learned from neighbor\n"
13181 "JavaScript Object Notation\n")
13182 {
13183 struct peer *peer;
13184 u_char uj = use_json(argc, argv);
13185
13186 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13187 if (! peer)
13188 return CMD_WARNING;
13189
13190 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13191 bgp_show_type_flap_neighbor, uj);
13192 }
13193
13194 DEFUN (show_ip_bgp_neighbor_damp,
13195 show_ip_bgp_neighbor_damp_cmd,
13196 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13197 SHOW_STR
13198 IP_STR
13199 BGP_STR
13200 "Detailed information on TCP and BGP neighbor connections\n"
13201 "Neighbor to display information about\n"
13202 "Neighbor to display information about\n"
13203 "Neighbor on bgp configured interface\n"
13204 "Display the dampened routes received from neighbor\n"
13205 "JavaScript Object Notation\n")
13206 {
13207 struct peer *peer;
13208 u_char uj = use_json(argc, argv);
13209
13210 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13211 if (! peer)
13212 return CMD_WARNING;
13213
13214 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13215 bgp_show_type_damp_neighbor, uj);
13216 }
13217
13218 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13219 show_ip_bgp_ipv4_neighbor_routes_cmd,
13220 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13221 SHOW_STR
13222 IP_STR
13223 BGP_STR
13224 "Address family\n"
13225 "Address Family modifier\n"
13226 "Address Family modifier\n"
13227 "Detailed information on TCP and BGP neighbor connections\n"
13228 "Neighbor to display information about\n"
13229 "Neighbor to display information about\n"
13230 "Neighbor on bgp configured interface\n"
13231 "Display routes learned from neighbor\n"
13232 "JavaScript Object Notation\n")
13233 {
13234 struct peer *peer;
13235 u_char uj = use_json(argc, argv);
13236
13237 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13238 if (! peer)
13239 return CMD_WARNING;
13240
13241 if (strncmp (argv[0], "m", 1) == 0)
13242 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13243 bgp_show_type_neighbor, uj);
13244
13245 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13246 bgp_show_type_neighbor, uj);
13247 }
13248
13249 #ifdef HAVE_IPV6
13250 DEFUN (show_bgp_instance_neighbor_routes,
13251 show_bgp_instance_neighbor_routes_cmd,
13252 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13253 SHOW_STR
13254 BGP_STR
13255 BGP_INSTANCE_HELP_STR
13256 "Detailed information on TCP and BGP neighbor connections\n"
13257 "Neighbor to display information about\n"
13258 "Neighbor to display information about\n"
13259 "Neighbor on bgp configured interface\n"
13260 "Display routes learned from neighbor\n"
13261 "JavaScript Object Notation\n")
13262 {
13263 struct peer *peer;
13264 u_char uj = use_json(argc, argv);
13265
13266 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13267 if (! peer)
13268 return CMD_WARNING;
13269
13270 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13271 bgp_show_type_neighbor, uj);
13272 }
13273
13274 ALIAS (show_bgp_instance_neighbor_routes,
13275 show_bgp_instance_ipv6_neighbor_routes_cmd,
13276 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13277 SHOW_STR
13278 BGP_STR
13279 BGP_INSTANCE_HELP_STR
13280 "Address family\n"
13281 "Detailed information on TCP and BGP neighbor connections\n"
13282 "Neighbor to display information about\n"
13283 "Neighbor to display information about\n"
13284 "Neighbor on bgp configured interface\n"
13285 "Display routes learned from neighbor\n"
13286 "JavaScript Object Notation\n")
13287
13288 DEFUN (show_bgp_instance_neighbor_damp,
13289 show_bgp_instance_neighbor_damp_cmd,
13290 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13291 SHOW_STR
13292 BGP_STR
13293 BGP_INSTANCE_HELP_STR
13294 "Detailed information on TCP and BGP neighbor connections\n"
13295 "Neighbor to display information about\n"
13296 "Neighbor to display information about\n"
13297 "Neighbor on bgp configured interface\n"
13298 "Display the dampened routes received from neighbor\n"
13299 "JavaScript Object Notation\n")
13300 {
13301 struct peer *peer;
13302 u_char uj = use_json(argc, argv);
13303
13304 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13305 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13306 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13307 else
13308 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13309
13310 if (! peer)
13311 return CMD_WARNING;
13312
13313 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13314 bgp_show_type_damp_neighbor, uj);
13315 }
13316
13317 ALIAS (show_bgp_instance_neighbor_damp,
13318 show_bgp_instance_ipv6_neighbor_damp_cmd,
13319 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13320 SHOW_STR
13321 BGP_STR
13322 BGP_INSTANCE_HELP_STR
13323 "Address family\n"
13324 "Detailed information on TCP and BGP neighbor connections\n"
13325 "Neighbor to display information about\n"
13326 "Neighbor to display information about\n"
13327 "Neighbor on bgp configured interface\n"
13328 "Display the dampened routes received from neighbor\n"
13329 "JavaScript Object Notation\n")
13330
13331 DEFUN (show_bgp_instance_neighbor_flap,
13332 show_bgp_instance_neighbor_flap_cmd,
13333 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13334 SHOW_STR
13335 BGP_STR
13336 BGP_INSTANCE_HELP_STR
13337 "Detailed information on TCP and BGP neighbor connections\n"
13338 "Neighbor to display information about\n"
13339 "Neighbor to display information about\n"
13340 "Neighbor on bgp configured interface\n"
13341 "Display flap statistics of the routes learned from neighbor\n"
13342 "JavaScript Object Notation\n")
13343 {
13344 struct peer *peer;
13345 u_char uj = use_json(argc, argv);
13346
13347 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13348 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13349 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13350 else
13351 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13352
13353 if (! peer)
13354 return CMD_WARNING;
13355
13356 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13357 bgp_show_type_flap_neighbor, uj);
13358 }
13359
13360 ALIAS (show_bgp_instance_neighbor_flap,
13361 show_bgp_instance_ipv6_neighbor_flap_cmd,
13362 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13363 SHOW_STR
13364 BGP_STR
13365 BGP_INSTANCE_HELP_STR
13366 "Address family\n"
13367 "Detailed information on TCP and BGP neighbor connections\n"
13368 "Neighbor to display information about\n"
13369 "Neighbor to display information about\n"
13370 "Neighbor on bgp configured interface\n"
13371 "Display flap statistics of the routes learned from neighbor\n"
13372 "JavaScript Object Notation\n")
13373
13374 DEFUN (show_bgp_neighbor_routes,
13375 show_bgp_neighbor_routes_cmd,
13376 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13377 SHOW_STR
13378 BGP_STR
13379 "Detailed information on TCP and BGP neighbor connections\n"
13380 "Neighbor to display information about\n"
13381 "Neighbor to display information about\n"
13382 "Neighbor on bgp configured interface\n"
13383 "Display routes learned from neighbor\n"
13384 "JavaScript Object Notation\n")
13385 {
13386 struct peer *peer;
13387 u_char uj = use_json(argc, argv);
13388
13389 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13390 if (! peer)
13391 return CMD_WARNING;
13392
13393 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13394 bgp_show_type_neighbor, uj);
13395 }
13396
13397
13398 ALIAS (show_bgp_neighbor_routes,
13399 show_bgp_ipv6_neighbor_routes_cmd,
13400 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13401 SHOW_STR
13402 BGP_STR
13403 "Address family\n"
13404 "Detailed information on TCP and BGP neighbor connections\n"
13405 "Neighbor to display information about\n"
13406 "Neighbor to display information about\n"
13407 "Neighbor on bgp configured interface\n"
13408 "Display routes learned from neighbor\n"
13409 "JavaScript Object Notation\n")
13410
13411 /* old command */
13412 ALIAS (show_bgp_neighbor_routes,
13413 ipv6_bgp_neighbor_routes_cmd,
13414 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13415 SHOW_STR
13416 IPV6_STR
13417 BGP_STR
13418 "Detailed information on TCP and BGP neighbor connections\n"
13419 "Neighbor to display information about\n"
13420 "Neighbor to display information about\n"
13421 "Neighbor on bgp configured interface\n"
13422 "Display routes learned from neighbor\n"
13423 "JavaScript Object Notation\n")
13424
13425 /* old command */
13426 DEFUN (ipv6_mbgp_neighbor_routes,
13427 ipv6_mbgp_neighbor_routes_cmd,
13428 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13429 SHOW_STR
13430 IPV6_STR
13431 MBGP_STR
13432 "Detailed information on TCP and BGP neighbor connections\n"
13433 "Neighbor to display information about\n"
13434 "Neighbor to display information about\n"
13435 "Neighbor on bgp configured interface\n"
13436 "Display routes learned from neighbor\n"
13437 "JavaScript Object Notation\n")
13438 {
13439 struct peer *peer;
13440 u_char uj = use_json(argc, argv);
13441
13442 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13443 if (! peer)
13444 return CMD_WARNING;
13445
13446 bgp_show_ipv6_bgp_deprecate_warning(vty);
13447 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13448 bgp_show_type_neighbor, uj);
13449 }
13450
13451 ALIAS (show_bgp_instance_neighbor_flap,
13452 show_bgp_neighbor_flap_cmd,
13453 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13454 SHOW_STR
13455 BGP_STR
13456 "Detailed information on TCP and BGP neighbor connections\n"
13457 "Neighbor to display information about\n"
13458 "Neighbor to display information about\n"
13459 "Neighbor on bgp configured interface\n"
13460 "Display flap statistics of the routes learned from neighbor\n"
13461 "JavaScript Object Notation\n")
13462
13463 ALIAS (show_bgp_instance_neighbor_flap,
13464 show_bgp_ipv6_neighbor_flap_cmd,
13465 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13466 SHOW_STR
13467 BGP_STR
13468 "Address family\n"
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 flap statistics of the routes learned from neighbor\n"
13474 "JavaScript Object Notation\n")
13475
13476 ALIAS (show_bgp_instance_neighbor_damp,
13477 show_bgp_neighbor_damp_cmd,
13478 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13479 SHOW_STR
13480 BGP_STR
13481 "Detailed information on TCP and BGP neighbor connections\n"
13482 "Neighbor to display information about\n"
13483 "Neighbor to display information about\n"
13484 "Neighbor on bgp configured interface\n"
13485 "Display the dampened routes received from neighbor\n"
13486 "JavaScript Object Notation\n")
13487
13488 ALIAS (show_bgp_instance_neighbor_damp,
13489 show_bgp_ipv6_neighbor_damp_cmd,
13490 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13491 SHOW_STR
13492 BGP_STR
13493 "Address family\n"
13494 "Detailed information on TCP and BGP neighbor connections\n"
13495 "Neighbor to display information about\n"
13496 "Neighbor to display information about\n"
13497 "Neighbor on bgp configured interface\n"
13498 "Display the dampened routes received from neighbor\n"
13499 "JavaScript Object Notation\n")
13500
13501 #endif /* HAVE_IPV6 */
13502
13503 struct bgp_table *bgp_distance_table;
13504
13505 struct bgp_distance
13506 {
13507 /* Distance value for the IP source prefix. */
13508 u_char distance;
13509
13510 /* Name of the access-list to be matched. */
13511 char *access_list;
13512 };
13513
13514 static struct bgp_distance *
13515 bgp_distance_new (void)
13516 {
13517 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13518 }
13519
13520 static void
13521 bgp_distance_free (struct bgp_distance *bdistance)
13522 {
13523 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13524 }
13525
13526 static int
13527 bgp_distance_set (struct vty *vty, const char *distance_str,
13528 const char *ip_str, const char *access_list_str)
13529 {
13530 int ret;
13531 struct prefix_ipv4 p;
13532 u_char distance;
13533 struct bgp_node *rn;
13534 struct bgp_distance *bdistance;
13535
13536 ret = str2prefix_ipv4 (ip_str, &p);
13537 if (ret == 0)
13538 {
13539 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13540 return CMD_WARNING;
13541 }
13542
13543 distance = atoi (distance_str);
13544
13545 /* Get BGP distance node. */
13546 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13547 if (rn->info)
13548 {
13549 bdistance = rn->info;
13550 bgp_unlock_node (rn);
13551 }
13552 else
13553 {
13554 bdistance = bgp_distance_new ();
13555 rn->info = bdistance;
13556 }
13557
13558 /* Set distance value. */
13559 bdistance->distance = distance;
13560
13561 /* Reset access-list configuration. */
13562 if (bdistance->access_list)
13563 {
13564 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13565 bdistance->access_list = NULL;
13566 }
13567 if (access_list_str)
13568 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13569
13570 return CMD_SUCCESS;
13571 }
13572
13573 static int
13574 bgp_distance_unset (struct vty *vty, const char *distance_str,
13575 const char *ip_str, const char *access_list_str)
13576 {
13577 int ret;
13578 int distance;
13579 struct prefix_ipv4 p;
13580 struct bgp_node *rn;
13581 struct bgp_distance *bdistance;
13582
13583 ret = str2prefix_ipv4 (ip_str, &p);
13584 if (ret == 0)
13585 {
13586 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13587 return CMD_WARNING;
13588 }
13589
13590 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13591 if (! rn)
13592 {
13593 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13594 return CMD_WARNING;
13595 }
13596
13597 bdistance = rn->info;
13598 distance = atoi(distance_str);
13599
13600 if (bdistance->distance != distance)
13601 {
13602 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13603 return CMD_WARNING;
13604 }
13605
13606 if (bdistance->access_list)
13607 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13608 bgp_distance_free (bdistance);
13609
13610 rn->info = NULL;
13611 bgp_unlock_node (rn);
13612 bgp_unlock_node (rn);
13613
13614 return CMD_SUCCESS;
13615 }
13616
13617 /* Apply BGP information to distance method. */
13618 u_char
13619 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13620 {
13621 struct bgp_node *rn;
13622 struct prefix_ipv4 q;
13623 struct peer *peer;
13624 struct bgp_distance *bdistance;
13625 struct access_list *alist;
13626 struct bgp_static *bgp_static;
13627
13628 if (! bgp)
13629 return 0;
13630
13631 if (p->family != AF_INET)
13632 return 0;
13633
13634 peer = rinfo->peer;
13635
13636 if (peer->su.sa.sa_family != AF_INET)
13637 return 0;
13638
13639 memset (&q, 0, sizeof (struct prefix_ipv4));
13640 q.family = AF_INET;
13641 q.prefix = peer->su.sin.sin_addr;
13642 q.prefixlen = IPV4_MAX_BITLEN;
13643
13644 /* Check source address. */
13645 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13646 if (rn)
13647 {
13648 bdistance = rn->info;
13649 bgp_unlock_node (rn);
13650
13651 if (bdistance->access_list)
13652 {
13653 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13654 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13655 return bdistance->distance;
13656 }
13657 else
13658 return bdistance->distance;
13659 }
13660
13661 /* Backdoor check. */
13662 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13663 if (rn)
13664 {
13665 bgp_static = rn->info;
13666 bgp_unlock_node (rn);
13667
13668 if (bgp_static->backdoor)
13669 {
13670 if (bgp->distance_local)
13671 return bgp->distance_local;
13672 else
13673 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13674 }
13675 }
13676
13677 if (peer->sort == BGP_PEER_EBGP)
13678 {
13679 if (bgp->distance_ebgp)
13680 return bgp->distance_ebgp;
13681 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13682 }
13683 else
13684 {
13685 if (bgp->distance_ibgp)
13686 return bgp->distance_ibgp;
13687 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13688 }
13689 }
13690
13691 DEFUN (bgp_distance,
13692 bgp_distance_cmd,
13693 "distance bgp <1-255> <1-255> <1-255>",
13694 "Define an administrative distance\n"
13695 "BGP distance\n"
13696 "Distance for routes external to the AS\n"
13697 "Distance for routes internal to the AS\n"
13698 "Distance for local routes\n")
13699 {
13700 struct bgp *bgp;
13701
13702 bgp = vty->index;
13703
13704 bgp->distance_ebgp = atoi (argv[0]);
13705 bgp->distance_ibgp = atoi (argv[1]);
13706 bgp->distance_local = atoi (argv[2]);
13707 return CMD_SUCCESS;
13708 }
13709
13710 DEFUN (no_bgp_distance,
13711 no_bgp_distance_cmd,
13712 "no distance bgp <1-255> <1-255> <1-255>",
13713 NO_STR
13714 "Define an administrative distance\n"
13715 "BGP distance\n"
13716 "Distance for routes external to the AS\n"
13717 "Distance for routes internal to the AS\n"
13718 "Distance for local routes\n")
13719 {
13720 struct bgp *bgp;
13721
13722 bgp = vty->index;
13723
13724 bgp->distance_ebgp= 0;
13725 bgp->distance_ibgp = 0;
13726 bgp->distance_local = 0;
13727 return CMD_SUCCESS;
13728 }
13729
13730 ALIAS (no_bgp_distance,
13731 no_bgp_distance2_cmd,
13732 "no distance bgp",
13733 NO_STR
13734 "Define an administrative distance\n"
13735 "BGP distance\n")
13736
13737 DEFUN (bgp_distance_source,
13738 bgp_distance_source_cmd,
13739 "distance <1-255> A.B.C.D/M",
13740 "Define an administrative distance\n"
13741 "Administrative distance\n"
13742 "IP source prefix\n")
13743 {
13744 bgp_distance_set (vty, argv[0], argv[1], NULL);
13745 return CMD_SUCCESS;
13746 }
13747
13748 DEFUN (no_bgp_distance_source,
13749 no_bgp_distance_source_cmd,
13750 "no distance <1-255> A.B.C.D/M",
13751 NO_STR
13752 "Define an administrative distance\n"
13753 "Administrative distance\n"
13754 "IP source prefix\n")
13755 {
13756 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13757 return CMD_SUCCESS;
13758 }
13759
13760 DEFUN (bgp_distance_source_access_list,
13761 bgp_distance_source_access_list_cmd,
13762 "distance <1-255> A.B.C.D/M WORD",
13763 "Define an administrative distance\n"
13764 "Administrative distance\n"
13765 "IP source prefix\n"
13766 "Access list name\n")
13767 {
13768 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13769 return CMD_SUCCESS;
13770 }
13771
13772 DEFUN (no_bgp_distance_source_access_list,
13773 no_bgp_distance_source_access_list_cmd,
13774 "no distance <1-255> A.B.C.D/M WORD",
13775 NO_STR
13776 "Define an administrative distance\n"
13777 "Administrative distance\n"
13778 "IP source prefix\n"
13779 "Access list name\n")
13780 {
13781 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13782 return CMD_SUCCESS;
13783 }
13784
13785 DEFUN (bgp_damp_set,
13786 bgp_damp_set_cmd,
13787 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13788 "BGP Specific commands\n"
13789 "Enable route-flap dampening\n"
13790 "Half-life time for the penalty\n"
13791 "Value to start reusing a route\n"
13792 "Value to start suppressing a route\n"
13793 "Maximum duration to suppress a stable route\n")
13794 {
13795 struct bgp *bgp;
13796 int half = DEFAULT_HALF_LIFE * 60;
13797 int reuse = DEFAULT_REUSE;
13798 int suppress = DEFAULT_SUPPRESS;
13799 int max = 4 * half;
13800
13801 if (argc == 4)
13802 {
13803 half = atoi (argv[0]) * 60;
13804 reuse = atoi (argv[1]);
13805 suppress = atoi (argv[2]);
13806 max = atoi (argv[3]) * 60;
13807 }
13808 else if (argc == 1)
13809 {
13810 half = atoi (argv[0]) * 60;
13811 max = 4 * half;
13812 }
13813
13814 bgp = vty->index;
13815
13816 if (suppress < reuse)
13817 {
13818 vty_out (vty, "Suppress value cannot be less than reuse value %s",
13819 VTY_NEWLINE);
13820 return 0;
13821 }
13822
13823 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13824 half, reuse, suppress, max);
13825 }
13826
13827 ALIAS (bgp_damp_set,
13828 bgp_damp_set2_cmd,
13829 "bgp dampening <1-45>",
13830 "BGP Specific commands\n"
13831 "Enable route-flap dampening\n"
13832 "Half-life time for the penalty\n")
13833
13834 ALIAS (bgp_damp_set,
13835 bgp_damp_set3_cmd,
13836 "bgp dampening",
13837 "BGP Specific commands\n"
13838 "Enable route-flap dampening\n")
13839
13840 DEFUN (bgp_damp_unset,
13841 bgp_damp_unset_cmd,
13842 "no bgp dampening",
13843 NO_STR
13844 "BGP Specific commands\n"
13845 "Enable route-flap dampening\n")
13846 {
13847 struct bgp *bgp;
13848
13849 bgp = vty->index;
13850 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13851 }
13852
13853 ALIAS (bgp_damp_unset,
13854 bgp_damp_unset2_cmd,
13855 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13856 NO_STR
13857 "BGP Specific commands\n"
13858 "Enable route-flap dampening\n"
13859 "Half-life time for the penalty\n"
13860 "Value to start reusing a route\n"
13861 "Value to start suppressing a route\n"
13862 "Maximum duration to suppress a stable route\n")
13863
13864 ALIAS (bgp_damp_unset,
13865 bgp_damp_unset3_cmd,
13866 "no bgp dampening <1-45>",
13867 NO_STR
13868 "BGP Specific commands\n"
13869 "Enable route-flap dampening\n"
13870 "Half-life time for the penalty\n")
13871
13872 DEFUN (show_ip_bgp_dampened_paths,
13873 show_ip_bgp_dampened_paths_cmd,
13874 "show ip bgp dampened-paths",
13875 SHOW_STR
13876 IP_STR
13877 BGP_STR
13878 "Display paths suppressed due to dampening\n")
13879 {
13880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13881 NULL, 0);
13882 }
13883
13884 ALIAS (show_ip_bgp_dampened_paths,
13885 show_ip_bgp_damp_dampened_paths_cmd,
13886 "show ip bgp dampening dampened-paths",
13887 SHOW_STR
13888 IP_STR
13889 BGP_STR
13890 "Display detailed information about dampening\n"
13891 "Display paths suppressed due to dampening\n")
13892
13893 DEFUN (show_ip_bgp_flap_statistics,
13894 show_ip_bgp_flap_statistics_cmd,
13895 "show ip bgp flap-statistics",
13896 SHOW_STR
13897 IP_STR
13898 BGP_STR
13899 "Display flap statistics of routes\n")
13900 {
13901 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13902 bgp_show_type_flap_statistics, NULL, 0);
13903 }
13904
13905 ALIAS (show_ip_bgp_flap_statistics,
13906 show_ip_bgp_damp_flap_statistics_cmd,
13907 "show ip bgp dampening flap-statistics",
13908 SHOW_STR
13909 IP_STR
13910 BGP_STR
13911 "Display detailed information about dampening\n"
13912 "Display flap statistics of routes\n")
13913
13914 /* Display specified route of BGP table. */
13915 static int
13916 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13917 const char *ip_str, afi_t afi, safi_t safi,
13918 struct prefix_rd *prd, int prefix_check)
13919 {
13920 int ret;
13921 struct prefix match;
13922 struct bgp_node *rn;
13923 struct bgp_node *rm;
13924 struct bgp_info *ri;
13925 struct bgp_info *ri_temp;
13926 struct bgp *bgp;
13927 struct bgp_table *table;
13928
13929 /* BGP structure lookup. */
13930 if (view_name)
13931 {
13932 bgp = bgp_lookup_by_name (view_name);
13933 if (bgp == NULL)
13934 {
13935 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
13936 return CMD_WARNING;
13937 }
13938 }
13939 else
13940 {
13941 bgp = bgp_get_default ();
13942 if (bgp == NULL)
13943 {
13944 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13945 return CMD_WARNING;
13946 }
13947 }
13948
13949 /* Check IP address argument. */
13950 ret = str2prefix (ip_str, &match);
13951 if (! ret)
13952 {
13953 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13954 return CMD_WARNING;
13955 }
13956
13957 match.family = afi2family (afi);
13958
13959 if (safi == SAFI_MPLS_VPN)
13960 {
13961 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13962 {
13963 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13964 continue;
13965
13966 if ((table = rn->info) != NULL)
13967 if ((rm = bgp_node_match (table, &match)) != NULL)
13968 {
13969 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13970 {
13971 ri = rm->info;
13972 while (ri)
13973 {
13974 if (ri->extra && ri->extra->damp_info)
13975 {
13976 ri_temp = ri->next;
13977 bgp_damp_info_free (ri->extra->damp_info, 1);
13978 ri = ri_temp;
13979 }
13980 else
13981 ri = ri->next;
13982 }
13983 }
13984
13985 bgp_unlock_node (rm);
13986 }
13987 }
13988 }
13989 else
13990 {
13991 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13992 {
13993 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13994 {
13995 ri = rn->info;
13996 while (ri)
13997 {
13998 if (ri->extra && ri->extra->damp_info)
13999 {
14000 ri_temp = ri->next;
14001 bgp_damp_info_free (ri->extra->damp_info, 1);
14002 ri = ri_temp;
14003 }
14004 else
14005 ri = ri->next;
14006 }
14007 }
14008
14009 bgp_unlock_node (rn);
14010 }
14011 }
14012
14013 return CMD_SUCCESS;
14014 }
14015
14016 DEFUN (clear_ip_bgp_dampening,
14017 clear_ip_bgp_dampening_cmd,
14018 "clear ip bgp dampening",
14019 CLEAR_STR
14020 IP_STR
14021 BGP_STR
14022 "Clear route flap dampening information\n")
14023 {
14024 bgp_damp_info_clean ();
14025 return CMD_SUCCESS;
14026 }
14027
14028 DEFUN (clear_ip_bgp_dampening_prefix,
14029 clear_ip_bgp_dampening_prefix_cmd,
14030 "clear ip bgp dampening A.B.C.D/M",
14031 CLEAR_STR
14032 IP_STR
14033 BGP_STR
14034 "Clear route flap dampening information\n"
14035 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14036 {
14037 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14038 SAFI_UNICAST, NULL, 1);
14039 }
14040
14041 DEFUN (clear_ip_bgp_dampening_address,
14042 clear_ip_bgp_dampening_address_cmd,
14043 "clear ip bgp dampening A.B.C.D",
14044 CLEAR_STR
14045 IP_STR
14046 BGP_STR
14047 "Clear route flap dampening information\n"
14048 "Network to clear damping information\n")
14049 {
14050 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14051 SAFI_UNICAST, NULL, 0);
14052 }
14053
14054 DEFUN (clear_ip_bgp_dampening_address_mask,
14055 clear_ip_bgp_dampening_address_mask_cmd,
14056 "clear ip bgp dampening A.B.C.D A.B.C.D",
14057 CLEAR_STR
14058 IP_STR
14059 BGP_STR
14060 "Clear route flap dampening information\n"
14061 "Network to clear damping information\n"
14062 "Network mask\n")
14063 {
14064 int ret;
14065 char prefix_str[BUFSIZ];
14066
14067 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14068 if (! ret)
14069 {
14070 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14071 return CMD_WARNING;
14072 }
14073
14074 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14075 SAFI_UNICAST, NULL, 0);
14076 }
14077
14078 static int
14079 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14080 afi_t afi, safi_t safi, int *write)
14081 {
14082 struct bgp_node *prn;
14083 struct bgp_node *rn;
14084 struct bgp_table *table;
14085 struct prefix *p;
14086 struct prefix_rd *prd;
14087 struct bgp_static *bgp_static;
14088 u_int32_t label;
14089 char buf[SU_ADDRSTRLEN];
14090 char rdbuf[RD_ADDRSTRLEN];
14091
14092 /* Network configuration. */
14093 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14094 if ((table = prn->info) != NULL)
14095 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14096 if ((bgp_static = rn->info) != NULL)
14097 {
14098 p = &rn->p;
14099 prd = (struct prefix_rd *) &prn->p;
14100
14101 /* "address-family" display. */
14102 bgp_config_write_family_header (vty, afi, safi, write);
14103
14104 /* "network" configuration display. */
14105 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14106 label = decode_label (bgp_static->tag);
14107
14108 vty_out (vty, " network %s/%d rd %s tag %d",
14109 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14110 p->prefixlen,
14111 rdbuf, label);
14112 vty_out (vty, "%s", VTY_NEWLINE);
14113 }
14114 return 0;
14115 }
14116
14117 /* Configuration of static route announcement and aggregate
14118 information. */
14119 int
14120 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14121 afi_t afi, safi_t safi, int *write)
14122 {
14123 struct bgp_node *rn;
14124 struct prefix *p;
14125 struct bgp_static *bgp_static;
14126 struct bgp_aggregate *bgp_aggregate;
14127 char buf[SU_ADDRSTRLEN];
14128
14129 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
14130 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14131
14132 /* Network configuration. */
14133 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14134 if ((bgp_static = rn->info) != NULL)
14135 {
14136 p = &rn->p;
14137
14138 /* "address-family" display. */
14139 bgp_config_write_family_header (vty, afi, safi, write);
14140
14141 /* "network" configuration display. */
14142 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14143 {
14144 u_int32_t destination;
14145 struct in_addr netmask;
14146
14147 destination = ntohl (p->u.prefix4.s_addr);
14148 masklen2ip (p->prefixlen, &netmask);
14149 vty_out (vty, " network %s",
14150 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14151
14152 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14153 || (IN_CLASSB (destination) && p->prefixlen == 16)
14154 || (IN_CLASSA (destination) && p->prefixlen == 8)
14155 || p->u.prefix4.s_addr == 0)
14156 {
14157 /* Natural mask is not display. */
14158 }
14159 else
14160 vty_out (vty, " mask %s", inet_ntoa (netmask));
14161 }
14162 else
14163 {
14164 vty_out (vty, " network %s/%d",
14165 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14166 p->prefixlen);
14167 }
14168
14169 if (bgp_static->rmap.name)
14170 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14171 else
14172 {
14173 if (bgp_static->backdoor)
14174 vty_out (vty, " backdoor");
14175 }
14176
14177 vty_out (vty, "%s", VTY_NEWLINE);
14178 }
14179
14180 /* Aggregate-address configuration. */
14181 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14182 if ((bgp_aggregate = rn->info) != NULL)
14183 {
14184 p = &rn->p;
14185
14186 /* "address-family" display. */
14187 bgp_config_write_family_header (vty, afi, safi, write);
14188
14189 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14190 {
14191 struct in_addr netmask;
14192
14193 masklen2ip (p->prefixlen, &netmask);
14194 vty_out (vty, " aggregate-address %s %s",
14195 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14196 inet_ntoa (netmask));
14197 }
14198 else
14199 {
14200 vty_out (vty, " aggregate-address %s/%d",
14201 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14202 p->prefixlen);
14203 }
14204
14205 if (bgp_aggregate->as_set)
14206 vty_out (vty, " as-set");
14207
14208 if (bgp_aggregate->summary_only)
14209 vty_out (vty, " summary-only");
14210
14211 vty_out (vty, "%s", VTY_NEWLINE);
14212 }
14213
14214 return 0;
14215 }
14216
14217 int
14218 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14219 {
14220 struct bgp_node *rn;
14221 struct bgp_distance *bdistance;
14222
14223 /* Distance configuration. */
14224 if (bgp->distance_ebgp
14225 && bgp->distance_ibgp
14226 && bgp->distance_local
14227 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14228 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14229 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14230 vty_out (vty, " distance bgp %d %d %d%s",
14231 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14232 VTY_NEWLINE);
14233
14234 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14235 if ((bdistance = rn->info) != NULL)
14236 {
14237 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14238 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14239 bdistance->access_list ? bdistance->access_list : "",
14240 VTY_NEWLINE);
14241 }
14242
14243 return 0;
14244 }
14245
14246 /* Allocate routing table structure and install commands. */
14247 void
14248 bgp_route_init (void)
14249 {
14250 /* Init BGP distance table. */
14251 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
14252
14253 /* IPv4 BGP commands. */
14254 install_element (BGP_NODE, &bgp_table_map_cmd);
14255 install_element (BGP_NODE, &bgp_network_cmd);
14256 install_element (BGP_NODE, &bgp_network_mask_cmd);
14257 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14258 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14259 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14260 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14261 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14262 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14263 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14264 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14265 install_element (BGP_NODE, &no_bgp_network_cmd);
14266 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14267 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14268 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14269 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14270 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14271 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14272 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14273 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14274
14275 install_element (BGP_NODE, &aggregate_address_cmd);
14276 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14277 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14278 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14279 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14280 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14281 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14282 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14283 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14284 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14285 install_element (BGP_NODE, &no_aggregate_address_cmd);
14286 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14287 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14288 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14289 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14290 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14291 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14292 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14293 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14294 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14295
14296 /* IPv4 unicast configuration. */
14297 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14298 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14299 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14300 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14301 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14302 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14303 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14304 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14305 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14306 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14307 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14308 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14309 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14310 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14311
14312 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14313 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14314 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14315 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14316 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14317 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14318 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14319 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14320 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14321 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14322 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14323 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14324 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14325 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14326 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14327 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14328 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14329 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14330 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14331 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14332
14333 /* IPv4 multicast configuration. */
14334 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14335 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14336 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14337 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14338 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14339 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14340 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14341 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14342 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14343 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14344 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14345 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14346 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14347 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14348 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14349 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14350 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14351 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14352 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14353 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14354 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14355 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14356 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14357 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14358 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14359 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14360 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14361 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14362 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14363 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14364 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14365 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14366 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14367 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14368
14369 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14370 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14371 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14372 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14373 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14374 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14375 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14376 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14377 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14378 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14379 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14380 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14381 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14382 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14383 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14384 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14386 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14387 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14388 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14389 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14390 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14391 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14392 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14393
14394 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14395 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14396 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14397 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14399 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14400 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14401 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14402 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14403 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14404 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14405 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14406 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14407 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14408 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14409 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14410 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14411 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14412 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14413 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14414 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14415 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14417 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14418 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14419 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14420 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14421 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14422 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14423 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14424 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14425 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14426 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14427 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14428 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14429 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14430 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14431 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14433 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14435 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14436 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14438 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14439 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14440 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14441 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14442 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14444 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14445 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14446 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14447 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14448 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14450 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14451 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14452 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14454 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14455 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14456 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14457 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14458 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14459 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14460 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14461 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14462 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14463 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14464 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14465 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14466 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14467 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14468 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14469 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14470 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14471 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14472 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14473 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14474 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14475 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14476 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14477
14478 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14479 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
14480 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14481 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14482 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14483 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14484 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14485 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
14486 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14487 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14488 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14489 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14490 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14491 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14492 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14493 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14494 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14495 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14496 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14497 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14498 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14499 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14500 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14501 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14502 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14503 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14504 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14505 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14506 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
14507 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14508 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14509 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14510 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14511 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14512 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14513 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14514 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14515 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14516 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14517 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14518 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14519 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14520
14521 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14522 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
14523 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
14524 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
14525 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
14526 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
14527 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
14528 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14529 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14530 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14531 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
14532 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
14533 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14534 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14535 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14536 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
14537 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14538 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14539 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14540 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14541 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14542 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14543 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14544 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14545
14546 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14547 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14548 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14549 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14550 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14551 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14552 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
14553 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14554 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14555 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
14556 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14557 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14558 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14559 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14560 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14561 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14562 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14563 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14564 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14565 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14566 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14568 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
14569 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14570 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14571 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14572 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14573 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14574 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14575 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14576 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14577 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14579 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14581 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14582 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14583 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
14584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14585 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14587 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14588 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14590 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14591 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14592 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14593 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14596 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14597 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14598 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14599 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14602 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14603 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14604 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14606 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14608 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
14609 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14610 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14611 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14612 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14613 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14614 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
14615 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14616 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14617 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14618 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14619 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
14620 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14621 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14622 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14623 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14624 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14625 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14626 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14627 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14628 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14629 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14630 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14631
14632 /* BGP dampening clear commands */
14633 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14634 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14635 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14636 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14637
14638 /* prefix count */
14639 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14640 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14642 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
14643 #ifdef HAVE_IPV6
14644 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14645 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14646
14647 /* New config IPv6 BGP commands. */
14648 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14649 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14650 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14651 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14652 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14653 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14654
14655 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14656 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14657 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14658 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14659
14660 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14661 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14662
14663 /* Old config IPv6 BGP commands. */
14664 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14665 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14666
14667 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14668 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14669 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14670 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14671
14672 install_element (VIEW_NODE, &show_bgp_cmd);
14673 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14674 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14675 install_element (VIEW_NODE, &show_bgp_route_cmd);
14676 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14677 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14678 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14679 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14680 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14681 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14682 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14683 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14684 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14685 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14686 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14687 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14688 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14689 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14690 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14691 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14692 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14693 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14694 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14695 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14696 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14697 install_element (VIEW_NODE, &show_bgp_community_cmd);
14698 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14699 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14700 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14701 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14702 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14703 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14704 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14705 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14706 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14707 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14708 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14709 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14710 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14711 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14712 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14713 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14714 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14715 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14716 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14717 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14718 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14719 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14720 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14721 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14722 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14723 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14724 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14725 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14726 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14727 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14728 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14729 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14730 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14731 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14732 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14733 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14734 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14735 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14736 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14737 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14738 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14739 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14740 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14741 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14742 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14743 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14744 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14745 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14746 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14747 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14748 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14749 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14750 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14751 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14752 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14753 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14754 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14755 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14756 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14757 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14758 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14759 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14760 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14761 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14762 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14763 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14764
14765 /* Restricted:
14766 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14767 */
14768 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14769 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14770 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14771 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14772 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14773 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14774 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14775 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14776 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14777 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14778 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14779 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14780 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14781 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14782 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14783 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14784 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14785 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14786 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14787 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14788 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14789 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14790 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14791 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14792 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14793 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14794 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14795 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14796 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14797 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14798 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14799 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14800 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14801 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14802 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14803 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14804
14805 install_element (ENABLE_NODE, &show_bgp_cmd);
14806 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14807 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14808 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14809 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14810 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14811 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14812 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14813 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14814 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14815 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14816 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14817 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14818 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14819 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14820 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14821 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14822 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14823 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14824 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14825 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14826 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14827 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14828 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14829 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14830 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14831 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14832 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14833 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14834 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14835 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14836 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14837 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14838 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14839 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14840 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14841 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14842 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14843 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14844 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14845 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14846 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14847 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14848 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14849 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14850 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14851 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14852 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14853 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14854 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14855 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14856 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14857 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14858 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14859 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14860 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14861 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14862 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14863 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14864 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
14865 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
14866 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14867 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14868 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14869 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14870 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14871 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14872 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14873 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14874 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14875 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14876 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14877 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14878 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14879 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14880 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14881 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14882 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14883 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14884 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14885 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14886 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14887 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14888 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14889 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14890 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14891 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14892 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14893 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14894 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14895 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14896 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14897
14898 /* Statistics */
14899 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14900 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14901 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14902 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14903
14904 /* old command */
14905 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14906 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14907 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14908 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14909 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14910 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14911 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14912 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14913 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14914 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14915 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14916 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14917 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14918 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14919 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14920 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14921 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14922 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14923 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14924 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14925 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14926 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14927 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14928 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14929 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14930 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14931 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14932 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14933 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14934 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14935 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14936 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14937 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14938 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14939 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14940 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14941
14942 /* old command */
14943 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14944 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14945 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14946 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14947 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14948 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14949 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14950 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14951 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14952 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14953 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14954 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14955 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14956 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14957 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14958 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14959 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14960 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14961 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14962 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14963 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14964 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14965 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14966 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14967 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14968 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14969 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14970 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14971 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14972 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14973 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14974 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14975 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14976 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14977 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14978 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14979
14980 /* old command */
14981 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14982 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14983 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14984 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14985
14986 /* old command */
14987 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14988 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14989 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14990 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14991
14992 /* old command */
14993 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14994 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14995 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14996 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14997 #endif /* HAVE_IPV6 */
14998
14999 install_element (BGP_NODE, &bgp_distance_cmd);
15000 install_element (BGP_NODE, &no_bgp_distance_cmd);
15001 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15002 install_element (BGP_NODE, &bgp_distance_source_cmd);
15003 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15004 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15005 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15006
15007 install_element (BGP_NODE, &bgp_damp_set_cmd);
15008 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15009 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15010 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15011 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15012 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15013 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15014 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15015 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15016 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15017 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15018 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15019 }
15020
15021 void
15022 bgp_route_finish (void)
15023 {
15024 bgp_table_unlock (bgp_distance_table);
15025 bgp_distance_table = NULL;
15026 }