]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd: add 'neighbor x.x.x.x allowas-in origin' knob
[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 #if ENABLE_BGP_VNC
66 #include "bgpd/rfapi/rfapi_backend.h"
67 #include "bgpd/rfapi/vnc_import_bgp.h"
68 #include "bgpd/rfapi/vnc_export_bgp.h"
69 #endif
70
71 /* Extern from bgp_dump.c */
72 extern const char *bgp_origin_str[];
73 extern const char *bgp_origin_long_str[];
74
75 struct bgp_node *
76 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
77 struct prefix_rd *prd)
78 {
79 struct bgp_node *rn;
80 struct bgp_node *prn = NULL;
81
82 assert (table);
83 if (!table)
84 return NULL;
85
86 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
87 {
88 prn = bgp_node_get (table, (struct prefix *) prd);
89
90 if (prn->info == NULL)
91 prn->info = bgp_table_init (afi, safi);
92 else
93 bgp_unlock_node (prn);
94 table = prn->info;
95 }
96
97 rn = bgp_node_get (table, p);
98
99 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
100 rn->prn = prn;
101
102 return rn;
103 }
104
105 /* Allocate bgp_info_extra */
106 static struct bgp_info_extra *
107 bgp_info_extra_new (void)
108 {
109 struct bgp_info_extra *new;
110 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
111 return new;
112 }
113
114 static void
115 bgp_info_extra_free (struct bgp_info_extra **extra)
116 {
117 if (extra && *extra)
118 {
119 if ((*extra)->damp_info)
120 bgp_damp_info_free ((*extra)->damp_info, 0);
121
122 (*extra)->damp_info = NULL;
123
124 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
125
126 *extra = NULL;
127 }
128 }
129
130 /* Get bgp_info extra information for the given bgp_info, lazy allocated
131 * if required.
132 */
133 struct bgp_info_extra *
134 bgp_info_extra_get (struct bgp_info *ri)
135 {
136 if (!ri->extra)
137 ri->extra = bgp_info_extra_new();
138 return ri->extra;
139 }
140
141 /* Allocate new bgp info structure. */
142 struct bgp_info *
143 bgp_info_new (void)
144 {
145 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
146 }
147
148 /* Free bgp route information. */
149 static void
150 bgp_info_free (struct bgp_info *binfo)
151 {
152 if (binfo->attr)
153 bgp_attr_unintern (&binfo->attr);
154
155 bgp_unlink_nexthop(binfo);
156 bgp_info_extra_free (&binfo->extra);
157 bgp_info_mpath_free (&binfo->mpath);
158
159 peer_unlock (binfo->peer); /* bgp_info peer reference */
160
161 XFREE (MTYPE_BGP_ROUTE, binfo);
162 }
163
164 struct bgp_info *
165 bgp_info_lock (struct bgp_info *binfo)
166 {
167 binfo->lock++;
168 return binfo;
169 }
170
171 struct bgp_info *
172 bgp_info_unlock (struct bgp_info *binfo)
173 {
174 assert (binfo && binfo->lock > 0);
175 binfo->lock--;
176
177 if (binfo->lock == 0)
178 {
179 #if 0
180 zlog_debug ("%s: unlocked and freeing", __func__);
181 zlog_backtrace (LOG_DEBUG);
182 #endif
183 bgp_info_free (binfo);
184 return NULL;
185 }
186
187 #if 0
188 if (binfo->lock == 1)
189 {
190 zlog_debug ("%s: unlocked to 1", __func__);
191 zlog_backtrace (LOG_DEBUG);
192 }
193 #endif
194
195 return binfo;
196 }
197
198 void
199 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
200 {
201 struct bgp_info *top;
202
203 top = rn->info;
204
205 ri->next = rn->info;
206 ri->prev = NULL;
207 if (top)
208 top->prev = ri;
209 rn->info = ri;
210
211 bgp_info_lock (ri);
212 bgp_lock_node (rn);
213 peer_lock (ri->peer); /* bgp_info peer reference */
214 }
215
216 /* Do the actual removal of info from RIB, for use by bgp_process
217 completion callback *only* */
218 static void
219 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
220 {
221 if (ri->next)
222 ri->next->prev = ri->prev;
223 if (ri->prev)
224 ri->prev->next = ri->next;
225 else
226 rn->info = ri->next;
227
228 bgp_info_mpath_dequeue (ri);
229 bgp_info_unlock (ri);
230 bgp_unlock_node (rn);
231 }
232
233 void
234 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
235 {
236 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
237 /* set of previous already took care of pcount */
238 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
239 }
240
241 /* undo the effects of a previous call to bgp_info_delete; typically
242 called when a route is deleted and then quickly re-added before the
243 deletion has been processed */
244 void
245 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
246 {
247 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
248 /* unset of previous already took care of pcount */
249 SET_FLAG (ri->flags, BGP_INFO_VALID);
250 }
251
252 /* Adjust pcount as required */
253 static void
254 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
255 {
256 struct bgp_table *table;
257
258 assert (rn && bgp_node_table (rn));
259 assert (ri && ri->peer && ri->peer->bgp);
260
261 table = bgp_node_table (rn);
262
263 if (ri->peer == ri->peer->bgp->peer_self)
264 return;
265
266 if (!BGP_INFO_COUNTABLE (ri)
267 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
268 {
269
270 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
271
272 /* slight hack, but more robust against errors. */
273 if (ri->peer->pcount[table->afi][table->safi])
274 ri->peer->pcount[table->afi][table->safi]--;
275 else
276 {
277 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
278 __func__, ri->peer->host);
279 zlog_backtrace (LOG_WARNING);
280 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
281 }
282 }
283 else if (BGP_INFO_COUNTABLE (ri)
284 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
285 {
286 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
287 ri->peer->pcount[table->afi][table->safi]++;
288 }
289 }
290
291
292 /* Set/unset bgp_info flags, adjusting any other state as needed.
293 * This is here primarily to keep prefix-count in check.
294 */
295 void
296 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
297 {
298 SET_FLAG (ri->flags, flag);
299
300 /* early bath if we know it's not a flag that changes countability state */
301 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
302 return;
303
304 bgp_pcount_adjust (rn, ri);
305 }
306
307 void
308 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
309 {
310 UNSET_FLAG (ri->flags, flag);
311
312 /* early bath if we know it's not a flag that changes countability state */
313 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
314 return;
315
316 bgp_pcount_adjust (rn, ri);
317 }
318
319 /* Get MED value. If MED value is missing and "bgp bestpath
320 missing-as-worst" is specified, treat it as the worst value. */
321 static u_int32_t
322 bgp_med_value (struct attr *attr, struct bgp *bgp)
323 {
324 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
325 return attr->med;
326 else
327 {
328 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
329 return BGP_MED_MAX;
330 else
331 return 0;
332 }
333 }
334
335 void
336 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
337 {
338 if (ri->addpath_rx_id)
339 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
340 else
341 sprintf(buf, "path %s", ri->peer->host);
342 }
343
344 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
345 static int
346 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
347 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
348 const char *pfx_buf)
349 {
350 struct attr *newattr, *existattr;
351 struct attr_extra *newattre, *existattre;
352 bgp_peer_sort_t new_sort;
353 bgp_peer_sort_t exist_sort;
354 u_int32_t new_pref;
355 u_int32_t exist_pref;
356 u_int32_t new_med;
357 u_int32_t exist_med;
358 u_int32_t new_weight;
359 u_int32_t exist_weight;
360 uint32_t newm, existm;
361 struct in_addr new_id;
362 struct in_addr exist_id;
363 int new_cluster;
364 int exist_cluster;
365 int internal_as_route;
366 int confed_as_route;
367 int ret;
368 char new_buf[PATH_ADDPATH_STR_BUFFER];
369 char exist_buf[PATH_ADDPATH_STR_BUFFER];
370
371 *paths_eq = 0;
372
373 /* 0. Null check. */
374 if (new == NULL)
375 {
376 if (debug)
377 zlog_debug("%s: new is NULL", pfx_buf);
378 return 0;
379 }
380
381 if (debug)
382 bgp_info_path_with_addpath_rx_str (new, new_buf);
383
384 if (exist == NULL)
385 {
386 if (debug)
387 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
388 return 1;
389 }
390
391 if (debug)
392 {
393 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
394 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
395 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
396 }
397
398 newattr = new->attr;
399 existattr = exist->attr;
400 newattre = newattr->extra;
401 existattre = existattr->extra;
402
403 /* 1. Weight check. */
404 new_weight = exist_weight = 0;
405
406 if (newattre)
407 new_weight = newattre->weight;
408 if (existattre)
409 exist_weight = existattre->weight;
410
411 if (new_weight > exist_weight)
412 {
413 if (debug)
414 zlog_debug("%s: %s wins over %s due to weight %d > %d",
415 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
416 return 1;
417 }
418
419 if (new_weight < exist_weight)
420 {
421 if (debug)
422 zlog_debug("%s: %s loses to %s due to weight %d < %d",
423 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
424 return 0;
425 }
426
427 /* 2. Local preference check. */
428 new_pref = exist_pref = bgp->default_local_pref;
429
430 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
431 new_pref = newattr->local_pref;
432 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
433 exist_pref = existattr->local_pref;
434
435 if (new_pref > exist_pref)
436 {
437 if (debug)
438 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
439 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
440 return 1;
441 }
442
443 if (new_pref < exist_pref)
444 {
445 if (debug)
446 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
447 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
448 return 0;
449 }
450
451 /* 3. Local route check. We prefer:
452 * - BGP_ROUTE_STATIC
453 * - BGP_ROUTE_AGGREGATE
454 * - BGP_ROUTE_REDISTRIBUTE
455 */
456 if (! (new->sub_type == BGP_ROUTE_NORMAL))
457 {
458 if (debug)
459 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
460 pfx_buf, new_buf, exist_buf);
461 return 1;
462 }
463
464 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
465 {
466 if (debug)
467 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
468 pfx_buf, new_buf, exist_buf);
469 return 0;
470 }
471
472 /* 4. AS path length check. */
473 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
474 {
475 int exist_hops = aspath_count_hops (existattr->aspath);
476 int exist_confeds = aspath_count_confeds (existattr->aspath);
477
478 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
479 {
480 int aspath_hops;
481
482 aspath_hops = aspath_count_hops (newattr->aspath);
483 aspath_hops += aspath_count_confeds (newattr->aspath);
484
485 if ( aspath_hops < (exist_hops + exist_confeds))
486 {
487 if (debug)
488 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
489 pfx_buf, new_buf, exist_buf,
490 aspath_hops, (exist_hops + exist_confeds));
491 return 1;
492 }
493
494 if ( aspath_hops > (exist_hops + exist_confeds))
495 {
496 if (debug)
497 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
498 pfx_buf, new_buf, exist_buf,
499 aspath_hops, (exist_hops + exist_confeds));
500 return 0;
501 }
502 }
503 else
504 {
505 int newhops = aspath_count_hops (newattr->aspath);
506
507 if (newhops < exist_hops)
508 {
509 if (debug)
510 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
511 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
512 return 1;
513 }
514
515 if (newhops > exist_hops)
516 {
517 if (debug)
518 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
519 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
520 return 0;
521 }
522 }
523 }
524
525 /* 5. Origin check. */
526 if (newattr->origin < existattr->origin)
527 {
528 if (debug)
529 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
530 pfx_buf, new_buf, exist_buf,
531 bgp_origin_long_str[newattr->origin],
532 bgp_origin_long_str[existattr->origin]);
533 return 1;
534 }
535
536 if (newattr->origin > existattr->origin)
537 {
538 if (debug)
539 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
540 pfx_buf, new_buf, exist_buf,
541 bgp_origin_long_str[newattr->origin],
542 bgp_origin_long_str[existattr->origin]);
543 return 0;
544 }
545
546 /* 6. MED check. */
547 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
548 && aspath_count_hops (existattr->aspath) == 0);
549 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
550 && aspath_count_confeds (existattr->aspath) > 0
551 && aspath_count_hops (newattr->aspath) == 0
552 && aspath_count_hops (existattr->aspath) == 0);
553
554 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
555 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
556 && confed_as_route)
557 || aspath_cmp_left (newattr->aspath, existattr->aspath)
558 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
559 || internal_as_route)
560 {
561 new_med = bgp_med_value (new->attr, bgp);
562 exist_med = bgp_med_value (exist->attr, bgp);
563
564 if (new_med < exist_med)
565 {
566 if (debug)
567 zlog_debug("%s: %s wins over %s due to MED %d < %d",
568 pfx_buf, new_buf, exist_buf, new_med, exist_med);
569 return 1;
570 }
571
572 if (new_med > exist_med)
573 {
574 if (debug)
575 zlog_debug("%s: %s loses to %s due to MED %d > %d",
576 pfx_buf, new_buf, exist_buf, new_med, exist_med);
577 return 0;
578 }
579 }
580
581 /* 7. Peer type check. */
582 new_sort = new->peer->sort;
583 exist_sort = exist->peer->sort;
584
585 if (new_sort == BGP_PEER_EBGP
586 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
587 {
588 if (debug)
589 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
590 pfx_buf, new_buf, exist_buf);
591 return 1;
592 }
593
594 if (exist_sort == BGP_PEER_EBGP
595 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
596 {
597 if (debug)
598 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
599 pfx_buf, new_buf, exist_buf);
600 return 0;
601 }
602
603 /* 8. IGP metric check. */
604 newm = existm = 0;
605
606 if (new->extra)
607 newm = new->extra->igpmetric;
608 if (exist->extra)
609 existm = exist->extra->igpmetric;
610
611 if (newm < existm)
612 {
613 if (debug)
614 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
615 pfx_buf, new_buf, exist_buf, newm, existm);
616 ret = 1;
617 }
618
619 if (newm > existm)
620 {
621 if (debug)
622 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
623 pfx_buf, new_buf, exist_buf, newm, existm);
624 ret = 0;
625 }
626
627 /* 9. Same IGP metric. Compare the cluster list length as
628 representative of IGP hops metric. Rewrite the metric value
629 pair (newm, existm) with the cluster list length. Prefer the
630 path with smaller cluster list length. */
631 if (newm == existm)
632 {
633 if (peer_sort (new->peer) == BGP_PEER_IBGP
634 && peer_sort (exist->peer) == BGP_PEER_IBGP
635 && CHECK_FLAG (mpath_cfg->ibgp_flags,
636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
637 {
638 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
639 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
640
641 if (newm < existm)
642 {
643 if (debug)
644 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
645 pfx_buf, new_buf, exist_buf, newm, existm);
646 ret = 1;
647 }
648
649 if (newm > existm)
650 {
651 if (debug)
652 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
653 pfx_buf, new_buf, exist_buf, newm, existm);
654 ret = 0;
655 }
656 }
657 }
658
659 /* 10. confed-external vs. confed-internal */
660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
661 {
662 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
663 {
664 if (debug)
665 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
666 pfx_buf, new_buf, exist_buf);
667 return 1;
668 }
669
670 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
671 {
672 if (debug)
673 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
674 pfx_buf, new_buf, exist_buf);
675 return 0;
676 }
677 }
678
679 /* 11. Maximum path check. */
680 if (newm == existm)
681 {
682 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
683 {
684
685 /*
686 * For the two paths, all comparison steps till IGP metric
687 * have succeeded - including AS_PATH hop count. Since 'bgp
688 * bestpath as-path multipath-relax' knob is on, we don't need
689 * an exact match of AS_PATH. Thus, mark the paths are equal.
690 * That will trigger both these paths to get into the multipath
691 * array.
692 */
693 *paths_eq = 1;
694
695 if (debug)
696 zlog_debug("%s: %s and %s are equal via multipath-relax",
697 pfx_buf, new_buf, exist_buf);
698 }
699 else if (new->peer->sort == BGP_PEER_IBGP)
700 {
701 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
702 {
703 *paths_eq = 1;
704
705 if (debug)
706 zlog_debug("%s: %s and %s are equal via matching aspaths",
707 pfx_buf, new_buf, exist_buf);
708 }
709 }
710 else if (new->peer->as == exist->peer->as)
711 {
712 *paths_eq = 1;
713
714 if (debug)
715 zlog_debug("%s: %s and %s are equal via same remote-as",
716 pfx_buf, new_buf, exist_buf);
717 }
718 }
719 else
720 {
721 /*
722 * TODO: If unequal cost ibgp multipath is enabled we can
723 * mark the paths as equal here instead of returning
724 */
725 if (debug)
726 {
727 if (ret == 1)
728 zlog_debug("%s: %s wins over %s after IGP metric comparison",
729 pfx_buf, new_buf, exist_buf);
730 else
731 zlog_debug("%s: %s loses to %s after IGP metric comparison",
732 pfx_buf, new_buf, exist_buf);
733 }
734 return ret;
735 }
736
737 /* 12. If both paths are external, prefer the path that was received
738 first (the oldest one). This step minimizes route-flap, since a
739 newer path won't displace an older one, even if it was the
740 preferred route based on the additional decision criteria below. */
741 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
742 && new_sort == BGP_PEER_EBGP
743 && exist_sort == BGP_PEER_EBGP)
744 {
745 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
746 {
747 if (debug)
748 zlog_debug("%s: %s wins over %s due to oldest external",
749 pfx_buf, new_buf, exist_buf);
750 return 1;
751 }
752
753 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
754 {
755 if (debug)
756 zlog_debug("%s: %s loses to %s due to oldest external",
757 pfx_buf, new_buf, exist_buf);
758 return 0;
759 }
760 }
761
762 /* 13. Router-ID comparision. */
763 /* If one of the paths is "stale", the corresponding peer router-id will
764 * be 0 and would always win over the other path. If originator id is
765 * used for the comparision, it will decide which path is better.
766 */
767 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
768 new_id.s_addr = newattre->originator_id.s_addr;
769 else
770 new_id.s_addr = new->peer->remote_id.s_addr;
771 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
772 exist_id.s_addr = existattre->originator_id.s_addr;
773 else
774 exist_id.s_addr = exist->peer->remote_id.s_addr;
775
776 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
777 {
778 if (debug)
779 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
780 pfx_buf, new_buf, exist_buf);
781 return 1;
782 }
783
784 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
785 {
786 if (debug)
787 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
788 pfx_buf, new_buf, exist_buf);
789 return 0;
790 }
791
792 /* 14. Cluster length comparision. */
793 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
794 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
795
796 if (new_cluster < exist_cluster)
797 {
798 if (debug)
799 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
800 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
801 return 1;
802 }
803
804 if (new_cluster > exist_cluster)
805 {
806 if (debug)
807 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
808 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
809 return 0;
810 }
811
812 /* 15. Neighbor address comparision. */
813 /* Do this only if neither path is "stale" as stale paths do not have
814 * valid peer information (as the connection may or may not be up).
815 */
816 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
817 {
818 if (debug)
819 zlog_debug("%s: %s wins over %s due to latter path being STALE",
820 pfx_buf, new_buf, exist_buf);
821 return 1;
822 }
823
824 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
825 {
826 if (debug)
827 zlog_debug("%s: %s loses to %s due to former path being STALE",
828 pfx_buf, new_buf, exist_buf);
829 return 0;
830 }
831
832 /* locally configured routes to advertise do not have su_remote */
833 if (new->peer->su_remote == NULL)
834 return 0;
835 if (exist->peer->su_remote == NULL)
836 return 1;
837
838 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
839
840 if (ret == 1)
841 {
842 if (debug)
843 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
844 pfx_buf, new_buf, exist_buf);
845 return 0;
846 }
847
848 if (ret == -1)
849 {
850 if (debug)
851 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
852 pfx_buf, new_buf, exist_buf);
853 return 1;
854 }
855
856 if (debug)
857 zlog_debug("%s: %s wins over %s due to nothing left to compare",
858 pfx_buf, new_buf, exist_buf);
859
860 return 1;
861 }
862
863 /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
864 * is preferred, or 0 if they are the same (usually will only occur if
865 * multipath is enabled
866 * This version is compatible with */
867 int
868 bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
869 afi_t afi, safi_t safi)
870 {
871 int paths_eq;
872 struct bgp_maxpaths_cfg mpath_cfg;
873 int ret;
874 ret = bgp_info_cmp (bgp, new, exist, &paths_eq, &mpath_cfg, 0, __func__);
875
876 if (paths_eq)
877 ret = 0;
878 else
879 {
880 if (ret == 1)
881 ret = -1;
882 else
883 ret = 1;
884 }
885 return ret;
886 }
887
888 static enum filter_type
889 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
890 afi_t afi, safi_t safi)
891 {
892 struct bgp_filter *filter;
893
894 filter = &peer->filter[afi][safi];
895
896 #define FILTER_EXIST_WARN(F,f,filter) \
897 if (BGP_DEBUG (update, UPDATE_IN) \
898 && !(F ## _IN (filter))) \
899 zlog_warn ("%s: Could not find configured input %s-list %s!", \
900 peer->host, #f, F ## _IN_NAME(filter));
901
902 if (DISTRIBUTE_IN_NAME (filter)) {
903 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
904
905 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
906 return FILTER_DENY;
907 }
908
909 if (PREFIX_LIST_IN_NAME (filter)) {
910 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
911
912 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
913 return FILTER_DENY;
914 }
915
916 if (FILTER_LIST_IN_NAME (filter)) {
917 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
918
919 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
920 return FILTER_DENY;
921 }
922
923 return FILTER_PERMIT;
924 #undef FILTER_EXIST_WARN
925 }
926
927 static enum filter_type
928 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
929 afi_t afi, safi_t safi)
930 {
931 struct bgp_filter *filter;
932
933 filter = &peer->filter[afi][safi];
934
935 #define FILTER_EXIST_WARN(F,f,filter) \
936 if (BGP_DEBUG (update, UPDATE_OUT) \
937 && !(F ## _OUT (filter))) \
938 zlog_warn ("%s: Could not find configured output %s-list %s!", \
939 peer->host, #f, F ## _OUT_NAME(filter));
940
941 if (DISTRIBUTE_OUT_NAME (filter)) {
942 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
943
944 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
945 return FILTER_DENY;
946 }
947
948 if (PREFIX_LIST_OUT_NAME (filter)) {
949 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
950
951 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
952 return FILTER_DENY;
953 }
954
955 if (FILTER_LIST_OUT_NAME (filter)) {
956 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
957
958 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
959 return FILTER_DENY;
960 }
961
962 return FILTER_PERMIT;
963 #undef FILTER_EXIST_WARN
964 }
965
966 /* If community attribute includes no_export then return 1. */
967 static int
968 bgp_community_filter (struct peer *peer, struct attr *attr)
969 {
970 if (attr->community)
971 {
972 /* NO_ADVERTISE check. */
973 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
974 return 1;
975
976 /* NO_EXPORT check. */
977 if (peer->sort == BGP_PEER_EBGP &&
978 community_include (attr->community, COMMUNITY_NO_EXPORT))
979 return 1;
980
981 /* NO_EXPORT_SUBCONFED check. */
982 if (peer->sort == BGP_PEER_EBGP
983 || peer->sort == BGP_PEER_CONFED)
984 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
985 return 1;
986 }
987 return 0;
988 }
989
990 /* Route reflection loop check. */
991 static int
992 bgp_cluster_filter (struct peer *peer, struct attr *attr)
993 {
994 struct in_addr cluster_id;
995
996 if (attr->extra && attr->extra->cluster)
997 {
998 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
999 cluster_id = peer->bgp->cluster_id;
1000 else
1001 cluster_id = peer->bgp->router_id;
1002
1003 if (cluster_loop_check (attr->extra->cluster, cluster_id))
1004 return 1;
1005 }
1006 return 0;
1007 }
1008
1009 static int
1010 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1011 afi_t afi, safi_t safi, const char *rmap_name)
1012 {
1013 struct bgp_filter *filter;
1014 struct bgp_info info;
1015 route_map_result_t ret;
1016 struct route_map *rmap = NULL;
1017
1018 filter = &peer->filter[afi][safi];
1019
1020 /* Apply default weight value. */
1021 if (peer->weight[afi][safi])
1022 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1023
1024 if (rmap_name)
1025 {
1026 rmap = route_map_lookup_by_name(rmap_name);
1027
1028 if (rmap == NULL)
1029 return RMAP_DENY;
1030 }
1031 else
1032 {
1033 if (ROUTE_MAP_IN_NAME(filter))
1034 {
1035 rmap = ROUTE_MAP_IN (filter);
1036
1037 if (rmap == NULL)
1038 return RMAP_DENY;
1039 }
1040 }
1041
1042 /* Route map apply. */
1043 if (rmap)
1044 {
1045 /* Duplicate current value to new strucutre for modification. */
1046 info.peer = peer;
1047 info.attr = attr;
1048
1049 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1050
1051 /* Apply BGP route map to the attribute. */
1052 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1053
1054 peer->rmap_type = 0;
1055
1056 if (ret == RMAP_DENYMATCH)
1057 {
1058 /* Free newly generated AS path and community by route-map. */
1059 bgp_attr_flush (attr);
1060 return RMAP_DENY;
1061 }
1062 }
1063 return RMAP_PERMIT;
1064 }
1065
1066 static int
1067 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1068 afi_t afi, safi_t safi, const char *rmap_name)
1069 {
1070 struct bgp_filter *filter;
1071 struct bgp_info info;
1072 route_map_result_t ret;
1073 struct route_map *rmap = NULL;
1074
1075 filter = &peer->filter[afi][safi];
1076
1077 /* Apply default weight value. */
1078 if (peer->weight[afi][safi])
1079 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1080
1081 if (rmap_name)
1082 {
1083 rmap = route_map_lookup_by_name(rmap_name);
1084
1085 if (rmap == NULL)
1086 return RMAP_DENY;
1087 }
1088 else
1089 {
1090 if (ROUTE_MAP_OUT_NAME(filter))
1091 {
1092 rmap = ROUTE_MAP_OUT (filter);
1093
1094 if (rmap == NULL)
1095 return RMAP_DENY;
1096 }
1097 }
1098
1099 /* Route map apply. */
1100 if (rmap)
1101 {
1102 /* Duplicate current value to new strucutre for modification. */
1103 info.peer = peer;
1104 info.attr = attr;
1105
1106 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1107
1108 /* Apply BGP route map to the attribute. */
1109 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1110
1111 peer->rmap_type = 0;
1112
1113 if (ret == RMAP_DENYMATCH)
1114 /* caller has multiple error paths with bgp_attr_flush() */
1115 return RMAP_DENY;
1116 }
1117 return RMAP_PERMIT;
1118 }
1119
1120 /* If this is an EBGP peer with remove-private-AS */
1121 static void
1122 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1123 struct peer *peer, struct attr *attr)
1124 {
1125 if (peer->sort == BGP_PEER_EBGP &&
1126 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1128 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1129 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1130 {
1131 // Take action on the entire aspath
1132 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1133 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1134 {
1135 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1136 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1137
1138 // The entire aspath consists of private ASNs so create an empty aspath
1139 else if (aspath_private_as_check (attr->aspath))
1140 attr->aspath = aspath_empty_get ();
1141
1142 // There are some public and some private ASNs, remove the private ASNs
1143 else
1144 attr->aspath = aspath_remove_private_asns (attr->aspath);
1145 }
1146
1147 // 'all' was not specified so the entire aspath must be private ASNs
1148 // for us to do anything
1149 else if (aspath_private_as_check (attr->aspath))
1150 {
1151 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1152 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1153 else
1154 attr->aspath = aspath_empty_get ();
1155 }
1156 }
1157 }
1158
1159 /* If this is an EBGP peer with as-override */
1160 static void
1161 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1162 struct peer *peer, struct attr *attr)
1163 {
1164 if (peer->sort == BGP_PEER_EBGP &&
1165 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1166 {
1167 if (aspath_single_asn_check (attr->aspath, peer->as))
1168 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1169 }
1170 }
1171
1172 static void
1173 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1174 {
1175 if (family == AF_INET)
1176 attr->nexthop.s_addr = 0;
1177 #ifdef HAVE_IPV6
1178 if (family == AF_INET6)
1179 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1180 #endif
1181 }
1182
1183 int
1184 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1185 struct prefix *p, struct attr *attr)
1186 {
1187 struct bgp_filter *filter;
1188 struct peer *from;
1189 struct peer *peer;
1190 struct peer *onlypeer;
1191 struct bgp *bgp;
1192 struct attr *riattr;
1193 struct peer_af *paf;
1194 char buf[SU_ADDRSTRLEN];
1195 int ret;
1196 int transparent;
1197 int reflect;
1198 afi_t afi;
1199 safi_t safi;
1200 int samepeer_safe = 0; /* for synthetic mplsvpns routes */
1201
1202 if (DISABLE_BGP_ANNOUNCE)
1203 return 0;
1204
1205 afi = SUBGRP_AFI(subgrp);
1206 safi = SUBGRP_SAFI(subgrp);
1207 peer = SUBGRP_PEER(subgrp);
1208 onlypeer = NULL;
1209 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1210 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1211
1212 from = ri->peer;
1213 filter = &peer->filter[afi][safi];
1214 bgp = SUBGRP_INST(subgrp);
1215 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1216
1217 #if ENABLE_BGP_VNC
1218 if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) &&
1219 ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) ||
1220 (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
1221
1222 /*
1223 * direct and direct_ext type routes originate internally even
1224 * though they can have peer pointers that reference other systems
1225 */
1226 char buf[BUFSIZ];
1227 prefix2str(p, buf, BUFSIZ);
1228 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf);
1229 samepeer_safe = 1;
1230 }
1231 #endif
1232
1233 /* With addpath we may be asked to TX all kinds of paths so make sure
1234 * ri is valid */
1235 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1236 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1237 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1238 {
1239 return 0;
1240 }
1241
1242 /* If this is not the bestpath then check to see if there is an enabled addpath
1243 * feature that requires us to advertise it */
1244 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1245 {
1246 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1247 {
1248 return 0;
1249 }
1250 }
1251
1252 /* Aggregate-address suppress check. */
1253 if (ri->extra && ri->extra->suppress)
1254 if (! UNSUPPRESS_MAP_NAME (filter))
1255 {
1256 return 0;
1257 }
1258
1259 /* Do not send back route to sender. */
1260 if (onlypeer && from == onlypeer)
1261 {
1262 return 0;
1263 }
1264
1265 /* Do not send the default route in the BGP table if the neighbor is
1266 * configured for default-originate */
1267 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1268 {
1269 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1270 return 0;
1271 #ifdef HAVE_IPV6
1272 else if (p->family == AF_INET6 && p->prefixlen == 0)
1273 return 0;
1274 #endif /* HAVE_IPV6 */
1275 }
1276
1277 /* Transparency check. */
1278 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1279 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1280 transparent = 1;
1281 else
1282 transparent = 0;
1283
1284 /* If community is not disabled check the no-export and local. */
1285 if (! transparent && bgp_community_filter (peer, riattr))
1286 {
1287 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1288 zlog_debug ("subgrpannouncecheck: community filter check fail");
1289 return 0;
1290 }
1291
1292 /* If the attribute has originator-id and it is same as remote
1293 peer's id. */
1294 if (onlypeer &&
1295 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1296 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1297 {
1298 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1299 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1300 "remote router-id",
1301 onlypeer->host,
1302 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1303 p->prefixlen);
1304 return 0;
1305 }
1306
1307 /* ORF prefix-list filter check */
1308 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1309 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1310 || CHECK_FLAG (peer->af_cap[afi][safi],
1311 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1312 if (peer->orf_plist[afi][safi])
1313 {
1314 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1315 {
1316 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1317 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1318 peer->host,
1319 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1320 p->prefixlen);
1321 return 0;
1322 }
1323 }
1324
1325 /* Output filter check. */
1326 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1327 {
1328 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1329 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1330 peer->host,
1331 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1332 p->prefixlen);
1333 return 0;
1334 }
1335
1336 #ifdef BGP_SEND_ASPATH_CHECK
1337 /* AS path loop check. */
1338 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1339 {
1340 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1341 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1342 "that is part of AS path.",
1343 onlypeer->host, onlypeer->as);
1344 return 0;
1345 }
1346 #endif /* BGP_SEND_ASPATH_CHECK */
1347
1348 /* If we're a CONFED we need to loop check the CONFED ID too */
1349 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1350 {
1351 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1352 {
1353 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1354 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1355 " is AS path.",
1356 peer->host,
1357 bgp->confed_id);
1358 return 0;
1359 }
1360 }
1361
1362 /* Route-Reflect check. */
1363 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1364 reflect = 1;
1365 else
1366 reflect = 0;
1367
1368 /* IBGP reflection check. */
1369 if (reflect && !samepeer_safe)
1370 {
1371 /* A route from a Client peer. */
1372 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1373 {
1374 /* Reflect to all the Non-Client peers and also to the
1375 Client peers other than the originator. Originator check
1376 is already done. So there is noting to do. */
1377 /* no bgp client-to-client reflection check. */
1378 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1379 if (CHECK_FLAG (peer->af_flags[afi][safi],
1380 PEER_FLAG_REFLECTOR_CLIENT))
1381 return 0;
1382 }
1383 else
1384 {
1385 /* A route from a Non-client peer. Reflect to all other
1386 clients. */
1387 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1388 PEER_FLAG_REFLECTOR_CLIENT))
1389 return 0;
1390 }
1391 }
1392
1393 /* For modify attribute, copy it to temporary structure. */
1394 bgp_attr_dup (attr, riattr);
1395
1396 /* If local-preference is not set. */
1397 if ((peer->sort == BGP_PEER_IBGP
1398 || peer->sort == BGP_PEER_CONFED)
1399 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1400 {
1401 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1402 attr->local_pref = bgp->default_local_pref;
1403 }
1404
1405 /* If originator-id is not set and the route is to be reflected,
1406 set the originator id */
1407 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1408 {
1409 attr->extra = bgp_attr_extra_get(attr);
1410 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1411 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1412 }
1413
1414 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1415 if (peer->sort == BGP_PEER_EBGP
1416 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1417 {
1418 if (from != bgp->peer_self && ! transparent
1419 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1420 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1421 }
1422
1423 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1424 * in announce check, only certain flags and length (or number of nexthops
1425 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1426 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1427 * Typically, the source nexthop in the attribute is preserved but in the
1428 * scenarios where we know it will always be overwritten, we reset the
1429 * nexthop to "0" in an attempt to achieve better Update packing. An
1430 * example of this is when a prefix from each of 2 IBGP peers needs to be
1431 * announced to an EBGP peer (and they have the same attributes barring
1432 * their nexthop).
1433 */
1434 if (reflect)
1435 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1436
1437 #ifdef HAVE_IPV6
1438 #define NEXTHOP_IS_V6 (\
1439 (safi != SAFI_ENCAP && \
1440 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1441 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1442
1443 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1444 * the peer (group) is configured to receive link-local nexthop unchanged
1445 * and it is available in the prefix OR we're not reflecting the route and
1446 * the peer (group) to whom we're going to announce is on a shared network
1447 * and this is either a self-originated route or the peer is EBGP.
1448 */
1449 if (NEXTHOP_IS_V6)
1450 {
1451 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1452 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1454 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1455 (!reflect && peer->shared_network &&
1456 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1457 {
1458 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1459 }
1460
1461 /* Clear off link-local nexthop in source, whenever it is not needed to
1462 * ensure more prefixes share the same attribute for announcement.
1463 */
1464 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1465 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1466 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1467 }
1468 #endif /* HAVE_IPV6 */
1469
1470 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1471 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1472
1473 /* Route map & unsuppress-map apply. */
1474 if (ROUTE_MAP_OUT_NAME (filter)
1475 || (ri->extra && ri->extra->suppress) )
1476 {
1477 struct bgp_info info;
1478 struct attr dummy_attr;
1479 struct attr_extra dummy_extra;
1480
1481 dummy_attr.extra = &dummy_extra;
1482
1483 info.peer = peer;
1484 info.attr = attr;
1485 /* don't confuse inbound and outbound setting */
1486 RESET_FLAG(attr->rmap_change_flags);
1487
1488 /*
1489 * The route reflector is not allowed to modify the attributes
1490 * of the reflected IBGP routes unless explicitly allowed.
1491 */
1492 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1493 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1494 {
1495 bgp_attr_dup (&dummy_attr, attr);
1496 info.attr = &dummy_attr;
1497 }
1498
1499 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1500
1501 if (ri->extra && ri->extra->suppress)
1502 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1503 else
1504 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1505
1506 peer->rmap_type = 0;
1507
1508 if (ret == RMAP_DENYMATCH)
1509 {
1510 bgp_attr_flush (attr);
1511 return 0;
1512 }
1513 }
1514
1515 /* After route-map has been applied, we check to see if the nexthop to
1516 * be carried in the attribute (that is used for the announcement) can
1517 * be cleared off or not. We do this in all cases where we would be
1518 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1519 * the global nexthop here; the link-local nexthop would have been cleared
1520 * already, and if not, it is required by the update formation code.
1521 * Also see earlier comments in this function.
1522 */
1523 /*
1524 * If route-map has performed some operation on the nexthop or the peer
1525 * configuration says to pass it unchanged, we cannot reset the nexthop
1526 * here, so only attempt to do it if these aren't true. Note that the
1527 * route-map handler itself might have cleared the nexthop, if for example,
1528 * it is configured as 'peer-address'.
1529 */
1530 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1531 riattr->rmap_change_flags) &&
1532 !transparent &&
1533 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1534 {
1535 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1537 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1538 {
1539 if (!reflect ||
1540 CHECK_FLAG (peer->af_flags[afi][safi],
1541 PEER_FLAG_FORCE_NEXTHOP_SELF))
1542 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1543 AF_INET6 : p->family), attr);
1544 }
1545 else if (peer->sort == BGP_PEER_EBGP)
1546 {
1547 /* Can also reset the nexthop if announcing to EBGP, but only if
1548 * no peer in the subgroup is on a shared subnet.
1549 * Note: 3rd party nexthop currently implemented for IPv4 only.
1550 */
1551 SUBGRP_FOREACH_PEER (subgrp, paf)
1552 {
1553 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1554 break;
1555 }
1556 if (!paf)
1557 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1558 }
1559 /* If IPv6/MP and nexthop does not have any override and happens to
1560 * be a link-local address, reset it so that we don't pass along the
1561 * source's link-local IPv6 address to recipients who may not be on
1562 * the same interface.
1563 */
1564 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1565 {
1566 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1567 subgroup_announce_reset_nhop (AF_INET6, attr);
1568 }
1569 }
1570
1571 return 1;
1572 }
1573
1574 struct bgp_info_pair
1575 {
1576 struct bgp_info *old;
1577 struct bgp_info *new;
1578 };
1579
1580 static void
1581 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1582 struct bgp_maxpaths_cfg *mpath_cfg,
1583 struct bgp_info_pair *result)
1584 {
1585 struct bgp_info *new_select;
1586 struct bgp_info *old_select;
1587 struct bgp_info *ri;
1588 struct bgp_info *ri1;
1589 struct bgp_info *ri2;
1590 struct bgp_info *nextri = NULL;
1591 int paths_eq, do_mpath, debug;
1592 struct list mp_list;
1593 char pfx_buf[PREFIX2STR_BUFFER];
1594 char path_buf[PATH_ADDPATH_STR_BUFFER];
1595
1596 bgp_mp_list_init (&mp_list);
1597 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1598
1599 debug = bgp_debug_bestpath(&rn->p);
1600
1601 if (debug)
1602 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1603
1604 /* bgp deterministic-med */
1605 new_select = NULL;
1606 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1607 {
1608
1609 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1610 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1611 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1612
1613 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1614 {
1615 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1616 continue;
1617 if (BGP_INFO_HOLDDOWN (ri1))
1618 continue;
1619 if (ri1->peer && ri1->peer != bgp->peer_self)
1620 if (ri1->peer->status != Established)
1621 continue;
1622
1623 new_select = ri1;
1624 if (ri1->next)
1625 {
1626 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1627 {
1628 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1629 continue;
1630 if (BGP_INFO_HOLDDOWN (ri2))
1631 continue;
1632 if (ri2->peer &&
1633 ri2->peer != bgp->peer_self &&
1634 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1635 if (ri2->peer->status != Established)
1636 continue;
1637
1638 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1639 || aspath_cmp_left_confed (ri1->attr->aspath,
1640 ri2->attr->aspath))
1641 {
1642 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1643 mpath_cfg, debug, pfx_buf))
1644 {
1645 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1646 new_select = ri2;
1647 }
1648
1649 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1650 }
1651 }
1652 }
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1654 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1655
1656 if (debug)
1657 {
1658 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1659 zlog_debug("%s: %s is the bestpath from AS %d",
1660 pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath));
1661 }
1662 }
1663 }
1664
1665 /* Check old selected route and new selected route. */
1666 old_select = NULL;
1667 new_select = NULL;
1668 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1669 {
1670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1671 old_select = ri;
1672
1673 if (BGP_INFO_HOLDDOWN (ri))
1674 {
1675 /* reap REMOVED routes, if needs be
1676 * selected route must stay for a while longer though
1677 */
1678 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1679 && (ri != old_select))
1680 bgp_info_reap (rn, ri);
1681
1682 continue;
1683 }
1684
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
1691 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1692 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1693 {
1694 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1695 continue;
1696 }
1697
1698 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1699
1700 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1701 {
1702 new_select = ri;
1703 }
1704 }
1705
1706 /* Now that we know which path is the bestpath see if any of the other paths
1707 * qualify as multipaths
1708 */
1709 if (debug)
1710 {
1711 if (new_select)
1712 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1713 else
1714 sprintf (path_buf, "NONE");
1715 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1716 pfx_buf, path_buf,
1717 old_select ? old_select->peer->host : "NONE");
1718 }
1719
1720 if (do_mpath && new_select)
1721 {
1722 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1723 {
1724
1725 if (debug)
1726 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1727
1728 if (ri == new_select)
1729 {
1730 if (debug)
1731 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1732 pfx_buf, path_buf);
1733 bgp_mp_list_add (&mp_list, ri);
1734 continue;
1735 }
1736
1737 if (BGP_INFO_HOLDDOWN (ri))
1738 continue;
1739
1740 if (ri->peer &&
1741 ri->peer != bgp->peer_self &&
1742 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1743 if (ri->peer->status != Established)
1744 continue;
1745
1746 if (!bgp_info_nexthop_cmp (ri, new_select))
1747 {
1748 if (debug)
1749 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1750 pfx_buf, path_buf);
1751 continue;
1752 }
1753
1754 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1755
1756 if (paths_eq)
1757 {
1758 if (debug)
1759 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1760 pfx_buf, path_buf);
1761 bgp_mp_list_add (&mp_list, ri);
1762 }
1763 }
1764 }
1765
1766 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1767 bgp_info_mpath_aggregate_update (new_select, old_select);
1768 bgp_mp_list_clear (&mp_list);
1769
1770 result->old = old_select;
1771 result->new = new_select;
1772
1773 return;
1774 }
1775
1776 /*
1777 * A new route/change in bestpath of an existing route. Evaluate the path
1778 * for advertisement to the subgroup.
1779 */
1780 int
1781 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1782 struct bgp_info *selected,
1783 struct bgp_node *rn,
1784 u_int32_t addpath_tx_id)
1785 {
1786 struct prefix *p;
1787 struct peer *onlypeer;
1788 struct attr attr;
1789 struct attr_extra extra;
1790 afi_t afi;
1791 safi_t safi;
1792
1793 p = &rn->p;
1794 afi = SUBGRP_AFI(subgrp);
1795 safi = SUBGRP_SAFI(subgrp);
1796 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1797 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1798
1799 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1800 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1801 PEER_STATUS_ORF_WAIT_REFRESH))
1802 return 0;
1803
1804 /* It's initialized in bgp_announce_check() */
1805 attr.extra = &extra;
1806
1807 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1808 if (selected)
1809 {
1810 if (subgroup_announce_check(selected, subgrp, p, &attr))
1811 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1812 else
1813 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1814 }
1815
1816 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1817 else
1818 {
1819 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1820 }
1821
1822 return 0;
1823 }
1824
1825 /*
1826 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1827 * This is called at the end of route processing.
1828 */
1829 static void
1830 bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1831 {
1832 struct bgp_info *ri;
1833
1834 for (ri = rn->info; ri; ri = ri->next)
1835 {
1836 if (BGP_INFO_HOLDDOWN (ri))
1837 continue;
1838 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
1839 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1840 }
1841 }
1842
1843 /*
1844 * Has the route changed from the RIB's perspective? This is invoked only
1845 * if the route selection returns the same best route as earlier - to
1846 * determine if we need to update zebra or not.
1847 */
1848 static int
1849 bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1850 {
1851 struct bgp_info *mpinfo;
1852
1853 /* If this is multipath, check all selected paths for any nexthop change or
1854 * attribute change. Some attribute changes (e.g., community) aren't of
1855 * relevance to the RIB, but we'll update zebra to ensure we handle the
1856 * case of BGP nexthop change. This is the behavior when the best path has
1857 * an attribute change anyway.
1858 */
1859 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1860 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1861 return 1;
1862
1863 /* If this is multipath, check all selected paths for any nexthop change */
1864 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1865 mpinfo = bgp_info_mpath_next (mpinfo))
1866 {
1867 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1868 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
1869 return 1;
1870 }
1871
1872 /* Nothing has changed from the RIB's perspective. */
1873 return 0;
1874 }
1875
1876 struct bgp_process_queue
1877 {
1878 struct bgp *bgp;
1879 struct bgp_node *rn;
1880 afi_t afi;
1881 safi_t safi;
1882 };
1883
1884 static wq_item_status
1885 bgp_process_main (struct work_queue *wq, void *data)
1886 {
1887 struct bgp_process_queue *pq = data;
1888 struct bgp *bgp = pq->bgp;
1889 struct bgp_node *rn = pq->rn;
1890 afi_t afi = pq->afi;
1891 safi_t safi = pq->safi;
1892 struct prefix *p = &rn->p;
1893 struct bgp_info *new_select;
1894 struct bgp_info *old_select;
1895 struct bgp_info_pair old_and_new;
1896
1897 /* Is it end of initial update? (after startup) */
1898 if (!rn)
1899 {
1900 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1901 sizeof(bgp->update_delay_zebra_resume_time));
1902
1903 bgp->main_zebra_update_hold = 0;
1904 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1905 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1906 {
1907 bgp_zebra_announce_table(bgp, afi, safi);
1908 }
1909 bgp->main_peers_update_hold = 0;
1910
1911 bgp_start_routeadv(bgp);
1912 return WQ_SUCCESS;
1913 }
1914
1915 /* Best path selection. */
1916 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1917 old_select = old_and_new.old;
1918 new_select = old_and_new.new;
1919
1920 /* Nothing to do. */
1921 if (old_select && old_select == new_select &&
1922 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1923 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1924 !bgp->addpath_tx_used[afi][safi])
1925 {
1926 if (bgp_zebra_has_route_changed (rn, old_select))
1927 {
1928 #if ENABLE_BGP_VNC
1929 vnc_import_bgp_add_route(bgp, p, old_select);
1930 vnc_import_bgp_exterior_add_route(bgp, p, old_select);
1931 #endif
1932 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1933 }
1934 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1935 bgp_zebra_clear_route_change_flags (rn);
1936 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1937 return WQ_SUCCESS;
1938 }
1939
1940 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1941 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1942
1943 /* bestpath has changed; bump version */
1944 if (old_select || new_select)
1945 {
1946 bgp_bump_version(rn);
1947
1948 if (!bgp->t_rmap_def_originate_eval)
1949 {
1950 bgp_lock (bgp);
1951 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1952 update_group_refresh_default_originate_route_map,
1953 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1954 }
1955 }
1956
1957 if (old_select)
1958 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1959 if (new_select)
1960 {
1961 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1962 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1963 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1964 }
1965
1966 #if ENABLE_BGP_VNC
1967 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
1968 if (old_select != new_select) {
1969 if (old_select) {
1970 vnc_import_bgp_exterior_del_route(bgp, p, old_select);
1971 vnc_import_bgp_del_route(bgp, p, old_select);
1972 }
1973 if (new_select) {
1974 vnc_import_bgp_exterior_add_route(bgp, p, new_select);
1975 vnc_import_bgp_add_route(bgp, p, new_select);
1976 }
1977 }
1978 }
1979 #endif
1980
1981 group_announce_route(bgp, afi, safi, rn, new_select);
1982
1983 /* FIB update. */
1984 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1985 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1986 !bgp_option_check (BGP_OPT_NO_FIB))
1987 {
1988 if (new_select
1989 && new_select->type == ZEBRA_ROUTE_BGP
1990 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1991 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1992 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1993 else
1994 {
1995 /* Withdraw the route from the kernel. */
1996 if (old_select
1997 && old_select->type == ZEBRA_ROUTE_BGP
1998 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1999 old_select->sub_type == BGP_ROUTE_AGGREGATE))
2000 bgp_zebra_withdraw (p, old_select, safi);
2001 }
2002 }
2003
2004 /* Clear any route change flags. */
2005 bgp_zebra_clear_route_change_flags (rn);
2006
2007 /* Reap old select bgp_info, if it has been removed */
2008 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2009 bgp_info_reap (rn, old_select);
2010
2011 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2012 return WQ_SUCCESS;
2013 }
2014
2015 static void
2016 bgp_processq_del (struct work_queue *wq, void *data)
2017 {
2018 struct bgp_process_queue *pq = data;
2019 struct bgp_table *table;
2020
2021 bgp_unlock (pq->bgp);
2022 if (pq->rn)
2023 {
2024 table = bgp_node_table (pq->rn);
2025 bgp_unlock_node (pq->rn);
2026 bgp_table_unlock (table);
2027 }
2028 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2029 }
2030
2031 void
2032 bgp_process_queue_init (void)
2033 {
2034 if (!bm->process_main_queue)
2035 {
2036 bm->process_main_queue
2037 = work_queue_new (bm->master, "process_main_queue");
2038
2039 if ( !bm->process_main_queue)
2040 {
2041 zlog_err ("%s: Failed to allocate work queue", __func__);
2042 exit (1);
2043 }
2044 }
2045
2046 bm->process_main_queue->spec.workfunc = &bgp_process_main;
2047 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
2048 bm->process_main_queue->spec.max_retries = 0;
2049 bm->process_main_queue->spec.hold = 50;
2050 /* Use a higher yield value of 50ms for main queue processing */
2051 bm->process_main_queue->spec.yield = 50 * 1000L;
2052 }
2053
2054 void
2055 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2056 {
2057 struct bgp_process_queue *pqnode;
2058
2059 /* already scheduled for processing? */
2060 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2061 return;
2062
2063 if (bm->process_main_queue == NULL)
2064 bgp_process_queue_init ();
2065
2066 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2067 sizeof (struct bgp_process_queue));
2068 if (!pqnode)
2069 return;
2070
2071 /* all unlocked in bgp_processq_del */
2072 bgp_table_lock (bgp_node_table (rn));
2073 pqnode->rn = bgp_lock_node (rn);
2074 pqnode->bgp = bgp;
2075 bgp_lock (bgp);
2076 pqnode->afi = afi;
2077 pqnode->safi = safi;
2078 work_queue_add (bm->process_main_queue, pqnode);
2079 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2080 return;
2081 }
2082
2083 void
2084 bgp_add_eoiu_mark (struct bgp *bgp)
2085 {
2086 struct bgp_process_queue *pqnode;
2087
2088 if (bm->process_main_queue == NULL)
2089 bgp_process_queue_init ();
2090
2091 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2092 sizeof (struct bgp_process_queue));
2093 if (!pqnode)
2094 return;
2095
2096 pqnode->rn = NULL;
2097 pqnode->bgp = bgp;
2098 bgp_lock (bgp);
2099 work_queue_add (bm->process_main_queue, pqnode);
2100 }
2101
2102 static int
2103 bgp_maximum_prefix_restart_timer (struct thread *thread)
2104 {
2105 struct peer *peer;
2106
2107 peer = THREAD_ARG (thread);
2108 peer->t_pmax_restart = NULL;
2109
2110 if (bgp_debug_neighbor_events(peer))
2111 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2112 peer->host);
2113
2114 peer_clear (peer, NULL);
2115
2116 return 0;
2117 }
2118
2119 int
2120 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2121 safi_t safi, int always)
2122 {
2123 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2124 return 0;
2125
2126 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
2127 {
2128 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2129 && ! always)
2130 return 0;
2131
2132 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2133 "limit %ld", afi_safi_print (afi, safi), peer->host,
2134 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2135 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2136
2137 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2138 return 0;
2139
2140 {
2141 u_int8_t ndata[7];
2142
2143 if (safi == SAFI_MPLS_VPN)
2144 safi = SAFI_MPLS_LABELED_VPN;
2145
2146 ndata[0] = (afi >> 8);
2147 ndata[1] = afi;
2148 ndata[2] = safi;
2149 ndata[3] = (peer->pmax[afi][safi] >> 24);
2150 ndata[4] = (peer->pmax[afi][safi] >> 16);
2151 ndata[5] = (peer->pmax[afi][safi] >> 8);
2152 ndata[6] = (peer->pmax[afi][safi]);
2153
2154 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2155 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2156 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2157 }
2158
2159 /* Dynamic peers will just close their connection. */
2160 if (peer_dynamic_neighbor (peer))
2161 return 1;
2162
2163 /* restart timer start */
2164 if (peer->pmax_restart[afi][safi])
2165 {
2166 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2167
2168 if (bgp_debug_neighbor_events(peer))
2169 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2170 peer->host, peer->v_pmax_restart);
2171
2172 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2173 peer->v_pmax_restart);
2174 }
2175
2176 return 1;
2177 }
2178 else
2179 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2180
2181 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2182 {
2183 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2184 && ! always)
2185 return 0;
2186
2187 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2188 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2189 peer->pmax[afi][safi]);
2190 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2191 }
2192 else
2193 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2194 return 0;
2195 }
2196
2197 /* Unconditionally remove the route from the RIB, without taking
2198 * damping into consideration (eg, because the session went down)
2199 */
2200 static void
2201 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2202 afi_t afi, safi_t safi)
2203 {
2204 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2205
2206 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2207 bgp_info_delete (rn, ri); /* keep historical info */
2208
2209 bgp_process (peer->bgp, rn, afi, safi);
2210 }
2211
2212 static void
2213 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2214 afi_t afi, safi_t safi, struct prefix_rd *prd)
2215 {
2216 int status = BGP_DAMP_NONE;
2217
2218 /* apply dampening, if result is suppressed, we'll be retaining
2219 * the bgp_info in the RIB for historical reference.
2220 */
2221 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2222 && peer->sort == BGP_PEER_EBGP)
2223 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2224 == BGP_DAMP_SUPPRESSED)
2225 {
2226 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2227 return;
2228 }
2229
2230 #if ENABLE_BGP_VNC
2231 if (safi == SAFI_MPLS_VPN) {
2232 struct bgp_node *prn = NULL;
2233 struct bgp_table *table = NULL;
2234
2235 prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd);
2236 if (prn->info) {
2237 table = (struct bgp_table *)(prn->info);
2238
2239 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2240 peer->bgp,
2241 prd,
2242 table,
2243 &rn->p,
2244 ri);
2245 }
2246 bgp_unlock_node(prn);
2247 }
2248 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2249 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2250
2251 vnc_import_bgp_del_route(peer->bgp, &rn->p, ri);
2252 vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri);
2253 }
2254 }
2255 #endif
2256 bgp_rib_remove (rn, ri, peer, afi, safi);
2257 }
2258
2259 static struct bgp_info *
2260 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2261 struct bgp_node *rn)
2262 {
2263 struct bgp_info *new;
2264
2265 /* Make new BGP info. */
2266 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2267 new->type = type;
2268 new->instance = instance;
2269 new->sub_type = sub_type;
2270 new->peer = peer;
2271 new->attr = attr;
2272 new->uptime = bgp_clock ();
2273 new->net = rn;
2274 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2275 return new;
2276 }
2277
2278 static void
2279 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2280 {
2281 if (addpath_id)
2282 sprintf(buf, " with addpath ID %d", addpath_id);
2283 }
2284
2285
2286 /* Check if received nexthop is valid or not. */
2287 static int
2288 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2289 {
2290 struct attr_extra *attre = attr->extra;
2291 int ret = 0;
2292
2293 /* Only validated for unicast and multicast currently. */
2294 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2295 return 0;
2296
2297 /* If NEXT_HOP is present, validate it. */
2298 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2299 {
2300 if (attr->nexthop.s_addr == 0 ||
2301 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2302 bgp_nexthop_self (bgp, attr))
2303 ret = 1;
2304 }
2305
2306 /* If MP_NEXTHOP is present, validate it. */
2307 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2308 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2309 * it is not an IPv6 link-local address.
2310 */
2311 if (attre && attre->mp_nexthop_len)
2312 {
2313 switch (attre->mp_nexthop_len)
2314 {
2315 case BGP_ATTR_NHLEN_IPV4:
2316 case BGP_ATTR_NHLEN_VPNV4:
2317 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2318 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2319 break;
2320
2321 #ifdef HAVE_IPV6
2322 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2323 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2324 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2325 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2326 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2327 break;
2328 #endif /* HAVE_IPV6 */
2329
2330 default:
2331 ret = 1;
2332 break;
2333 }
2334 }
2335
2336 return ret;
2337 }
2338
2339 int
2340 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2341 struct attr *attr, afi_t afi, safi_t safi, int type,
2342 int sub_type, struct prefix_rd *prd, u_char *tag,
2343 int soft_reconfig)
2344 {
2345 int ret;
2346 int aspath_loop_count = 0;
2347 struct bgp_node *rn;
2348 struct bgp *bgp;
2349 struct attr new_attr;
2350 struct attr_extra new_extra;
2351 struct attr *attr_new;
2352 struct bgp_info *ri;
2353 struct bgp_info *new;
2354 const char *reason;
2355 char buf[SU_ADDRSTRLEN];
2356 char buf2[30];
2357 int connected = 0;
2358 int do_loop_check = 1;
2359 #if ENABLE_BGP_VNC
2360 int vnc_implicit_withdraw = 0;
2361 #endif
2362
2363 memset (&new_attr, 0, sizeof(struct attr));
2364 memset (&new_extra, 0, sizeof(struct attr_extra));
2365
2366 bgp = peer->bgp;
2367 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2368
2369 /* When peer's soft reconfiguration enabled. Record input packet in
2370 Adj-RIBs-In. */
2371 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2372 && peer != bgp->peer_self)
2373 bgp_adj_in_set (rn, peer, attr, addpath_id);
2374
2375 /* Check previously received route. */
2376 for (ri = rn->info; ri; ri = ri->next)
2377 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2378 ri->addpath_rx_id == addpath_id)
2379 break;
2380
2381 /* AS path local-as loop check. */
2382 if (peer->change_local_as)
2383 {
2384 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2385 aspath_loop_count = 1;
2386
2387 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2388 {
2389 reason = "as-path contains our own AS;";
2390 goto filtered;
2391 }
2392 }
2393
2394 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2395 * as-path is our ASN then we do not need to call aspath_loop_check
2396 */
2397 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2398 if (aspath_get_last_as(attr->aspath) == bgp->as)
2399 do_loop_check = 0;
2400
2401 /* AS path loop check. */
2402 if (do_loop_check)
2403 {
2404 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2405 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2406 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2407 {
2408 reason = "as-path contains our own AS;";
2409 goto filtered;
2410 }
2411 }
2412
2413 /* Route reflector originator ID check. */
2414 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2415 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2416 {
2417 reason = "originator is us;";
2418 goto filtered;
2419 }
2420
2421 /* Route reflector cluster ID check. */
2422 if (bgp_cluster_filter (peer, attr))
2423 {
2424 reason = "reflected from the same cluster;";
2425 goto filtered;
2426 }
2427
2428 /* Apply incoming filter. */
2429 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2430 {
2431 reason = "filter;";
2432 goto filtered;
2433 }
2434
2435 new_attr.extra = &new_extra;
2436 bgp_attr_dup (&new_attr, attr);
2437
2438 /* Apply incoming route-map.
2439 * NB: new_attr may now contain newly allocated values from route-map "set"
2440 * commands, so we need bgp_attr_flush in the error paths, until we intern
2441 * the attr (which takes over the memory references) */
2442 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2443 {
2444 reason = "route-map;";
2445 bgp_attr_flush (&new_attr);
2446 goto filtered;
2447 }
2448
2449 /* next hop check. */
2450 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2451 {
2452 reason = "martian or self next-hop;";
2453 bgp_attr_flush (&new_attr);
2454 goto filtered;
2455 }
2456
2457 attr_new = bgp_attr_intern (&new_attr);
2458
2459 /* If the update is implicit withdraw. */
2460 if (ri)
2461 {
2462 ri->uptime = bgp_clock ();
2463
2464 /* Same attribute comes in. */
2465 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2466 && attrhash_cmp (ri->attr, attr_new))
2467 {
2468 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2469 && peer->sort == BGP_PEER_EBGP
2470 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2471 {
2472 if (bgp_debug_update(peer, p, NULL, 1))
2473 {
2474 bgp_info_addpath_rx_str(addpath_id, buf2);
2475 zlog_debug ("%s rcvd %s/%d%s",
2476 peer->host,
2477 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2478 p->prefixlen, buf2);
2479 }
2480
2481 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2482 {
2483 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2484 bgp_process (bgp, rn, afi, safi);
2485 }
2486 }
2487 else /* Duplicate - odd */
2488 {
2489 if (bgp_debug_update(peer, p, NULL, 1))
2490 {
2491 if (!peer->rcvd_attr_printed)
2492 {
2493 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2494 peer->rcvd_attr_printed = 1;
2495 }
2496
2497 bgp_info_addpath_rx_str(addpath_id, buf2);
2498 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2499 peer->host,
2500 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2501 p->prefixlen, buf2);
2502 }
2503
2504 /* graceful restart STALE flag unset. */
2505 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2506 {
2507 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2508 bgp_process (bgp, rn, afi, safi);
2509 }
2510 }
2511
2512 bgp_unlock_node (rn);
2513 bgp_attr_unintern (&attr_new);
2514
2515 return 0;
2516 }
2517
2518 /* Withdraw/Announce before we fully processed the withdraw */
2519 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2520 {
2521 if (bgp_debug_update(peer, p, NULL, 1))
2522 {
2523 bgp_info_addpath_rx_str(addpath_id, buf2);
2524 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2525 peer->host,
2526 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2527 p->prefixlen, buf2);
2528 }
2529 bgp_info_restore (rn, ri);
2530 }
2531
2532 /* Received Logging. */
2533 if (bgp_debug_update(peer, p, NULL, 1))
2534 {
2535 bgp_info_addpath_rx_str(addpath_id, buf2);
2536 zlog_debug ("%s rcvd %s/%d%s",
2537 peer->host,
2538 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2539 p->prefixlen, buf2);
2540 }
2541
2542 /* graceful restart STALE flag unset. */
2543 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2544 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2545
2546 /* The attribute is changed. */
2547 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2548
2549 /* implicit withdraw, decrement aggregate and pcount here.
2550 * only if update is accepted, they'll increment below.
2551 */
2552 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2553
2554 /* Update bgp route dampening information. */
2555 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2556 && peer->sort == BGP_PEER_EBGP)
2557 {
2558 /* This is implicit withdraw so we should update dampening
2559 information. */
2560 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2561 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2562 }
2563 #if ENABLE_BGP_VNC
2564 if (safi == SAFI_MPLS_VPN) {
2565 struct bgp_node *prn = NULL;
2566 struct bgp_table *table = NULL;
2567
2568 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2569 if (prn->info) {
2570 table = (struct bgp_table *)(prn->info);
2571
2572 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2573 bgp,
2574 prd,
2575 table,
2576 p,
2577 ri);
2578 }
2579 bgp_unlock_node(prn);
2580 }
2581 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2582 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2583 /*
2584 * Implicit withdraw case.
2585 */
2586 ++vnc_implicit_withdraw;
2587 vnc_import_bgp_del_route(bgp, p, ri);
2588 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2589 }
2590 }
2591 #endif
2592
2593 /* Update to new attribute. */
2594 bgp_attr_unintern (&ri->attr);
2595 ri->attr = attr_new;
2596
2597 /* Update MPLS tag. */
2598 if (safi == SAFI_MPLS_VPN)
2599 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2600
2601 #if ENABLE_BGP_VNC
2602 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2603 {
2604 if (vnc_implicit_withdraw)
2605 {
2606 /*
2607 * Add back the route with its new attributes (e.g., nexthop).
2608 * The route is still selected, until the route selection
2609 * queued by bgp_process actually runs. We have to make this
2610 * update to the VNC side immediately to avoid racing against
2611 * configuration changes (e.g., route-map changes) which
2612 * trigger re-importation of the entire RIB.
2613 */
2614 vnc_import_bgp_add_route(bgp, p, ri);
2615 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2616 }
2617 }
2618 #endif
2619
2620 /* Update bgp route dampening information. */
2621 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2622 && peer->sort == BGP_PEER_EBGP)
2623 {
2624 /* Now we do normal update dampening. */
2625 ret = bgp_damp_update (ri, rn, afi, safi);
2626 if (ret == BGP_DAMP_SUPPRESSED)
2627 {
2628 bgp_unlock_node (rn);
2629 return 0;
2630 }
2631 }
2632
2633 /* Nexthop reachability check. */
2634 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2635 {
2636 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2637 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2638 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2639 connected = 1;
2640 else
2641 connected = 0;
2642
2643 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2644 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2645 else
2646 {
2647 if (BGP_DEBUG(nht, NHT))
2648 {
2649 char buf1[INET6_ADDRSTRLEN];
2650 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2651 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2652 }
2653 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2654 }
2655 }
2656 else
2657 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2658
2659 #if ENABLE_BGP_VNC
2660 if (safi == SAFI_MPLS_VPN)
2661 {
2662 struct bgp_node *prn = NULL;
2663 struct bgp_table *table = NULL;
2664
2665 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2666 if (prn->info)
2667 {
2668 table = (struct bgp_table *)(prn->info);
2669
2670 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2671 bgp,
2672 prd,
2673 table,
2674 p,
2675 ri);
2676 }
2677 bgp_unlock_node(prn);
2678 }
2679 #endif
2680
2681 /* Process change. */
2682 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2683
2684 bgp_process (bgp, rn, afi, safi);
2685 bgp_unlock_node (rn);
2686
2687 return 0;
2688 } // End of implicit withdraw
2689
2690 /* Received Logging. */
2691 if (bgp_debug_update(peer, p, NULL, 1))
2692 {
2693 if (!peer->rcvd_attr_printed)
2694 {
2695 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2696 peer->rcvd_attr_printed = 1;
2697 }
2698
2699 bgp_info_addpath_rx_str(addpath_id, buf2);
2700 zlog_debug ("%s rcvd %s/%d%s",
2701 peer->host,
2702 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2703 p->prefixlen, buf2);
2704 }
2705
2706 /* Make new BGP info. */
2707 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2708
2709 /* Update MPLS tag. */
2710 if (safi == SAFI_MPLS_VPN)
2711 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2712
2713 /* Nexthop reachability check. */
2714 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2715 {
2716 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2717 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2718 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2719 connected = 1;
2720 else
2721 connected = 0;
2722
2723 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2724 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2725 else
2726 {
2727 if (BGP_DEBUG(nht, NHT))
2728 {
2729 char buf1[INET6_ADDRSTRLEN];
2730 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2731 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2732 }
2733 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2734 }
2735 }
2736 else
2737 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2738
2739 /* Addpath ID */
2740 new->addpath_rx_id = addpath_id;
2741
2742 /* Increment prefix */
2743 bgp_aggregate_increment (bgp, p, new, afi, safi);
2744
2745 /* Register new BGP information. */
2746 bgp_info_add (rn, new);
2747
2748 /* route_node_get lock */
2749 bgp_unlock_node (rn);
2750
2751 #if ENABLE_BGP_VNC
2752 if (safi == SAFI_MPLS_VPN)
2753 {
2754 struct bgp_node *prn = NULL;
2755 struct bgp_table *table = NULL;
2756
2757 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2758 if (prn->info)
2759 {
2760 table = (struct bgp_table *)(prn->info);
2761
2762 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2763 bgp,
2764 prd,
2765 table,
2766 p,
2767 new);
2768 }
2769 bgp_unlock_node(prn);
2770 }
2771 #endif
2772
2773 /* If maximum prefix count is configured and current prefix
2774 count exeed it. */
2775 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2776 return -1;
2777
2778 /* Process change. */
2779 bgp_process (bgp, rn, afi, safi);
2780
2781 return 0;
2782
2783 /* This BGP update is filtered. Log the reason then update BGP
2784 entry. */
2785 filtered:
2786 if (bgp_debug_update(peer, p, NULL, 1))
2787 {
2788 if (!peer->rcvd_attr_printed)
2789 {
2790 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2791 peer->rcvd_attr_printed = 1;
2792 }
2793
2794 bgp_info_addpath_rx_str(addpath_id, buf2);
2795 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2796 peer->host,
2797 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2798 p->prefixlen, buf2, reason);
2799 }
2800
2801 if (ri)
2802 bgp_rib_remove (rn, ri, peer, afi, safi);
2803
2804 bgp_unlock_node (rn);
2805
2806 return 0;
2807 }
2808
2809 int
2810 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2811 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2812 struct prefix_rd *prd, u_char *tag)
2813 {
2814 struct bgp *bgp;
2815 char buf[SU_ADDRSTRLEN];
2816 char buf2[30];
2817 struct bgp_node *rn;
2818 struct bgp_info *ri;
2819
2820 bgp = peer->bgp;
2821
2822 /* Lookup node. */
2823 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2824
2825 /* If peer is soft reconfiguration enabled. Record input packet for
2826 * further calculation.
2827 *
2828 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2829 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2830 * the iteration over all RS clients.
2831 * Since we need to remove the entry from adj_in anyway, do that first and
2832 * if there was no entry, we don't need to do anything more.
2833 */
2834 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2835 && peer != bgp->peer_self)
2836 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2837 {
2838 if (bgp_debug_update (peer, p, NULL, 1))
2839 zlog_debug ("%s withdrawing route %s/%d "
2840 "not in adj-in", peer->host,
2841 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2842 p->prefixlen);
2843 bgp_unlock_node (rn);
2844 return 0;
2845 }
2846
2847 /* Lookup withdrawn route. */
2848 for (ri = rn->info; ri; ri = ri->next)
2849 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2850 ri->addpath_rx_id == addpath_id)
2851 break;
2852
2853 /* Logging. */
2854 if (bgp_debug_update(peer, p, NULL, 1))
2855 {
2856 bgp_info_addpath_rx_str(addpath_id, buf2);
2857 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2858 peer->host,
2859 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2860 p->prefixlen, buf2);
2861 }
2862
2863 /* Withdraw specified route from routing table. */
2864 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2865 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2866 else if (bgp_debug_update(peer, p, NULL, 1))
2867 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2868 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2869 p->prefixlen);
2870
2871 /* Unlock bgp_node_get() lock. */
2872 bgp_unlock_node (rn);
2873
2874 return 0;
2875 }
2876
2877 void
2878 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2879 {
2880 struct update_subgroup *subgrp;
2881 subgrp = peer_subgroup(peer, afi, safi);
2882 subgroup_default_originate(subgrp, withdraw);
2883 }
2884
2885
2886 /*
2887 * bgp_stop_announce_route_timer
2888 */
2889 void
2890 bgp_stop_announce_route_timer (struct peer_af *paf)
2891 {
2892 if (!paf->t_announce_route)
2893 return;
2894
2895 THREAD_TIMER_OFF (paf->t_announce_route);
2896 }
2897
2898 /*
2899 * bgp_announce_route_timer_expired
2900 *
2901 * Callback that is invoked when the route announcement timer for a
2902 * peer_af expires.
2903 */
2904 static int
2905 bgp_announce_route_timer_expired (struct thread *t)
2906 {
2907 struct peer_af *paf;
2908 struct peer *peer;
2909
2910 paf = THREAD_ARG (t);
2911 peer = paf->peer;
2912
2913 assert (paf->t_announce_route);
2914 paf->t_announce_route = NULL;
2915
2916 if (peer->status != Established)
2917 return 0;
2918
2919 if (!peer->afc_nego[paf->afi][paf->safi])
2920 return 0;
2921
2922 peer_af_announce_route (paf, 1);
2923 return 0;
2924 }
2925
2926 /*
2927 * bgp_announce_route
2928 *
2929 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2930 */
2931 void
2932 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2933 {
2934 struct peer_af *paf;
2935 struct update_subgroup *subgrp;
2936
2937 paf = peer_af_find (peer, afi, safi);
2938 if (!paf)
2939 return;
2940 subgrp = PAF_SUBGRP(paf);
2941
2942 /*
2943 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2944 * or a refresh has already been triggered.
2945 */
2946 if (!subgrp || paf->t_announce_route)
2947 return;
2948
2949 /*
2950 * Start a timer to stagger/delay the announce. This serves
2951 * two purposes - announcement can potentially be combined for
2952 * multiple peers and the announcement doesn't happen in the
2953 * vty context.
2954 */
2955 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2956 bgp_announce_route_timer_expired, paf,
2957 (subgrp->peer_count == 1) ?
2958 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2959 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2960 }
2961
2962 /*
2963 * Announce routes from all AF tables to a peer.
2964 *
2965 * This should ONLY be called when there is a need to refresh the
2966 * routes to the peer based on a policy change for this peer alone
2967 * or a route refresh request received from the peer.
2968 * The operation will result in splitting the peer from its existing
2969 * subgroups and putting it in new subgroups.
2970 */
2971 void
2972 bgp_announce_route_all (struct peer *peer)
2973 {
2974 afi_t afi;
2975 safi_t safi;
2976
2977 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2978 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2979 bgp_announce_route (peer, afi, safi);
2980 }
2981
2982 static void
2983 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2984 struct bgp_table *table, struct prefix_rd *prd)
2985 {
2986 int ret;
2987 struct bgp_node *rn;
2988 struct bgp_adj_in *ain;
2989
2990 if (! table)
2991 table = peer->bgp->rib[afi][safi];
2992
2993 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2994 for (ain = rn->adj_in; ain; ain = ain->next)
2995 {
2996 if (ain->peer == peer)
2997 {
2998 struct bgp_info *ri = rn->info;
2999 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
3000
3001 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
3002 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
3003 prd, tag, 1);
3004
3005 if (ret < 0)
3006 {
3007 bgp_unlock_node (rn);
3008 return;
3009 }
3010 }
3011 }
3012 }
3013
3014 void
3015 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3016 {
3017 struct bgp_node *rn;
3018 struct bgp_table *table;
3019
3020 if (peer->status != Established)
3021 return;
3022
3023 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3024 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3025 else
3026 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3027 rn = bgp_route_next (rn))
3028 if ((table = rn->info) != NULL)
3029 {
3030 struct prefix_rd prd;
3031 prd.family = AF_UNSPEC;
3032 prd.prefixlen = 64;
3033 memcpy(&prd.val, rn->p.u.val, 8);
3034
3035 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3036 }
3037 }
3038
3039
3040 struct bgp_clear_node_queue
3041 {
3042 struct bgp_node *rn;
3043 };
3044
3045 static wq_item_status
3046 bgp_clear_route_node (struct work_queue *wq, void *data)
3047 {
3048 struct bgp_clear_node_queue *cnq = data;
3049 struct bgp_node *rn = cnq->rn;
3050 struct peer *peer = wq->spec.data;
3051 struct bgp_info *ri;
3052 afi_t afi = bgp_node_table (rn)->afi;
3053 safi_t safi = bgp_node_table (rn)->safi;
3054
3055 assert (rn && peer);
3056
3057 /* It is possible that we have multiple paths for a prefix from a peer
3058 * if that peer is using AddPath.
3059 */
3060 for (ri = rn->info; ri; ri = ri->next)
3061 if (ri->peer == peer)
3062 {
3063 /* graceful restart STALE flag set. */
3064 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3065 && peer->nsf[afi][safi]
3066 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3067 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3068 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3069 else
3070 bgp_rib_remove (rn, ri, peer, afi, safi);
3071 }
3072 return WQ_SUCCESS;
3073 }
3074
3075 static void
3076 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3077 {
3078 struct bgp_clear_node_queue *cnq = data;
3079 struct bgp_node *rn = cnq->rn;
3080 struct bgp_table *table = bgp_node_table (rn);
3081
3082 bgp_unlock_node (rn);
3083 bgp_table_unlock (table);
3084 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3085 }
3086
3087 static void
3088 bgp_clear_node_complete (struct work_queue *wq)
3089 {
3090 struct peer *peer = wq->spec.data;
3091
3092 /* Tickle FSM to start moving again */
3093 BGP_EVENT_ADD (peer, Clearing_Completed);
3094
3095 peer_unlock (peer); /* bgp_clear_route */
3096 }
3097
3098 static void
3099 bgp_clear_node_queue_init (struct peer *peer)
3100 {
3101 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3102
3103 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3104 #undef CLEAR_QUEUE_NAME_LEN
3105
3106 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3107 {
3108 zlog_err ("%s: Failed to allocate work queue", __func__);
3109 exit (1);
3110 }
3111 peer->clear_node_queue->spec.hold = 10;
3112 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3113 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3114 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3115 peer->clear_node_queue->spec.max_retries = 0;
3116
3117 /* we only 'lock' this peer reference when the queue is actually active */
3118 peer->clear_node_queue->spec.data = peer;
3119 }
3120
3121 static void
3122 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3123 struct bgp_table *table)
3124 {
3125 struct bgp_node *rn;
3126
3127
3128 if (! table)
3129 table = peer->bgp->rib[afi][safi];
3130
3131 /* If still no table => afi/safi isn't configured at all or smth. */
3132 if (! table)
3133 return;
3134
3135 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3136 {
3137 struct bgp_info *ri;
3138 struct bgp_adj_in *ain;
3139 struct bgp_adj_in *ain_next;
3140
3141 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3142 * queued for every clearing peer, regardless of whether it is
3143 * relevant to the peer at hand.
3144 *
3145 * Overview: There are 3 different indices which need to be
3146 * scrubbed, potentially, when a peer is removed:
3147 *
3148 * 1 peer's routes visible via the RIB (ie accepted routes)
3149 * 2 peer's routes visible by the (optional) peer's adj-in index
3150 * 3 other routes visible by the peer's adj-out index
3151 *
3152 * 3 there is no hurry in scrubbing, once the struct peer is
3153 * removed from bgp->peer, we could just GC such deleted peer's
3154 * adj-outs at our leisure.
3155 *
3156 * 1 and 2 must be 'scrubbed' in some way, at least made
3157 * invisible via RIB index before peer session is allowed to be
3158 * brought back up. So one needs to know when such a 'search' is
3159 * complete.
3160 *
3161 * Ideally:
3162 *
3163 * - there'd be a single global queue or a single RIB walker
3164 * - rather than tracking which route_nodes still need to be
3165 * examined on a peer basis, we'd track which peers still
3166 * aren't cleared
3167 *
3168 * Given that our per-peer prefix-counts now should be reliable,
3169 * this may actually be achievable. It doesn't seem to be a huge
3170 * problem at this time,
3171 *
3172 * It is possible that we have multiple paths for a prefix from a peer
3173 * if that peer is using AddPath.
3174 */
3175 ain = rn->adj_in;
3176 while (ain)
3177 {
3178 ain_next = ain->next;
3179
3180 if (ain->peer == peer)
3181 {
3182 bgp_adj_in_remove (rn, ain);
3183 bgp_unlock_node (rn);
3184 }
3185
3186 ain = ain_next;
3187 }
3188
3189 for (ri = rn->info; ri; ri = ri->next)
3190 if (ri->peer == peer)
3191 {
3192 struct bgp_clear_node_queue *cnq;
3193
3194 /* both unlocked in bgp_clear_node_queue_del */
3195 bgp_table_lock (bgp_node_table (rn));
3196 bgp_lock_node (rn);
3197 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3198 sizeof (struct bgp_clear_node_queue));
3199 cnq->rn = rn;
3200 work_queue_add (peer->clear_node_queue, cnq);
3201 break;
3202 }
3203 }
3204 return;
3205 }
3206
3207 void
3208 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3209 {
3210 struct bgp_node *rn;
3211 struct bgp_table *table;
3212
3213 if (peer->clear_node_queue == NULL)
3214 bgp_clear_node_queue_init (peer);
3215
3216 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3217 * Idle until it receives a Clearing_Completed event. This protects
3218 * against peers which flap faster than we can we clear, which could
3219 * lead to:
3220 *
3221 * a) race with routes from the new session being installed before
3222 * clear_route_node visits the node (to delete the route of that
3223 * peer)
3224 * b) resource exhaustion, clear_route_node likely leads to an entry
3225 * on the process_main queue. Fast-flapping could cause that queue
3226 * to grow and grow.
3227 */
3228
3229 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3230 * the unlock will happen upon work-queue completion; other wise, the
3231 * unlock happens at the end of this function.
3232 */
3233 if (!peer->clear_node_queue->thread)
3234 peer_lock (peer);
3235
3236 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3237 bgp_clear_route_table (peer, afi, safi, NULL);
3238 else
3239 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3240 rn = bgp_route_next (rn))
3241 if ((table = rn->info) != NULL)
3242 bgp_clear_route_table (peer, afi, safi, table);
3243
3244 /* unlock if no nodes got added to the clear-node-queue. */
3245 if (!peer->clear_node_queue->thread)
3246 peer_unlock (peer);
3247
3248 }
3249
3250 void
3251 bgp_clear_route_all (struct peer *peer)
3252 {
3253 afi_t afi;
3254 safi_t safi;
3255
3256 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3257 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3258 bgp_clear_route (peer, afi, safi);
3259
3260 #if ENABLE_BGP_VNC
3261 rfapiProcessPeerDown(peer);
3262 #endif
3263 }
3264
3265 void
3266 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3267 {
3268 struct bgp_table *table;
3269 struct bgp_node *rn;
3270 struct bgp_adj_in *ain;
3271 struct bgp_adj_in *ain_next;
3272
3273 table = peer->bgp->rib[afi][safi];
3274
3275 /* It is possible that we have multiple paths for a prefix from a peer
3276 * if that peer is using AddPath.
3277 */
3278 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3279 {
3280 ain = rn->adj_in;
3281
3282 while (ain)
3283 {
3284 ain_next = ain->next;
3285
3286 if (ain->peer == peer)
3287 {
3288 bgp_adj_in_remove (rn, ain);
3289 bgp_unlock_node (rn);
3290 }
3291
3292 ain = ain_next;
3293 }
3294 }
3295 }
3296
3297 void
3298 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3299 {
3300 struct bgp_node *rn;
3301 struct bgp_info *ri;
3302 struct bgp_table *table;
3303
3304 table = peer->bgp->rib[afi][safi];
3305
3306 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3307 {
3308 for (ri = rn->info; ri; ri = ri->next)
3309 if (ri->peer == peer)
3310 {
3311 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3312 bgp_rib_remove (rn, ri, peer, afi, safi);
3313 break;
3314 }
3315 }
3316 }
3317
3318 static void
3319 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3320 {
3321 struct bgp_node *rn;
3322 struct bgp_info *ri;
3323 struct bgp_info *next;
3324
3325 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3326 for (ri = rn->info; ri; ri = next)
3327 {
3328 next = ri->next;
3329 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3330 && ri->type == ZEBRA_ROUTE_BGP
3331 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3332 ri->sub_type == BGP_ROUTE_AGGREGATE))
3333 {
3334 #if ENABLE_BGP_VNC
3335 if (table->owner && table->owner->bgp)
3336 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3337 #endif
3338 bgp_zebra_withdraw (&rn->p, ri, safi);
3339 }
3340 }
3341 }
3342
3343 /* Delete all kernel routes. */
3344 void
3345 bgp_cleanup_routes (void)
3346 {
3347 struct bgp *bgp;
3348 struct listnode *node, *nnode;
3349 afi_t afi;
3350
3351 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3352 {
3353 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3354 {
3355 struct bgp_node *rn;
3356
3357 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3358
3359 /*
3360 * VPN and ENCAP tables are two-level (RD is top level)
3361 */
3362 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3363 rn = bgp_route_next (rn))
3364 {
3365 if (rn->info)
3366 {
3367 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3368 bgp_table_finish ((struct bgp_table **)&(rn->info));
3369 rn->info = NULL;
3370 bgp_unlock_node(rn);
3371 }
3372 }
3373
3374 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3375 rn = bgp_route_next (rn))
3376 {
3377 if (rn->info)
3378 {
3379 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3380 bgp_table_finish ((struct bgp_table **)&(rn->info));
3381 rn->info = NULL;
3382 bgp_unlock_node(rn);
3383 }
3384 }
3385 }
3386 }
3387 }
3388
3389 void
3390 bgp_reset (void)
3391 {
3392 vty_reset ();
3393 bgp_zclient_reset ();
3394 access_list_reset ();
3395 prefix_list_reset ();
3396 }
3397
3398 static int
3399 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3400 {
3401 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3402 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3403 }
3404
3405 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3406 value. */
3407 int
3408 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3409 {
3410 u_char *pnt;
3411 u_char *lim;
3412 struct prefix p;
3413 int psize;
3414 int ret;
3415 afi_t afi;
3416 safi_t safi;
3417 int addpath_encoded;
3418 u_int32_t addpath_id;
3419
3420 /* Check peer status. */
3421 if (peer->status != Established)
3422 return 0;
3423
3424 pnt = packet->nlri;
3425 lim = pnt + packet->length;
3426 afi = packet->afi;
3427 safi = packet->safi;
3428 addpath_id = 0;
3429 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3430
3431 for (; pnt < lim; pnt += psize)
3432 {
3433 /* Clear prefix structure. */
3434 memset (&p, 0, sizeof (struct prefix));
3435
3436 if (addpath_encoded)
3437 {
3438
3439 /* When packet overflow occurs return immediately. */
3440 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3441 return -1;
3442
3443 addpath_id = ntohl(*((uint32_t*) pnt));
3444 pnt += BGP_ADDPATH_ID_LEN;
3445 }
3446
3447 /* Fetch prefix length. */
3448 p.prefixlen = *pnt++;
3449 p.family = afi2family (afi);
3450
3451 /* Already checked in nlri_sanity_check(). We do double check
3452 here. */
3453 if ((afi == AFI_IP && p.prefixlen > 32)
3454 || (afi == AFI_IP6 && p.prefixlen > 128))
3455 return -1;
3456
3457 /* Packet size overflow check. */
3458 psize = PSIZE (p.prefixlen);
3459
3460 /* When packet overflow occur return immediately. */
3461 if (pnt + psize > lim)
3462 return -1;
3463
3464 /* Fetch prefix from NLRI packet. */
3465 memcpy (&p.u.prefix, pnt, psize);
3466
3467 /* Check address. */
3468 if (afi == AFI_IP && safi == SAFI_UNICAST)
3469 {
3470 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3471 {
3472 /*
3473 * From draft-ietf-idr-bgp4-22, Section 6.3:
3474 * If a BGP router receives an UPDATE message with a
3475 * semantically incorrect NLRI field, in which a prefix is
3476 * semantically incorrect (eg. an unexpected multicast IP
3477 * address), it should ignore the prefix.
3478 */
3479 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3480 inet_ntoa (p.u.prefix4));
3481
3482 return -1;
3483 }
3484 }
3485
3486 #ifdef HAVE_IPV6
3487 /* Check address. */
3488 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3489 {
3490 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3491 {
3492 char buf[BUFSIZ];
3493
3494 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3495 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3496
3497 continue;
3498 }
3499 }
3500 #endif /* HAVE_IPV6 */
3501
3502 /* Normal process. */
3503 if (attr)
3504 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3505 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3506 else
3507 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3508 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3509
3510 /* Address family configuration mismatch or maximum-prefix count
3511 overflow. */
3512 if (ret < 0)
3513 return -1;
3514 }
3515
3516 /* Packet length consistency check. */
3517 if (pnt != lim)
3518 return -1;
3519
3520 return 0;
3521 }
3522
3523 /* NLRI encode syntax check routine. */
3524 int
3525 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3526 bgp_size_t length, int *numpfx)
3527 {
3528 u_char *end;
3529 u_char prefixlen;
3530 int psize;
3531 int addpath_encoded;
3532
3533 *numpfx = 0;
3534 end = pnt + length;
3535 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3536
3537 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3538 syntactic validity. If the field is syntactically incorrect,
3539 then the Error Subcode is set to Invalid Network Field. */
3540
3541 while (pnt < end)
3542 {
3543 int badlength;
3544
3545 /* If the NLRI is encoded using addpath then the first 4 bytes are
3546 * the addpath ID. */
3547 if (addpath_encoded)
3548 {
3549 if (pnt + BGP_ADDPATH_ID_LEN > end)
3550 {
3551 zlog_err ("%s [Error] Update packet error"
3552 " (prefix data addpath overflow)",
3553 peer->host);
3554 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3555 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3556 return -1;
3557 }
3558 pnt += BGP_ADDPATH_ID_LEN;
3559 }
3560
3561 prefixlen = *pnt++;
3562
3563 /* Prefix length check. */
3564 badlength = 0;
3565 if (safi == SAFI_ENCAP) {
3566 if (prefixlen > 128)
3567 badlength = 1;
3568 } else {
3569 if ((afi == AFI_IP && prefixlen > 32) ||
3570 (afi == AFI_IP6 && prefixlen > 128)) {
3571
3572 badlength = 1;
3573 }
3574 }
3575 if (badlength)
3576 {
3577 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3578 peer->host, prefixlen);
3579 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3580 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3581 return -1;
3582 }
3583
3584 /* Packet size overflow check. */
3585 psize = PSIZE (prefixlen);
3586
3587 if (pnt + psize > end)
3588 {
3589 zlog_err ("%s [Error] Update packet error"
3590 " (prefix data overflow prefix size is %d)",
3591 peer->host, psize);
3592 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3593 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3594 return -1;
3595 }
3596
3597 pnt += psize;
3598 (*numpfx)++;
3599 }
3600
3601 /* Packet length consistency check. */
3602 if (pnt != end)
3603 {
3604 zlog_err ("%s [Error] Update packet error"
3605 " (prefix length mismatch with total length)",
3606 peer->host);
3607 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3608 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3609 return -1;
3610 }
3611 return 0;
3612 }
3613
3614 static struct bgp_static *
3615 bgp_static_new (void)
3616 {
3617 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3618 }
3619
3620 static void
3621 bgp_static_free (struct bgp_static *bgp_static)
3622 {
3623 if (bgp_static->rmap.name)
3624 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3625 XFREE (MTYPE_BGP_STATIC, bgp_static);
3626 }
3627
3628 static void
3629 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3630 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3631 {
3632 struct bgp_node *rn;
3633 struct bgp_info *ri;
3634 struct bgp_info *new;
3635 struct bgp_info info;
3636 struct attr attr;
3637 struct attr *attr_new;
3638 int ret;
3639 #if ENABLE_BGP_VNC
3640 int vnc_implicit_withdraw = 0;
3641 #endif
3642
3643 assert (bgp_static);
3644 if (!bgp_static)
3645 return;
3646
3647 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3648
3649 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3650
3651 attr.nexthop = bgp_static->igpnexthop;
3652 attr.med = bgp_static->igpmetric;
3653 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3654
3655 if (bgp_static->atomic)
3656 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3657
3658 /* Apply route-map. */
3659 if (bgp_static->rmap.name)
3660 {
3661 struct attr attr_tmp = attr;
3662 info.peer = bgp->peer_self;
3663 info.attr = &attr_tmp;
3664
3665 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3666
3667 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3668
3669 bgp->peer_self->rmap_type = 0;
3670
3671 if (ret == RMAP_DENYMATCH)
3672 {
3673 /* Free uninterned attribute. */
3674 bgp_attr_flush (&attr_tmp);
3675
3676 /* Unintern original. */
3677 aspath_unintern (&attr.aspath);
3678 bgp_attr_extra_free (&attr);
3679 bgp_static_withdraw (bgp, p, afi, safi);
3680 return;
3681 }
3682 attr_new = bgp_attr_intern (&attr_tmp);
3683 }
3684 else
3685 attr_new = bgp_attr_intern (&attr);
3686
3687 for (ri = rn->info; ri; ri = ri->next)
3688 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3689 && ri->sub_type == BGP_ROUTE_STATIC)
3690 break;
3691
3692 if (ri)
3693 {
3694 if (attrhash_cmp (ri->attr, attr_new) &&
3695 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3696 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3697 {
3698 bgp_unlock_node (rn);
3699 bgp_attr_unintern (&attr_new);
3700 aspath_unintern (&attr.aspath);
3701 bgp_attr_extra_free (&attr);
3702 return;
3703 }
3704 else
3705 {
3706 /* The attribute is changed. */
3707 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3708
3709 /* Rewrite BGP route information. */
3710 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3711 bgp_info_restore(rn, ri);
3712 else
3713 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3714 #if ENABLE_BGP_VNC
3715 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3716 {
3717 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3718 {
3719 /*
3720 * Implicit withdraw case.
3721 * We have to do this before ri is changed
3722 */
3723 ++vnc_implicit_withdraw;
3724 vnc_import_bgp_del_route(bgp, p, ri);
3725 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3726 }
3727 }
3728 #endif
3729 bgp_attr_unintern (&ri->attr);
3730 ri->attr = attr_new;
3731 ri->uptime = bgp_clock ();
3732 #if ENABLE_BGP_VNC
3733 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3734 {
3735 if (vnc_implicit_withdraw)
3736 {
3737 vnc_import_bgp_add_route(bgp, p, ri);
3738 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3739 }
3740 }
3741 #endif
3742
3743 /* Nexthop reachability check. */
3744 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3745 {
3746 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3747 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3748 else
3749 {
3750 if (BGP_DEBUG(nht, NHT))
3751 {
3752 char buf1[INET6_ADDRSTRLEN];
3753 inet_ntop(p->family, &p->u.prefix, buf1,
3754 INET6_ADDRSTRLEN);
3755 zlog_debug("%s(%s): Route not in table, not advertising",
3756 __FUNCTION__, buf1);
3757 }
3758 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3759 }
3760 }
3761 else
3762 {
3763 /* Delete the NHT structure if any, if we're toggling between
3764 * enabling/disabling import check. We deregister the route
3765 * from NHT to avoid overloading NHT and the process interaction
3766 */
3767 bgp_unlink_nexthop(ri);
3768 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3769 }
3770 /* Process change. */
3771 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3772 bgp_process (bgp, rn, afi, safi);
3773 bgp_unlock_node (rn);
3774 aspath_unintern (&attr.aspath);
3775 bgp_attr_extra_free (&attr);
3776 return;
3777 }
3778 }
3779
3780 /* Make new BGP info. */
3781 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3782 rn);
3783 /* Nexthop reachability check. */
3784 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3785 {
3786 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3787 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3788 else
3789 {
3790 if (BGP_DEBUG(nht, NHT))
3791 {
3792 char buf1[INET6_ADDRSTRLEN];
3793 inet_ntop(p->family, &p->u.prefix, buf1,
3794 INET6_ADDRSTRLEN);
3795 zlog_debug("%s(%s): Route not in table, not advertising",
3796 __FUNCTION__, buf1);
3797 }
3798 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3799 }
3800 }
3801 else
3802 {
3803 /* Delete the NHT structure if any, if we're toggling between
3804 * enabling/disabling import check. We deregister the route
3805 * from NHT to avoid overloading NHT and the process interaction
3806 */
3807 bgp_unlink_nexthop(new);
3808
3809 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3810 }
3811
3812 /* Aggregate address increment. */
3813 bgp_aggregate_increment (bgp, p, new, afi, safi);
3814
3815 /* Register new BGP information. */
3816 bgp_info_add (rn, new);
3817
3818 /* route_node_get lock */
3819 bgp_unlock_node (rn);
3820
3821 /* Process change. */
3822 bgp_process (bgp, rn, afi, safi);
3823
3824 /* Unintern original. */
3825 aspath_unintern (&attr.aspath);
3826 bgp_attr_extra_free (&attr);
3827 }
3828
3829 void
3830 bgp_static_update (struct bgp *bgp, struct prefix *p,
3831 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3832 {
3833 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3834 }
3835
3836 void
3837 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3838 safi_t safi)
3839 {
3840 struct bgp_node *rn;
3841 struct bgp_info *ri;
3842
3843 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3844
3845 /* Check selected route and self inserted route. */
3846 for (ri = rn->info; ri; ri = ri->next)
3847 if (ri->peer == bgp->peer_self
3848 && ri->type == ZEBRA_ROUTE_BGP
3849 && ri->sub_type == BGP_ROUTE_STATIC)
3850 break;
3851
3852 /* Withdraw static BGP route from routing table. */
3853 if (ri)
3854 {
3855 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3856 bgp_unlink_nexthop(ri);
3857 bgp_info_delete (rn, ri);
3858 bgp_process (bgp, rn, afi, safi);
3859 }
3860
3861 /* Unlock bgp_node_lookup. */
3862 bgp_unlock_node (rn);
3863 }
3864
3865 /*
3866 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3867 */
3868 static void
3869 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3870 safi_t safi, struct prefix_rd *prd, u_char *tag)
3871 {
3872 struct bgp_node *rn;
3873 struct bgp_info *ri;
3874
3875 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3876
3877 /* Check selected route and self inserted route. */
3878 for (ri = rn->info; ri; ri = ri->next)
3879 if (ri->peer == bgp->peer_self
3880 && ri->type == ZEBRA_ROUTE_BGP
3881 && ri->sub_type == BGP_ROUTE_STATIC)
3882 break;
3883
3884 /* Withdraw static BGP route from routing table. */
3885 if (ri)
3886 {
3887 #if ENABLE_BGP_VNC
3888 rfapiProcessWithdraw(
3889 ri->peer,
3890 NULL,
3891 p,
3892 prd,
3893 ri->attr,
3894 afi,
3895 safi,
3896 ri->type,
3897 1); /* Kill, since it is an administrative change */
3898 #endif
3899 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3900 bgp_info_delete (rn, ri);
3901 bgp_process (bgp, rn, afi, safi);
3902 }
3903
3904 /* Unlock bgp_node_lookup. */
3905 bgp_unlock_node (rn);
3906 }
3907
3908 static void
3909 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3910 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3911 {
3912 struct bgp_node *rn;
3913 struct bgp_info *new;
3914 struct attr *attr_new;
3915 struct attr attr = { 0 };
3916 struct bgp_info *ri;
3917 #if ENABLE_BGP_VNC
3918 u_int32_t label = 0;
3919 #endif
3920
3921 assert (bgp_static);
3922
3923 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3924
3925 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3926
3927 attr.nexthop = bgp_static->igpnexthop;
3928 attr.med = bgp_static->igpmetric;
3929 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3930
3931 /* Apply route-map. */
3932 if (bgp_static->rmap.name)
3933 {
3934 struct attr attr_tmp = attr;
3935 struct bgp_info info;
3936 int ret;
3937
3938 info.peer = bgp->peer_self;
3939 info.attr = &attr_tmp;
3940
3941 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3942
3943 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3944
3945 bgp->peer_self->rmap_type = 0;
3946
3947 if (ret == RMAP_DENYMATCH)
3948 {
3949 /* Free uninterned attribute. */
3950 bgp_attr_flush (&attr_tmp);
3951
3952 /* Unintern original. */
3953 aspath_unintern (&attr.aspath);
3954 bgp_attr_extra_free (&attr);
3955 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3956 bgp_static->tag);
3957 return;
3958 }
3959
3960 attr_new = bgp_attr_intern (&attr_tmp);
3961 }
3962 else
3963 {
3964 attr_new = bgp_attr_intern (&attr);
3965 }
3966
3967 for (ri = rn->info; ri; ri = ri->next)
3968 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3969 && ri->sub_type == BGP_ROUTE_STATIC)
3970 break;
3971
3972 if (ri)
3973 {
3974 if (attrhash_cmp (ri->attr, attr_new) &&
3975 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3976 {
3977 bgp_unlock_node (rn);
3978 bgp_attr_unintern (&attr_new);
3979 aspath_unintern (&attr.aspath);
3980 bgp_attr_extra_free (&attr);
3981 return;
3982 }
3983 else
3984 {
3985 /* The attribute is changed. */
3986 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3987
3988 /* Rewrite BGP route information. */
3989 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3990 bgp_info_restore(rn, ri);
3991 else
3992 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3993 bgp_attr_unintern (&ri->attr);
3994 ri->attr = attr_new;
3995 ri->uptime = bgp_clock ();
3996 #if ENABLE_BGP_VNC
3997 if (ri->extra)
3998 label = decode_label (ri->extra->tag);
3999 #endif
4000
4001 /* Process change. */
4002 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4003 bgp_process (bgp, rn, afi, safi);
4004 #if ENABLE_BGP_VNC
4005 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
4006 ri->attr, afi, safi,
4007 ri->type, ri->sub_type, &label);
4008 #endif
4009 bgp_unlock_node (rn);
4010 aspath_unintern (&attr.aspath);
4011 bgp_attr_extra_free (&attr);
4012 return;
4013 }
4014 }
4015
4016
4017 /* Make new BGP info. */
4018 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4019 rn);
4020 SET_FLAG (new->flags, BGP_INFO_VALID);
4021 new->extra = bgp_info_extra_new();
4022 memcpy (new->extra->tag, bgp_static->tag, 3);
4023 #if ENABLE_BGP_VNC
4024 label = decode_label (bgp_static->tag);
4025 #endif
4026
4027 /* Aggregate address increment. */
4028 bgp_aggregate_increment (bgp, p, new, afi, safi);
4029
4030 /* Register new BGP information. */
4031 bgp_info_add (rn, new);
4032
4033 /* route_node_get lock */
4034 bgp_unlock_node (rn);
4035
4036 /* Process change. */
4037 bgp_process (bgp, rn, afi, safi);
4038
4039 #if ENABLE_BGP_VNC
4040 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4041 new->attr, afi, safi,
4042 new->type, new->sub_type, &label);
4043 #endif
4044
4045 /* Unintern original. */
4046 aspath_unintern (&attr.aspath);
4047 bgp_attr_extra_free (&attr);
4048 }
4049
4050 /* Configure static BGP network. When user don't run zebra, static
4051 route should be installed as valid. */
4052 static int
4053 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4054 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4055 {
4056 int ret;
4057 struct prefix p;
4058 struct bgp_static *bgp_static;
4059 struct bgp_node *rn;
4060 u_char need_update = 0;
4061
4062 /* Convert IP prefix string to struct prefix. */
4063 ret = str2prefix (ip_str, &p);
4064 if (! ret)
4065 {
4066 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4067 return CMD_WARNING;
4068 }
4069 #ifdef HAVE_IPV6
4070 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4071 {
4072 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4073 VTY_NEWLINE);
4074 return CMD_WARNING;
4075 }
4076 #endif /* HAVE_IPV6 */
4077
4078 apply_mask (&p);
4079
4080 /* Set BGP static route configuration. */
4081 rn = bgp_node_get (bgp->route[afi][safi], &p);
4082
4083 if (rn->info)
4084 {
4085 /* Configuration change. */
4086 bgp_static = rn->info;
4087
4088 /* Check previous routes are installed into BGP. */
4089 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4090 need_update = 1;
4091
4092 bgp_static->backdoor = backdoor;
4093
4094 if (rmap)
4095 {
4096 if (bgp_static->rmap.name)
4097 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4098 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4099 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4100 }
4101 else
4102 {
4103 if (bgp_static->rmap.name)
4104 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4105 bgp_static->rmap.name = NULL;
4106 bgp_static->rmap.map = NULL;
4107 bgp_static->valid = 0;
4108 }
4109 bgp_unlock_node (rn);
4110 }
4111 else
4112 {
4113 /* New configuration. */
4114 bgp_static = bgp_static_new ();
4115 bgp_static->backdoor = backdoor;
4116 bgp_static->valid = 0;
4117 bgp_static->igpmetric = 0;
4118 bgp_static->igpnexthop.s_addr = 0;
4119
4120 if (rmap)
4121 {
4122 if (bgp_static->rmap.name)
4123 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4124 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4125 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4126 }
4127 rn->info = bgp_static;
4128 }
4129
4130 bgp_static->valid = 1;
4131 if (need_update)
4132 bgp_static_withdraw (bgp, &p, afi, safi);
4133
4134 if (! bgp_static->backdoor)
4135 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4136
4137 return CMD_SUCCESS;
4138 }
4139
4140 /* Configure static BGP network. */
4141 static int
4142 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4143 afi_t afi, safi_t safi)
4144 {
4145 int ret;
4146 struct prefix p;
4147 struct bgp_static *bgp_static;
4148 struct bgp_node *rn;
4149
4150 /* Convert IP prefix string to struct prefix. */
4151 ret = str2prefix (ip_str, &p);
4152 if (! ret)
4153 {
4154 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157 #ifdef HAVE_IPV6
4158 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4159 {
4160 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4161 VTY_NEWLINE);
4162 return CMD_WARNING;
4163 }
4164 #endif /* HAVE_IPV6 */
4165
4166 apply_mask (&p);
4167
4168 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4169 if (! rn)
4170 {
4171 vty_out (vty, "%% Can't find specified static route configuration.%s",
4172 VTY_NEWLINE);
4173 return CMD_WARNING;
4174 }
4175
4176 bgp_static = rn->info;
4177
4178 /* Update BGP RIB. */
4179 if (! bgp_static->backdoor)
4180 bgp_static_withdraw (bgp, &p, afi, safi);
4181
4182 /* Clear configuration. */
4183 bgp_static_free (bgp_static);
4184 rn->info = NULL;
4185 bgp_unlock_node (rn);
4186 bgp_unlock_node (rn);
4187
4188 return CMD_SUCCESS;
4189 }
4190
4191 void
4192 bgp_static_add (struct bgp *bgp)
4193 {
4194 afi_t afi;
4195 safi_t safi;
4196 struct bgp_node *rn;
4197 struct bgp_node *rm;
4198 struct bgp_table *table;
4199 struct bgp_static *bgp_static;
4200
4201 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4202 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4203 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4204 if (rn->info != NULL)
4205 {
4206 if (safi == SAFI_MPLS_VPN)
4207 {
4208 table = rn->info;
4209
4210 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4211 {
4212 bgp_static = rn->info;
4213 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4214 }
4215 }
4216 else
4217 {
4218 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4219 }
4220 }
4221 }
4222
4223 /* Called from bgp_delete(). Delete all static routes from the BGP
4224 instance. */
4225 void
4226 bgp_static_delete (struct bgp *bgp)
4227 {
4228 afi_t afi;
4229 safi_t safi;
4230 struct bgp_node *rn;
4231 struct bgp_node *rm;
4232 struct bgp_table *table;
4233 struct bgp_static *bgp_static;
4234
4235 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4236 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4237 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4238 if (rn->info != NULL)
4239 {
4240 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4241 {
4242 table = rn->info;
4243
4244 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4245 {
4246 bgp_static = rn->info;
4247 bgp_static_withdraw_safi (bgp, &rm->p,
4248 AFI_IP, safi,
4249 (struct prefix_rd *)&rn->p,
4250 bgp_static->tag);
4251 bgp_static_free (bgp_static);
4252 rn->info = NULL;
4253 bgp_unlock_node (rn);
4254 }
4255 }
4256 else
4257 {
4258 bgp_static = rn->info;
4259 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4260 bgp_static_free (bgp_static);
4261 rn->info = NULL;
4262 bgp_unlock_node (rn);
4263 }
4264 }
4265 }
4266
4267 void
4268 bgp_static_redo_import_check (struct bgp *bgp)
4269 {
4270 afi_t afi;
4271 safi_t safi;
4272 struct bgp_node *rn;
4273 struct bgp_static *bgp_static;
4274
4275 /* Use this flag to force reprocessing of the route */
4276 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4277 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4278 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4279 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4280 if (rn->info != NULL)
4281 {
4282 bgp_static = rn->info;
4283 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4284 }
4285 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4286 }
4287
4288 static void
4289 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4290 {
4291 struct bgp_table *table;
4292 struct bgp_node *rn;
4293 struct bgp_info *ri;
4294
4295 table = bgp->rib[afi][safi];
4296 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4297 {
4298 for (ri = rn->info; ri; ri = ri->next)
4299 {
4300 if (ri->peer == bgp->peer_self &&
4301 ((ri->type == ZEBRA_ROUTE_BGP &&
4302 ri->sub_type == BGP_ROUTE_STATIC) ||
4303 (ri->type != ZEBRA_ROUTE_BGP &&
4304 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4305 {
4306 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4307 bgp_unlink_nexthop(ri);
4308 bgp_info_delete (rn, ri);
4309 bgp_process (bgp, rn, afi, safi);
4310 }
4311 }
4312 }
4313 }
4314
4315 /*
4316 * Purge all networks and redistributed routes from routing table.
4317 * Invoked upon the instance going down.
4318 */
4319 void
4320 bgp_purge_static_redist_routes (struct bgp *bgp)
4321 {
4322 afi_t afi;
4323 safi_t safi;
4324
4325 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4326 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4327 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4328 }
4329
4330 /*
4331 * gpz 110624
4332 * Currently this is used to set static routes for VPN and ENCAP.
4333 * I think it can probably be factored with bgp_static_set.
4334 */
4335 int
4336 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4337 const char *rd_str, const char *tag_str,
4338 const char *rmap_str)
4339 {
4340 int ret;
4341 struct prefix p;
4342 struct prefix_rd prd;
4343 struct bgp *bgp;
4344 struct bgp_node *prn;
4345 struct bgp_node *rn;
4346 struct bgp_table *table;
4347 struct bgp_static *bgp_static;
4348 u_char tag[3];
4349
4350 bgp = vty->index;
4351
4352 ret = str2prefix (ip_str, &p);
4353 if (! ret)
4354 {
4355 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4356 return CMD_WARNING;
4357 }
4358 apply_mask (&p);
4359
4360 ret = str2prefix_rd (rd_str, &prd);
4361 if (! ret)
4362 {
4363 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4364 return CMD_WARNING;
4365 }
4366
4367 ret = str2tag (tag_str, tag);
4368 if (! ret)
4369 {
4370 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4371 return CMD_WARNING;
4372 }
4373
4374 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4375 (struct prefix *)&prd);
4376 if (prn->info == NULL)
4377 prn->info = bgp_table_init (AFI_IP, safi);
4378 else
4379 bgp_unlock_node (prn);
4380 table = prn->info;
4381
4382 rn = bgp_node_get (table, &p);
4383
4384 if (rn->info)
4385 {
4386 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4387 bgp_unlock_node (rn);
4388 }
4389 else
4390 {
4391 /* New configuration. */
4392 bgp_static = bgp_static_new ();
4393 bgp_static->backdoor = 0;
4394 bgp_static->valid = 0;
4395 bgp_static->igpmetric = 0;
4396 bgp_static->igpnexthop.s_addr = 0;
4397 memcpy(bgp_static->tag, tag, 3);
4398 bgp_static->prd = prd;
4399
4400 if (rmap_str)
4401 {
4402 if (bgp_static->rmap.name)
4403 free (bgp_static->rmap.name);
4404 bgp_static->rmap.name = strdup (rmap_str);
4405 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4406 }
4407 rn->info = bgp_static;
4408
4409 bgp_static->valid = 1;
4410 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4411 }
4412
4413 return CMD_SUCCESS;
4414 }
4415
4416 /* Configure static BGP network. */
4417 int
4418 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4419 const char *rd_str, const char *tag_str)
4420 {
4421 int ret;
4422 struct bgp *bgp;
4423 struct prefix p;
4424 struct prefix_rd prd;
4425 struct bgp_node *prn;
4426 struct bgp_node *rn;
4427 struct bgp_table *table;
4428 struct bgp_static *bgp_static;
4429 u_char tag[3];
4430
4431 bgp = vty->index;
4432
4433 /* Convert IP prefix string to struct prefix. */
4434 ret = str2prefix (ip_str, &p);
4435 if (! ret)
4436 {
4437 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4438 return CMD_WARNING;
4439 }
4440 apply_mask (&p);
4441
4442 ret = str2prefix_rd (rd_str, &prd);
4443 if (! ret)
4444 {
4445 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4446 return CMD_WARNING;
4447 }
4448
4449 ret = str2tag (tag_str, tag);
4450 if (! ret)
4451 {
4452 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4453 return CMD_WARNING;
4454 }
4455
4456 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4457 (struct prefix *)&prd);
4458 if (prn->info == NULL)
4459 prn->info = bgp_table_init (AFI_IP, safi);
4460 else
4461 bgp_unlock_node (prn);
4462 table = prn->info;
4463
4464 rn = bgp_node_lookup (table, &p);
4465
4466 if (rn)
4467 {
4468 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4469
4470 bgp_static = rn->info;
4471 bgp_static_free (bgp_static);
4472 rn->info = NULL;
4473 bgp_unlock_node (rn);
4474 bgp_unlock_node (rn);
4475 }
4476 else
4477 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4478
4479 return CMD_SUCCESS;
4480 }
4481
4482 static int
4483 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4484 const char *rmap_name)
4485 {
4486 struct bgp_rmap *rmap;
4487
4488 rmap = &bgp->table_map[afi][safi];
4489 if (rmap_name)
4490 {
4491 if (rmap->name)
4492 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4493 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4494 rmap->map = route_map_lookup_by_name (rmap_name);
4495 }
4496 else
4497 {
4498 if (rmap->name)
4499 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4500 rmap->name = NULL;
4501 rmap->map = NULL;
4502 }
4503
4504 bgp_zebra_announce_table(bgp, afi, safi);
4505
4506 return CMD_SUCCESS;
4507 }
4508
4509 static int
4510 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4511 const char *rmap_name)
4512 {
4513 struct bgp_rmap *rmap;
4514
4515 rmap = &bgp->table_map[afi][safi];
4516 if (rmap->name)
4517 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4518 rmap->name = NULL;
4519 rmap->map = NULL;
4520
4521 bgp_zebra_announce_table(bgp, afi, safi);
4522
4523 return CMD_SUCCESS;
4524 }
4525
4526 int
4527 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4528 safi_t safi, int *write)
4529 {
4530 if (bgp->table_map[afi][safi].name)
4531 {
4532 bgp_config_write_family_header (vty, afi, safi, write);
4533 vty_out (vty, " table-map %s%s",
4534 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4535 }
4536
4537 return 0;
4538 }
4539
4540
4541 DEFUN (bgp_table_map,
4542 bgp_table_map_cmd,
4543 "table-map WORD",
4544 "BGP table to RIB route download filter\n"
4545 "Name of the route map\n")
4546 {
4547 return bgp_table_map_set (vty, vty->index,
4548 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4549 }
4550 DEFUN (no_bgp_table_map,
4551 no_bgp_table_map_cmd,
4552 "no table-map WORD",
4553 "BGP table to RIB route download filter\n"
4554 "Name of the route map\n")
4555 {
4556 return bgp_table_map_unset (vty, vty->index,
4557 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4558 }
4559
4560 DEFUN (bgp_network,
4561 bgp_network_cmd,
4562 "network A.B.C.D/M",
4563 "Specify a network to announce via BGP\n"
4564 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4565 {
4566 return bgp_static_set (vty, vty->index, argv[0],
4567 AFI_IP, bgp_node_safi (vty), NULL, 0);
4568 }
4569
4570 DEFUN (bgp_network_route_map,
4571 bgp_network_route_map_cmd,
4572 "network A.B.C.D/M route-map WORD",
4573 "Specify a network to announce via BGP\n"
4574 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4575 "Route-map to modify the attributes\n"
4576 "Name of the route map\n")
4577 {
4578 return bgp_static_set (vty, vty->index, argv[0],
4579 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4580 }
4581
4582 DEFUN (bgp_network_backdoor,
4583 bgp_network_backdoor_cmd,
4584 "network A.B.C.D/M backdoor",
4585 "Specify a network to announce via BGP\n"
4586 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4587 "Specify a BGP backdoor route\n")
4588 {
4589 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4590 NULL, 1);
4591 }
4592
4593 DEFUN (bgp_network_mask,
4594 bgp_network_mask_cmd,
4595 "network A.B.C.D mask A.B.C.D",
4596 "Specify a network to announce via BGP\n"
4597 "Network number\n"
4598 "Network mask\n"
4599 "Network mask\n")
4600 {
4601 int ret;
4602 char prefix_str[BUFSIZ];
4603
4604 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4605 if (! ret)
4606 {
4607 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4608 return CMD_WARNING;
4609 }
4610
4611 return bgp_static_set (vty, vty->index, prefix_str,
4612 AFI_IP, bgp_node_safi (vty), NULL, 0);
4613 }
4614
4615 DEFUN (bgp_network_mask_route_map,
4616 bgp_network_mask_route_map_cmd,
4617 "network A.B.C.D mask A.B.C.D route-map WORD",
4618 "Specify a network to announce via BGP\n"
4619 "Network number\n"
4620 "Network mask\n"
4621 "Network mask\n"
4622 "Route-map to modify the attributes\n"
4623 "Name of the route map\n")
4624 {
4625 int ret;
4626 char prefix_str[BUFSIZ];
4627
4628 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4629 if (! ret)
4630 {
4631 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4632 return CMD_WARNING;
4633 }
4634
4635 return bgp_static_set (vty, vty->index, prefix_str,
4636 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4637 }
4638
4639 DEFUN (bgp_network_mask_backdoor,
4640 bgp_network_mask_backdoor_cmd,
4641 "network A.B.C.D mask A.B.C.D backdoor",
4642 "Specify a network to announce via BGP\n"
4643 "Network number\n"
4644 "Network mask\n"
4645 "Network mask\n"
4646 "Specify a BGP backdoor route\n")
4647 {
4648 int ret;
4649 char prefix_str[BUFSIZ];
4650
4651 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4652 if (! ret)
4653 {
4654 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4655 return CMD_WARNING;
4656 }
4657
4658 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4659 NULL, 1);
4660 }
4661
4662 DEFUN (bgp_network_mask_natural,
4663 bgp_network_mask_natural_cmd,
4664 "network A.B.C.D",
4665 "Specify a network to announce via BGP\n"
4666 "Network number\n")
4667 {
4668 int ret;
4669 char prefix_str[BUFSIZ];
4670
4671 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4672 if (! ret)
4673 {
4674 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4675 return CMD_WARNING;
4676 }
4677
4678 return bgp_static_set (vty, vty->index, prefix_str,
4679 AFI_IP, bgp_node_safi (vty), NULL, 0);
4680 }
4681
4682 DEFUN (bgp_network_mask_natural_route_map,
4683 bgp_network_mask_natural_route_map_cmd,
4684 "network A.B.C.D route-map WORD",
4685 "Specify a network to announce via BGP\n"
4686 "Network number\n"
4687 "Route-map to modify the attributes\n"
4688 "Name of the route map\n")
4689 {
4690 int ret;
4691 char prefix_str[BUFSIZ];
4692
4693 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4694 if (! ret)
4695 {
4696 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4697 return CMD_WARNING;
4698 }
4699
4700 return bgp_static_set (vty, vty->index, prefix_str,
4701 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4702 }
4703
4704 DEFUN (bgp_network_mask_natural_backdoor,
4705 bgp_network_mask_natural_backdoor_cmd,
4706 "network A.B.C.D backdoor",
4707 "Specify a network to announce via BGP\n"
4708 "Network number\n"
4709 "Specify a BGP backdoor route\n")
4710 {
4711 int ret;
4712 char prefix_str[BUFSIZ];
4713
4714 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4715 if (! ret)
4716 {
4717 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4718 return CMD_WARNING;
4719 }
4720
4721 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4722 NULL, 1);
4723 }
4724
4725 DEFUN (no_bgp_network,
4726 no_bgp_network_cmd,
4727 "no network A.B.C.D/M",
4728 NO_STR
4729 "Specify a network to announce via BGP\n"
4730 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4731 {
4732 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4733 bgp_node_safi (vty));
4734 }
4735
4736 ALIAS (no_bgp_network,
4737 no_bgp_network_route_map_cmd,
4738 "no network A.B.C.D/M route-map WORD",
4739 NO_STR
4740 "Specify a network to announce via BGP\n"
4741 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4742 "Route-map to modify the attributes\n"
4743 "Name of the route map\n")
4744
4745 ALIAS (no_bgp_network,
4746 no_bgp_network_backdoor_cmd,
4747 "no network A.B.C.D/M backdoor",
4748 NO_STR
4749 "Specify a network to announce via BGP\n"
4750 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4751 "Specify a BGP backdoor route\n")
4752
4753 DEFUN (no_bgp_network_mask,
4754 no_bgp_network_mask_cmd,
4755 "no network A.B.C.D mask A.B.C.D",
4756 NO_STR
4757 "Specify a network to announce via BGP\n"
4758 "Network number\n"
4759 "Network mask\n"
4760 "Network mask\n")
4761 {
4762 int ret;
4763 char prefix_str[BUFSIZ];
4764
4765 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4766 if (! ret)
4767 {
4768 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4769 return CMD_WARNING;
4770 }
4771
4772 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4773 bgp_node_safi (vty));
4774 }
4775
4776 ALIAS (no_bgp_network_mask,
4777 no_bgp_network_mask_route_map_cmd,
4778 "no network A.B.C.D mask A.B.C.D route-map WORD",
4779 NO_STR
4780 "Specify a network to announce via BGP\n"
4781 "Network number\n"
4782 "Network mask\n"
4783 "Network mask\n"
4784 "Route-map to modify the attributes\n"
4785 "Name of the route map\n")
4786
4787 ALIAS (no_bgp_network_mask,
4788 no_bgp_network_mask_backdoor_cmd,
4789 "no network A.B.C.D mask A.B.C.D backdoor",
4790 NO_STR
4791 "Specify a network to announce via BGP\n"
4792 "Network number\n"
4793 "Network mask\n"
4794 "Network mask\n"
4795 "Specify a BGP backdoor route\n")
4796
4797 DEFUN (no_bgp_network_mask_natural,
4798 no_bgp_network_mask_natural_cmd,
4799 "no network A.B.C.D",
4800 NO_STR
4801 "Specify a network to announce via BGP\n"
4802 "Network number\n")
4803 {
4804 int ret;
4805 char prefix_str[BUFSIZ];
4806
4807 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4808 if (! ret)
4809 {
4810 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4811 return CMD_WARNING;
4812 }
4813
4814 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4815 bgp_node_safi (vty));
4816 }
4817
4818 ALIAS (no_bgp_network_mask_natural,
4819 no_bgp_network_mask_natural_route_map_cmd,
4820 "no network A.B.C.D route-map WORD",
4821 NO_STR
4822 "Specify a network to announce via BGP\n"
4823 "Network number\n"
4824 "Route-map to modify the attributes\n"
4825 "Name of the route map\n")
4826
4827 ALIAS (no_bgp_network_mask_natural,
4828 no_bgp_network_mask_natural_backdoor_cmd,
4829 "no network A.B.C.D backdoor",
4830 NO_STR
4831 "Specify a network to announce via BGP\n"
4832 "Network number\n"
4833 "Specify a BGP backdoor route\n")
4834
4835 #ifdef HAVE_IPV6
4836 DEFUN (ipv6_bgp_network,
4837 ipv6_bgp_network_cmd,
4838 "network X:X::X:X/M",
4839 "Specify a network to announce via BGP\n"
4840 "IPv6 prefix <network>/<length>\n")
4841 {
4842 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4843 NULL, 0);
4844 }
4845
4846 DEFUN (ipv6_bgp_network_route_map,
4847 ipv6_bgp_network_route_map_cmd,
4848 "network X:X::X:X/M route-map WORD",
4849 "Specify a network to announce via BGP\n"
4850 "IPv6 prefix <network>/<length>\n"
4851 "Route-map to modify the attributes\n"
4852 "Name of the route map\n")
4853 {
4854 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4855 bgp_node_safi (vty), argv[1], 0);
4856 }
4857
4858 DEFUN (no_ipv6_bgp_network,
4859 no_ipv6_bgp_network_cmd,
4860 "no network X:X::X:X/M",
4861 NO_STR
4862 "Specify a network to announce via BGP\n"
4863 "IPv6 prefix <network>/<length>\n")
4864 {
4865 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4866 }
4867
4868 ALIAS (no_ipv6_bgp_network,
4869 no_ipv6_bgp_network_route_map_cmd,
4870 "no network X:X::X:X/M route-map WORD",
4871 NO_STR
4872 "Specify a network to announce via BGP\n"
4873 "IPv6 prefix <network>/<length>\n"
4874 "Route-map to modify the attributes\n"
4875 "Name of the route map\n")
4876
4877 ALIAS (ipv6_bgp_network,
4878 old_ipv6_bgp_network_cmd,
4879 "ipv6 bgp network X:X::X:X/M",
4880 IPV6_STR
4881 BGP_STR
4882 "Specify a network to announce via BGP\n"
4883 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4884
4885 ALIAS (no_ipv6_bgp_network,
4886 old_no_ipv6_bgp_network_cmd,
4887 "no ipv6 bgp network X:X::X:X/M",
4888 NO_STR
4889 IPV6_STR
4890 BGP_STR
4891 "Specify a network to announce via BGP\n"
4892 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4893 #endif /* HAVE_IPV6 */
4894
4895 /* Aggreagete address:
4896
4897 advertise-map Set condition to advertise attribute
4898 as-set Generate AS set path information
4899 attribute-map Set attributes of aggregate
4900 route-map Set parameters of aggregate
4901 summary-only Filter more specific routes from updates
4902 suppress-map Conditionally filter more specific routes from updates
4903 <cr>
4904 */
4905 struct bgp_aggregate
4906 {
4907 /* Summary-only flag. */
4908 u_char summary_only;
4909
4910 /* AS set generation. */
4911 u_char as_set;
4912
4913 /* Route-map for aggregated route. */
4914 struct route_map *map;
4915
4916 /* Suppress-count. */
4917 unsigned long count;
4918
4919 /* SAFI configuration. */
4920 safi_t safi;
4921 };
4922
4923 static struct bgp_aggregate *
4924 bgp_aggregate_new (void)
4925 {
4926 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4927 }
4928
4929 static void
4930 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4931 {
4932 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4933 }
4934
4935 /* Update an aggregate as routes are added/removed from the BGP table */
4936 static void
4937 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4938 afi_t afi, safi_t safi, struct bgp_info *del,
4939 struct bgp_aggregate *aggregate)
4940 {
4941 struct bgp_table *table;
4942 struct bgp_node *top;
4943 struct bgp_node *rn;
4944 u_char origin;
4945 struct aspath *aspath = NULL;
4946 struct aspath *asmerge = NULL;
4947 struct community *community = NULL;
4948 struct community *commerge = NULL;
4949 #if defined(AGGREGATE_NEXTHOP_CHECK)
4950 struct in_addr nexthop;
4951 u_int32_t med = 0;
4952 #endif
4953 struct bgp_info *ri;
4954 struct bgp_info *new;
4955 int first = 1;
4956 unsigned long match = 0;
4957 u_char atomic_aggregate = 0;
4958
4959 /* Record adding route's nexthop and med. */
4960 if (rinew)
4961 {
4962 #if defined(AGGREGATE_NEXTHOP_CHECK)
4963 nexthop = rinew->attr->nexthop;
4964 med = rinew->attr->med;
4965 #endif
4966 }
4967
4968 /* ORIGIN attribute: If at least one route among routes that are
4969 aggregated has ORIGIN with the value INCOMPLETE, then the
4970 aggregated route must have the ORIGIN attribute with the value
4971 INCOMPLETE. Otherwise, if at least one route among routes that
4972 are aggregated has ORIGIN with the value EGP, then the aggregated
4973 route must have the origin attribute with the value EGP. In all
4974 other case the value of the ORIGIN attribute of the aggregated
4975 route is INTERNAL. */
4976 origin = BGP_ORIGIN_IGP;
4977
4978 table = bgp->rib[afi][safi];
4979
4980 top = bgp_node_get (table, p);
4981 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4982 if (rn->p.prefixlen > p->prefixlen)
4983 {
4984 match = 0;
4985
4986 for (ri = rn->info; ri; ri = ri->next)
4987 {
4988 if (BGP_INFO_HOLDDOWN (ri))
4989 continue;
4990
4991 if (del && ri == del)
4992 continue;
4993
4994 if (! rinew && first)
4995 {
4996 #if defined(AGGREGATE_NEXTHOP_CHECK)
4997 nexthop = ri->attr->nexthop;
4998 med = ri->attr->med;
4999 #endif
5000 first = 0;
5001 }
5002
5003 #ifdef AGGREGATE_NEXTHOP_CHECK
5004 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5005 || ri->attr->med != med)
5006 {
5007 if (aspath)
5008 aspath_free (aspath);
5009 if (community)
5010 community_free (community);
5011 bgp_unlock_node (rn);
5012 bgp_unlock_node (top);
5013 return;
5014 }
5015 #endif /* AGGREGATE_NEXTHOP_CHECK */
5016
5017 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5018 atomic_aggregate = 1;
5019
5020 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5021 {
5022 if (aggregate->summary_only)
5023 {
5024 (bgp_info_extra_get (ri))->suppress++;
5025 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5026 match++;
5027 }
5028
5029 aggregate->count++;
5030
5031 if (origin < ri->attr->origin)
5032 origin = ri->attr->origin;
5033
5034 if (aggregate->as_set)
5035 {
5036 if (aspath)
5037 {
5038 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5039 aspath_free (aspath);
5040 aspath = asmerge;
5041 }
5042 else
5043 aspath = aspath_dup (ri->attr->aspath);
5044
5045 if (ri->attr->community)
5046 {
5047 if (community)
5048 {
5049 commerge = community_merge (community,
5050 ri->attr->community);
5051 community = community_uniq_sort (commerge);
5052 community_free (commerge);
5053 }
5054 else
5055 community = community_dup (ri->attr->community);
5056 }
5057 }
5058 }
5059 }
5060 if (match)
5061 bgp_process (bgp, rn, afi, safi);
5062 }
5063 bgp_unlock_node (top);
5064
5065 if (rinew)
5066 {
5067 aggregate->count++;
5068
5069 if (aggregate->summary_only)
5070 (bgp_info_extra_get (rinew))->suppress++;
5071
5072 if (origin < rinew->attr->origin)
5073 origin = rinew->attr->origin;
5074
5075 if (aggregate->as_set)
5076 {
5077 if (aspath)
5078 {
5079 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5080 aspath_free (aspath);
5081 aspath = asmerge;
5082 }
5083 else
5084 aspath = aspath_dup (rinew->attr->aspath);
5085
5086 if (rinew->attr->community)
5087 {
5088 if (community)
5089 {
5090 commerge = community_merge (community,
5091 rinew->attr->community);
5092 community = community_uniq_sort (commerge);
5093 community_free (commerge);
5094 }
5095 else
5096 community = community_dup (rinew->attr->community);
5097 }
5098 }
5099 }
5100
5101 if (aggregate->count > 0)
5102 {
5103 rn = bgp_node_get (table, p);
5104 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5105 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5106 aggregate->as_set,
5107 atomic_aggregate), rn);
5108 SET_FLAG (new->flags, BGP_INFO_VALID);
5109
5110 bgp_info_add (rn, new);
5111 bgp_unlock_node (rn);
5112 bgp_process (bgp, rn, afi, safi);
5113 }
5114 else
5115 {
5116 if (aspath)
5117 aspath_free (aspath);
5118 if (community)
5119 community_free (community);
5120 }
5121 }
5122
5123 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5124 struct bgp_aggregate *);
5125
5126 void
5127 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5128 struct bgp_info *ri, afi_t afi, safi_t safi)
5129 {
5130 struct bgp_node *child;
5131 struct bgp_node *rn;
5132 struct bgp_aggregate *aggregate;
5133 struct bgp_table *table;
5134
5135 /* MPLS-VPN aggregation is not yet supported. */
5136 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5137 return;
5138
5139 table = bgp->aggregate[afi][safi];
5140
5141 /* No aggregates configured. */
5142 if (bgp_table_top_nolock (table) == NULL)
5143 return;
5144
5145 if (p->prefixlen == 0)
5146 return;
5147
5148 if (BGP_INFO_HOLDDOWN (ri))
5149 return;
5150
5151 child = bgp_node_get (table, p);
5152
5153 /* Aggregate address configuration check. */
5154 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5155 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5156 {
5157 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5158 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5159 }
5160 bgp_unlock_node (child);
5161 }
5162
5163 void
5164 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5165 struct bgp_info *del, afi_t afi, safi_t safi)
5166 {
5167 struct bgp_node *child;
5168 struct bgp_node *rn;
5169 struct bgp_aggregate *aggregate;
5170 struct bgp_table *table;
5171
5172 /* MPLS-VPN aggregation is not yet supported. */
5173 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5174 return;
5175
5176 table = bgp->aggregate[afi][safi];
5177
5178 /* No aggregates configured. */
5179 if (bgp_table_top_nolock (table) == NULL)
5180 return;
5181
5182 if (p->prefixlen == 0)
5183 return;
5184
5185 child = bgp_node_get (table, p);
5186
5187 /* Aggregate address configuration check. */
5188 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5189 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5190 {
5191 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5192 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5193 }
5194 bgp_unlock_node (child);
5195 }
5196
5197 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5198 static void
5199 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5200 struct bgp_aggregate *aggregate)
5201 {
5202 struct bgp_table *table;
5203 struct bgp_node *top;
5204 struct bgp_node *rn;
5205 struct bgp_info *new;
5206 struct bgp_info *ri;
5207 unsigned long match;
5208 u_char origin = BGP_ORIGIN_IGP;
5209 struct aspath *aspath = NULL;
5210 struct aspath *asmerge = NULL;
5211 struct community *community = NULL;
5212 struct community *commerge = NULL;
5213 u_char atomic_aggregate = 0;
5214
5215 table = bgp->rib[afi][safi];
5216
5217 /* Sanity check. */
5218 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5219 return;
5220 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5221 return;
5222
5223 /* If routes exists below this node, generate aggregate routes. */
5224 top = bgp_node_get (table, p);
5225 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5226 if (rn->p.prefixlen > p->prefixlen)
5227 {
5228 match = 0;
5229
5230 for (ri = rn->info; ri; ri = ri->next)
5231 {
5232 if (BGP_INFO_HOLDDOWN (ri))
5233 continue;
5234
5235 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5236 atomic_aggregate = 1;
5237
5238 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5239 {
5240 /* summary-only aggregate route suppress aggregated
5241 route announcement. */
5242 if (aggregate->summary_only)
5243 {
5244 (bgp_info_extra_get (ri))->suppress++;
5245 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5246 match++;
5247 }
5248
5249 /* If at least one route among routes that are aggregated has
5250 * ORIGIN with the value INCOMPLETE, then the aggregated route
5251 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5252 * Otherwise, if at least one route among routes that are
5253 * aggregated has ORIGIN with the value EGP, then the aggregated
5254 * route MUST have the ORIGIN attribute with the value EGP.
5255 */
5256 if (origin < ri->attr->origin)
5257 origin = ri->attr->origin;
5258
5259 /* as-set aggregate route generate origin, as path,
5260 community aggregation. */
5261 if (aggregate->as_set)
5262 {
5263 if (aspath)
5264 {
5265 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5266 aspath_free (aspath);
5267 aspath = asmerge;
5268 }
5269 else
5270 aspath = aspath_dup (ri->attr->aspath);
5271
5272 if (ri->attr->community)
5273 {
5274 if (community)
5275 {
5276 commerge = community_merge (community,
5277 ri->attr->community);
5278 community = community_uniq_sort (commerge);
5279 community_free (commerge);
5280 }
5281 else
5282 community = community_dup (ri->attr->community);
5283 }
5284 }
5285 aggregate->count++;
5286 }
5287 }
5288
5289 /* If this node is suppressed, process the change. */
5290 if (match)
5291 bgp_process (bgp, rn, afi, safi);
5292 }
5293 bgp_unlock_node (top);
5294
5295 /* Add aggregate route to BGP table. */
5296 if (aggregate->count)
5297 {
5298 rn = bgp_node_get (table, p);
5299 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5300 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5301 aggregate->as_set,
5302 atomic_aggregate), rn);
5303 SET_FLAG (new->flags, BGP_INFO_VALID);
5304
5305 bgp_info_add (rn, new);
5306 bgp_unlock_node (rn);
5307
5308 /* Process change. */
5309 bgp_process (bgp, rn, afi, safi);
5310 }
5311 else
5312 {
5313 if (aspath)
5314 aspath_free (aspath);
5315 if (community)
5316 community_free (community);
5317 }
5318 }
5319
5320 void
5321 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5322 safi_t safi, struct bgp_aggregate *aggregate)
5323 {
5324 struct bgp_table *table;
5325 struct bgp_node *top;
5326 struct bgp_node *rn;
5327 struct bgp_info *ri;
5328 unsigned long match;
5329
5330 table = bgp->rib[afi][safi];
5331
5332 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5333 return;
5334 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5335 return;
5336
5337 /* If routes exists below this node, generate aggregate routes. */
5338 top = bgp_node_get (table, p);
5339 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5340 if (rn->p.prefixlen > p->prefixlen)
5341 {
5342 match = 0;
5343
5344 for (ri = rn->info; ri; ri = ri->next)
5345 {
5346 if (BGP_INFO_HOLDDOWN (ri))
5347 continue;
5348
5349 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5350 {
5351 if (aggregate->summary_only && ri->extra)
5352 {
5353 ri->extra->suppress--;
5354
5355 if (ri->extra->suppress == 0)
5356 {
5357 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5358 match++;
5359 }
5360 }
5361 aggregate->count--;
5362 }
5363 }
5364
5365 /* If this node was suppressed, process the change. */
5366 if (match)
5367 bgp_process (bgp, rn, afi, safi);
5368 }
5369 bgp_unlock_node (top);
5370
5371 /* Delete aggregate route from BGP table. */
5372 rn = bgp_node_get (table, p);
5373
5374 for (ri = rn->info; ri; ri = ri->next)
5375 if (ri->peer == bgp->peer_self
5376 && ri->type == ZEBRA_ROUTE_BGP
5377 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5378 break;
5379
5380 /* Withdraw static BGP route from routing table. */
5381 if (ri)
5382 {
5383 bgp_info_delete (rn, ri);
5384 bgp_process (bgp, rn, afi, safi);
5385 }
5386
5387 /* Unlock bgp_node_lookup. */
5388 bgp_unlock_node (rn);
5389 }
5390
5391 /* Aggregate route attribute. */
5392 #define AGGREGATE_SUMMARY_ONLY 1
5393 #define AGGREGATE_AS_SET 1
5394
5395 static int
5396 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5397 afi_t afi, safi_t safi)
5398 {
5399 int ret;
5400 struct prefix p;
5401 struct bgp_node *rn;
5402 struct bgp *bgp;
5403 struct bgp_aggregate *aggregate;
5404
5405 /* Convert string to prefix structure. */
5406 ret = str2prefix (prefix_str, &p);
5407 if (!ret)
5408 {
5409 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5410 return CMD_WARNING;
5411 }
5412 apply_mask (&p);
5413
5414 /* Get BGP structure. */
5415 bgp = vty->index;
5416
5417 /* Old configuration check. */
5418 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5419 if (! rn)
5420 {
5421 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5422 VTY_NEWLINE);
5423 return CMD_WARNING;
5424 }
5425
5426 aggregate = rn->info;
5427 if (aggregate->safi & SAFI_UNICAST)
5428 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5429 if (aggregate->safi & SAFI_MULTICAST)
5430 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5431
5432 /* Unlock aggregate address configuration. */
5433 rn->info = NULL;
5434 bgp_aggregate_free (aggregate);
5435 bgp_unlock_node (rn);
5436 bgp_unlock_node (rn);
5437
5438 return CMD_SUCCESS;
5439 }
5440
5441 static int
5442 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5443 afi_t afi, safi_t safi,
5444 u_char summary_only, u_char as_set)
5445 {
5446 int ret;
5447 struct prefix p;
5448 struct bgp_node *rn;
5449 struct bgp *bgp;
5450 struct bgp_aggregate *aggregate;
5451
5452 /* Convert string to prefix structure. */
5453 ret = str2prefix (prefix_str, &p);
5454 if (!ret)
5455 {
5456 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5457 return CMD_WARNING;
5458 }
5459 apply_mask (&p);
5460
5461 /* Get BGP structure. */
5462 bgp = vty->index;
5463
5464 /* Old configuration check. */
5465 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5466
5467 if (rn->info)
5468 {
5469 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5470 /* try to remove the old entry */
5471 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5472 if (ret)
5473 {
5474 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5475 bgp_unlock_node (rn);
5476 return CMD_WARNING;
5477 }
5478 }
5479
5480 /* Make aggregate address structure. */
5481 aggregate = bgp_aggregate_new ();
5482 aggregate->summary_only = summary_only;
5483 aggregate->as_set = as_set;
5484 aggregate->safi = safi;
5485 rn->info = aggregate;
5486
5487 /* Aggregate address insert into BGP routing table. */
5488 if (safi & SAFI_UNICAST)
5489 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5490 if (safi & SAFI_MULTICAST)
5491 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5492
5493 return CMD_SUCCESS;
5494 }
5495
5496 DEFUN (aggregate_address,
5497 aggregate_address_cmd,
5498 "aggregate-address A.B.C.D/M",
5499 "Configure BGP aggregate entries\n"
5500 "Aggregate prefix\n")
5501 {
5502 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5503 }
5504
5505 DEFUN (aggregate_address_mask,
5506 aggregate_address_mask_cmd,
5507 "aggregate-address A.B.C.D A.B.C.D",
5508 "Configure BGP aggregate entries\n"
5509 "Aggregate address\n"
5510 "Aggregate mask\n")
5511 {
5512 int ret;
5513 char prefix_str[BUFSIZ];
5514
5515 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5516
5517 if (! ret)
5518 {
5519 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5520 return CMD_WARNING;
5521 }
5522
5523 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5524 0, 0);
5525 }
5526
5527 DEFUN (aggregate_address_summary_only,
5528 aggregate_address_summary_only_cmd,
5529 "aggregate-address A.B.C.D/M summary-only",
5530 "Configure BGP aggregate entries\n"
5531 "Aggregate prefix\n"
5532 "Filter more specific routes from updates\n")
5533 {
5534 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5535 AGGREGATE_SUMMARY_ONLY, 0);
5536 }
5537
5538 DEFUN (aggregate_address_mask_summary_only,
5539 aggregate_address_mask_summary_only_cmd,
5540 "aggregate-address A.B.C.D A.B.C.D summary-only",
5541 "Configure BGP aggregate entries\n"
5542 "Aggregate address\n"
5543 "Aggregate mask\n"
5544 "Filter more specific routes from updates\n")
5545 {
5546 int ret;
5547 char prefix_str[BUFSIZ];
5548
5549 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5550
5551 if (! ret)
5552 {
5553 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5554 return CMD_WARNING;
5555 }
5556
5557 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5558 AGGREGATE_SUMMARY_ONLY, 0);
5559 }
5560
5561 DEFUN (aggregate_address_as_set,
5562 aggregate_address_as_set_cmd,
5563 "aggregate-address A.B.C.D/M as-set",
5564 "Configure BGP aggregate entries\n"
5565 "Aggregate prefix\n"
5566 "Generate AS set path information\n")
5567 {
5568 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5569 0, AGGREGATE_AS_SET);
5570 }
5571
5572 DEFUN (aggregate_address_mask_as_set,
5573 aggregate_address_mask_as_set_cmd,
5574 "aggregate-address A.B.C.D A.B.C.D as-set",
5575 "Configure BGP aggregate entries\n"
5576 "Aggregate address\n"
5577 "Aggregate mask\n"
5578 "Generate AS set path information\n")
5579 {
5580 int ret;
5581 char prefix_str[BUFSIZ];
5582
5583 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5584
5585 if (! ret)
5586 {
5587 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5588 return CMD_WARNING;
5589 }
5590
5591 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5592 0, AGGREGATE_AS_SET);
5593 }
5594
5595
5596 DEFUN (aggregate_address_as_set_summary,
5597 aggregate_address_as_set_summary_cmd,
5598 "aggregate-address A.B.C.D/M as-set summary-only",
5599 "Configure BGP aggregate entries\n"
5600 "Aggregate prefix\n"
5601 "Generate AS set path information\n"
5602 "Filter more specific routes from updates\n")
5603 {
5604 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5605 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5606 }
5607
5608 ALIAS (aggregate_address_as_set_summary,
5609 aggregate_address_summary_as_set_cmd,
5610 "aggregate-address A.B.C.D/M summary-only as-set",
5611 "Configure BGP aggregate entries\n"
5612 "Aggregate prefix\n"
5613 "Filter more specific routes from updates\n"
5614 "Generate AS set path information\n")
5615
5616 DEFUN (aggregate_address_mask_as_set_summary,
5617 aggregate_address_mask_as_set_summary_cmd,
5618 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5619 "Configure BGP aggregate entries\n"
5620 "Aggregate address\n"
5621 "Aggregate mask\n"
5622 "Generate AS set path information\n"
5623 "Filter more specific routes from updates\n")
5624 {
5625 int ret;
5626 char prefix_str[BUFSIZ];
5627
5628 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5629
5630 if (! ret)
5631 {
5632 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5633 return CMD_WARNING;
5634 }
5635
5636 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5637 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5638 }
5639
5640 ALIAS (aggregate_address_mask_as_set_summary,
5641 aggregate_address_mask_summary_as_set_cmd,
5642 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5643 "Configure BGP aggregate entries\n"
5644 "Aggregate address\n"
5645 "Aggregate mask\n"
5646 "Filter more specific routes from updates\n"
5647 "Generate AS set path information\n")
5648
5649 DEFUN (no_aggregate_address,
5650 no_aggregate_address_cmd,
5651 "no aggregate-address A.B.C.D/M",
5652 NO_STR
5653 "Configure BGP aggregate entries\n"
5654 "Aggregate prefix\n")
5655 {
5656 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5657 }
5658
5659 ALIAS (no_aggregate_address,
5660 no_aggregate_address_summary_only_cmd,
5661 "no aggregate-address A.B.C.D/M summary-only",
5662 NO_STR
5663 "Configure BGP aggregate entries\n"
5664 "Aggregate prefix\n"
5665 "Filter more specific routes from updates\n")
5666
5667 ALIAS (no_aggregate_address,
5668 no_aggregate_address_as_set_cmd,
5669 "no aggregate-address A.B.C.D/M as-set",
5670 NO_STR
5671 "Configure BGP aggregate entries\n"
5672 "Aggregate prefix\n"
5673 "Generate AS set path information\n")
5674
5675 ALIAS (no_aggregate_address,
5676 no_aggregate_address_as_set_summary_cmd,
5677 "no aggregate-address A.B.C.D/M as-set summary-only",
5678 NO_STR
5679 "Configure BGP aggregate entries\n"
5680 "Aggregate prefix\n"
5681 "Generate AS set path information\n"
5682 "Filter more specific routes from updates\n")
5683
5684 ALIAS (no_aggregate_address,
5685 no_aggregate_address_summary_as_set_cmd,
5686 "no aggregate-address A.B.C.D/M summary-only as-set",
5687 NO_STR
5688 "Configure BGP aggregate entries\n"
5689 "Aggregate prefix\n"
5690 "Filter more specific routes from updates\n"
5691 "Generate AS set path information\n")
5692
5693 DEFUN (no_aggregate_address_mask,
5694 no_aggregate_address_mask_cmd,
5695 "no aggregate-address A.B.C.D A.B.C.D",
5696 NO_STR
5697 "Configure BGP aggregate entries\n"
5698 "Aggregate address\n"
5699 "Aggregate mask\n")
5700 {
5701 int ret;
5702 char prefix_str[BUFSIZ];
5703
5704 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5705
5706 if (! ret)
5707 {
5708 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5709 return CMD_WARNING;
5710 }
5711
5712 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5713 }
5714
5715 ALIAS (no_aggregate_address_mask,
5716 no_aggregate_address_mask_summary_only_cmd,
5717 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5718 NO_STR
5719 "Configure BGP aggregate entries\n"
5720 "Aggregate address\n"
5721 "Aggregate mask\n"
5722 "Filter more specific routes from updates\n")
5723
5724 ALIAS (no_aggregate_address_mask,
5725 no_aggregate_address_mask_as_set_cmd,
5726 "no aggregate-address A.B.C.D A.B.C.D as-set",
5727 NO_STR
5728 "Configure BGP aggregate entries\n"
5729 "Aggregate address\n"
5730 "Aggregate mask\n"
5731 "Generate AS set path information\n")
5732
5733 ALIAS (no_aggregate_address_mask,
5734 no_aggregate_address_mask_as_set_summary_cmd,
5735 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5736 NO_STR
5737 "Configure BGP aggregate entries\n"
5738 "Aggregate address\n"
5739 "Aggregate mask\n"
5740 "Generate AS set path information\n"
5741 "Filter more specific routes from updates\n")
5742
5743 ALIAS (no_aggregate_address_mask,
5744 no_aggregate_address_mask_summary_as_set_cmd,
5745 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5746 NO_STR
5747 "Configure BGP aggregate entries\n"
5748 "Aggregate address\n"
5749 "Aggregate mask\n"
5750 "Filter more specific routes from updates\n"
5751 "Generate AS set path information\n")
5752
5753 #ifdef HAVE_IPV6
5754 DEFUN (ipv6_aggregate_address,
5755 ipv6_aggregate_address_cmd,
5756 "aggregate-address X:X::X:X/M",
5757 "Configure BGP aggregate entries\n"
5758 "Aggregate prefix\n")
5759 {
5760 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5761 }
5762
5763 DEFUN (ipv6_aggregate_address_summary_only,
5764 ipv6_aggregate_address_summary_only_cmd,
5765 "aggregate-address X:X::X:X/M summary-only",
5766 "Configure BGP aggregate entries\n"
5767 "Aggregate prefix\n"
5768 "Filter more specific routes from updates\n")
5769 {
5770 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5771 AGGREGATE_SUMMARY_ONLY, 0);
5772 }
5773
5774 DEFUN (no_ipv6_aggregate_address,
5775 no_ipv6_aggregate_address_cmd,
5776 "no aggregate-address X:X::X:X/M",
5777 NO_STR
5778 "Configure BGP aggregate entries\n"
5779 "Aggregate prefix\n")
5780 {
5781 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5782 }
5783
5784 DEFUN (no_ipv6_aggregate_address_summary_only,
5785 no_ipv6_aggregate_address_summary_only_cmd,
5786 "no aggregate-address X:X::X:X/M summary-only",
5787 NO_STR
5788 "Configure BGP aggregate entries\n"
5789 "Aggregate prefix\n"
5790 "Filter more specific routes from updates\n")
5791 {
5792 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5793 }
5794
5795 ALIAS (ipv6_aggregate_address,
5796 old_ipv6_aggregate_address_cmd,
5797 "ipv6 bgp aggregate-address X:X::X:X/M",
5798 IPV6_STR
5799 BGP_STR
5800 "Configure BGP aggregate entries\n"
5801 "Aggregate prefix\n")
5802
5803 ALIAS (ipv6_aggregate_address_summary_only,
5804 old_ipv6_aggregate_address_summary_only_cmd,
5805 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5806 IPV6_STR
5807 BGP_STR
5808 "Configure BGP aggregate entries\n"
5809 "Aggregate prefix\n"
5810 "Filter more specific routes from updates\n")
5811
5812 ALIAS (no_ipv6_aggregate_address,
5813 old_no_ipv6_aggregate_address_cmd,
5814 "no ipv6 bgp aggregate-address X:X::X:X/M",
5815 NO_STR
5816 IPV6_STR
5817 BGP_STR
5818 "Configure BGP aggregate entries\n"
5819 "Aggregate prefix\n")
5820
5821 ALIAS (no_ipv6_aggregate_address_summary_only,
5822 old_no_ipv6_aggregate_address_summary_only_cmd,
5823 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5824 NO_STR
5825 IPV6_STR
5826 BGP_STR
5827 "Configure BGP aggregate entries\n"
5828 "Aggregate prefix\n"
5829 "Filter more specific routes from updates\n")
5830 #endif /* HAVE_IPV6 */
5831
5832 /* Redistribute route treatment. */
5833 void
5834 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5835 const struct in6_addr *nexthop6, unsigned int ifindex,
5836 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
5837 {
5838 struct bgp_info *new;
5839 struct bgp_info *bi;
5840 struct bgp_info info;
5841 struct bgp_node *bn;
5842 struct attr attr;
5843 struct attr *new_attr;
5844 afi_t afi;
5845 int ret;
5846 struct bgp_redist *red;
5847
5848 /* Make default attribute. */
5849 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5850 if (nexthop)
5851 attr.nexthop = *nexthop;
5852 attr.nh_ifindex = ifindex;
5853
5854 #ifdef HAVE_IPV6
5855 if (nexthop6)
5856 {
5857 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5858 extra->mp_nexthop_global = *nexthop6;
5859 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5860 }
5861 #endif
5862
5863 attr.med = metric;
5864 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5865 attr.extra->tag = tag;
5866
5867 afi = family2afi (p->family);
5868
5869 red = bgp_redist_lookup(bgp, afi, type, instance);
5870 if (red)
5871 {
5872 struct attr attr_new;
5873 struct attr_extra extra_new;
5874
5875 /* Copy attribute for modification. */
5876 attr_new.extra = &extra_new;
5877 bgp_attr_dup (&attr_new, &attr);
5878
5879 if (red->redist_metric_flag)
5880 attr_new.med = red->redist_metric;
5881
5882 /* Apply route-map. */
5883 if (red->rmap.name)
5884 {
5885 info.peer = bgp->peer_self;
5886 info.attr = &attr_new;
5887
5888 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5889
5890 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5891
5892 bgp->peer_self->rmap_type = 0;
5893
5894 if (ret == RMAP_DENYMATCH)
5895 {
5896 /* Free uninterned attribute. */
5897 bgp_attr_flush (&attr_new);
5898
5899 /* Unintern original. */
5900 aspath_unintern (&attr.aspath);
5901 bgp_attr_extra_free (&attr);
5902 bgp_redistribute_delete (bgp, p, type, instance);
5903 return;
5904 }
5905 }
5906
5907 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5908 afi, SAFI_UNICAST, p, NULL);
5909
5910 new_attr = bgp_attr_intern (&attr_new);
5911
5912 for (bi = bn->info; bi; bi = bi->next)
5913 if (bi->peer == bgp->peer_self
5914 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5915 break;
5916
5917 if (bi)
5918 {
5919 /* Ensure the (source route) type is updated. */
5920 bi->type = type;
5921 if (attrhash_cmp (bi->attr, new_attr) &&
5922 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5923 {
5924 bgp_attr_unintern (&new_attr);
5925 aspath_unintern (&attr.aspath);
5926 bgp_attr_extra_free (&attr);
5927 bgp_unlock_node (bn);
5928 return;
5929 }
5930 else
5931 {
5932 /* The attribute is changed. */
5933 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5934
5935 /* Rewrite BGP route information. */
5936 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5937 bgp_info_restore(bn, bi);
5938 else
5939 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5940 bgp_attr_unintern (&bi->attr);
5941 bi->attr = new_attr;
5942 bi->uptime = bgp_clock ();
5943
5944 /* Process change. */
5945 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5946 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5947 bgp_unlock_node (bn);
5948 aspath_unintern (&attr.aspath);
5949 bgp_attr_extra_free (&attr);
5950 return;
5951 }
5952 }
5953
5954 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5955 new_attr, bn);
5956 SET_FLAG (new->flags, BGP_INFO_VALID);
5957
5958 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5959 bgp_info_add (bn, new);
5960 bgp_unlock_node (bn);
5961 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5962 }
5963
5964 /* Unintern original. */
5965 aspath_unintern (&attr.aspath);
5966 bgp_attr_extra_free (&attr);
5967 }
5968
5969 void
5970 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5971 {
5972 afi_t afi;
5973 struct bgp_node *rn;
5974 struct bgp_info *ri;
5975 struct bgp_redist *red;
5976
5977 afi = family2afi (p->family);
5978
5979 red = bgp_redist_lookup(bgp, afi, type, instance);
5980 if (red)
5981 {
5982 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5983
5984 for (ri = rn->info; ri; ri = ri->next)
5985 if (ri->peer == bgp->peer_self
5986 && ri->type == type)
5987 break;
5988
5989 if (ri)
5990 {
5991 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5992 bgp_info_delete (rn, ri);
5993 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5994 }
5995 bgp_unlock_node (rn);
5996 }
5997 }
5998
5999 /* Withdraw specified route type's route. */
6000 void
6001 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
6002 {
6003 struct bgp_node *rn;
6004 struct bgp_info *ri;
6005 struct bgp_table *table;
6006
6007 table = bgp->rib[afi][SAFI_UNICAST];
6008
6009 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6010 {
6011 for (ri = rn->info; ri; ri = ri->next)
6012 if (ri->peer == bgp->peer_self
6013 && ri->type == type
6014 && ri->instance == instance)
6015 break;
6016
6017 if (ri)
6018 {
6019 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6020 bgp_info_delete (rn, ri);
6021 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6022 }
6023 }
6024 }
6025
6026 /* Static function to display route. */
6027 static void
6028 route_vty_out_route (struct prefix *p, struct vty *vty)
6029 {
6030 int len;
6031 u_int32_t destination;
6032 char buf[BUFSIZ];
6033
6034 if (p->family == AF_INET)
6035 {
6036 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6037 destination = ntohl (p->u.prefix4.s_addr);
6038
6039 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6040 || (IN_CLASSB (destination) && p->prefixlen == 16)
6041 || (IN_CLASSA (destination) && p->prefixlen == 8)
6042 || p->u.prefix4.s_addr == 0)
6043 {
6044 /* When mask is natural, mask is not displayed. */
6045 }
6046 else
6047 len += vty_out (vty, "/%d", p->prefixlen);
6048 }
6049 else
6050 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6051 p->prefixlen);
6052
6053 len = 17 - len;
6054 if (len < 1)
6055 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6056 else
6057 vty_out (vty, "%*s", len, " ");
6058 }
6059
6060 enum bgp_display_type
6061 {
6062 normal_list,
6063 };
6064
6065 /* Print the short form route status for a bgp_info */
6066 static void
6067 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6068 json_object *json_path)
6069 {
6070 if (json_path)
6071 {
6072
6073 /* Route status display. */
6074 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6075 json_object_boolean_true_add(json_path, "removed");
6076
6077 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6078 json_object_boolean_true_add(json_path, "stale");
6079
6080 if (binfo->extra && binfo->extra->suppress)
6081 json_object_boolean_true_add(json_path, "suppressed");
6082
6083 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6084 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6085 json_object_boolean_true_add(json_path, "valid");
6086
6087 /* Selected */
6088 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6089 json_object_boolean_true_add(json_path, "history");
6090
6091 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6092 json_object_boolean_true_add(json_path, "damped");
6093
6094 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6095 json_object_boolean_true_add(json_path, "bestpath");
6096
6097 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6098 json_object_boolean_true_add(json_path, "multipath");
6099
6100 /* Internal route. */
6101 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6102 json_object_string_add(json_path, "pathFrom", "internal");
6103 else
6104 json_object_string_add(json_path, "pathFrom", "external");
6105
6106 return;
6107 }
6108
6109 /* Route status display. */
6110 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6111 vty_out (vty, "R");
6112 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6113 vty_out (vty, "S");
6114 else if (binfo->extra && binfo->extra->suppress)
6115 vty_out (vty, "s");
6116 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6117 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6118 vty_out (vty, "*");
6119 else
6120 vty_out (vty, " ");
6121
6122 /* Selected */
6123 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6124 vty_out (vty, "h");
6125 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6126 vty_out (vty, "d");
6127 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6128 vty_out (vty, ">");
6129 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6130 vty_out (vty, "=");
6131 else
6132 vty_out (vty, " ");
6133
6134 /* Internal route. */
6135 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6136 vty_out (vty, "i");
6137 else
6138 vty_out (vty, " ");
6139 }
6140
6141 /* called from terminal list command */
6142 void
6143 route_vty_out (struct vty *vty, struct prefix *p,
6144 struct bgp_info *binfo, int display, safi_t safi,
6145 json_object *json_paths)
6146 {
6147 struct attr *attr;
6148 json_object *json_path = NULL;
6149 json_object *json_nexthops = NULL;
6150 json_object *json_nexthop_global = NULL;
6151 json_object *json_nexthop_ll = NULL;
6152
6153 if (json_paths)
6154 json_path = json_object_new_object();
6155
6156 /* short status lead text */
6157 route_vty_short_status_out (vty, binfo, json_path);
6158
6159 if (!json_paths)
6160 {
6161 /* print prefix and mask */
6162 if (! display)
6163 route_vty_out_route (p, vty);
6164 else
6165 vty_out (vty, "%*s", 17, " ");
6166 }
6167
6168 /* Print attribute */
6169 attr = binfo->attr;
6170 if (attr)
6171 {
6172 /*
6173 * For ENCAP routes, nexthop address family is not
6174 * neccessarily the same as the prefix address family.
6175 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6176 */
6177 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6178 {
6179 if (attr->extra)
6180 {
6181 char buf[BUFSIZ];
6182 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6183
6184 switch (af)
6185 {
6186 case AF_INET:
6187 vty_out (vty, "%s", inet_ntop(af,
6188 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6189 break;
6190 #if HAVE_IPV6
6191 case AF_INET6:
6192 vty_out (vty, "%s", inet_ntop(af,
6193 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6194 break;
6195 #endif
6196 default:
6197 vty_out(vty, "?");
6198 break;
6199 }
6200 }
6201 else
6202 vty_out(vty, "?");
6203 }
6204 /* IPv4 Next Hop */
6205 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6206 {
6207 if (json_paths)
6208 {
6209 json_nexthop_global = json_object_new_object();
6210
6211 if (safi == SAFI_MPLS_VPN)
6212 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6213 else
6214 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6215
6216 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6217 json_object_boolean_true_add(json_nexthop_global, "used");
6218 }
6219 else
6220 {
6221 if (safi == SAFI_MPLS_VPN)
6222 vty_out (vty, "%-16s",
6223 inet_ntoa (attr->extra->mp_nexthop_global_in));
6224 else
6225 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6226 }
6227 }
6228
6229 /* IPv6 Next Hop */
6230 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6231 {
6232 int len;
6233 char buf[BUFSIZ];
6234
6235 if (json_paths)
6236 {
6237 json_nexthop_global = json_object_new_object();
6238 json_object_string_add(json_nexthop_global, "ip",
6239 inet_ntop (AF_INET6,
6240 &attr->extra->mp_nexthop_global,
6241 buf, BUFSIZ));
6242 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6243 json_object_string_add(json_nexthop_global, "scope", "global");
6244
6245 /* We display both LL & GL if both have been received */
6246 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6247 {
6248 json_nexthop_ll = json_object_new_object();
6249 json_object_string_add(json_nexthop_ll, "ip",
6250 inet_ntop (AF_INET6,
6251 &attr->extra->mp_nexthop_local,
6252 buf, BUFSIZ));
6253 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6254 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6255
6256 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6257 &attr->extra->mp_nexthop_local) != 0) &&
6258 !attr->extra->mp_nexthop_prefer_global)
6259 json_object_boolean_true_add(json_nexthop_ll, "used");
6260 else
6261 json_object_boolean_true_add(json_nexthop_global, "used");
6262 }
6263 else
6264 json_object_boolean_true_add(json_nexthop_global, "used");
6265 }
6266 else
6267 {
6268 /* Display LL if LL/Global both in table unless prefer-global is set */
6269 if (((attr->extra->mp_nexthop_len == 32) &&
6270 !attr->extra->mp_nexthop_prefer_global) ||
6271 (binfo->peer->conf_if))
6272 {
6273 if (binfo->peer->conf_if)
6274 {
6275 len = vty_out (vty, "%s",
6276 binfo->peer->conf_if);
6277 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6278
6279 if (len < 1)
6280 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6281 else
6282 vty_out (vty, "%*s", len, " ");
6283 }
6284 else
6285 {
6286 len = vty_out (vty, "%s",
6287 inet_ntop (AF_INET6,
6288 &attr->extra->mp_nexthop_local,
6289 buf, BUFSIZ));
6290 len = 16 - len;
6291
6292 if (len < 1)
6293 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6294 else
6295 vty_out (vty, "%*s", len, " ");
6296 }
6297 }
6298 else
6299 {
6300 len = vty_out (vty, "%s",
6301 inet_ntop (AF_INET6,
6302 &attr->extra->mp_nexthop_global,
6303 buf, BUFSIZ));
6304 len = 16 - len;
6305
6306 if (len < 1)
6307 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6308 else
6309 vty_out (vty, "%*s", len, " ");
6310 }
6311 }
6312 }
6313
6314 /* MED/Metric */
6315 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6316 if (json_paths)
6317 json_object_int_add(json_path, "med", attr->med);
6318 else
6319 vty_out (vty, "%10u ", attr->med);
6320 else
6321 if (!json_paths)
6322 vty_out (vty, " ");
6323
6324 /* Local Pref */
6325 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6326 if (json_paths)
6327 json_object_int_add(json_path, "localpref", attr->local_pref);
6328 else
6329 vty_out (vty, "%7u ", attr->local_pref);
6330 else
6331 if (!json_paths)
6332 vty_out (vty, " ");
6333
6334 if (json_paths)
6335 {
6336 if (attr->extra)
6337 json_object_int_add(json_path, "weight", attr->extra->weight);
6338 else
6339 json_object_int_add(json_path, "weight", 0);
6340 }
6341 else
6342 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6343
6344 if (json_paths) {
6345 char buf[BUFSIZ];
6346 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6347 }
6348
6349 /* Print aspath */
6350 if (attr->aspath)
6351 {
6352 if (json_paths)
6353 json_object_string_add(json_path, "aspath", attr->aspath->str);
6354 else
6355 aspath_print_vty (vty, "%s", attr->aspath, " ");
6356 }
6357
6358 /* Print origin */
6359 if (json_paths)
6360 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6361 else
6362 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6363 }
6364 else
6365 {
6366 if (json_paths)
6367 json_object_string_add(json_path, "alert", "No attributes");
6368 else
6369 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6370 }
6371
6372 if (json_paths)
6373 {
6374 if (json_nexthop_global || json_nexthop_ll)
6375 {
6376 json_nexthops = json_object_new_array();
6377
6378 if (json_nexthop_global)
6379 json_object_array_add(json_nexthops, json_nexthop_global);
6380
6381 if (json_nexthop_ll)
6382 json_object_array_add(json_nexthops, json_nexthop_ll);
6383
6384 json_object_object_add(json_path, "nexthops", json_nexthops);
6385 }
6386
6387 json_object_array_add(json_paths, json_path);
6388 }
6389 else
6390 {
6391 vty_out (vty, "%s", VTY_NEWLINE);
6392 #if ENABLE_BGP_VNC
6393 /* prints an additional line, indented, with VNC info, if present */
6394 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_UNICAST))
6395 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6396 #endif
6397 }
6398 }
6399
6400 /* called from terminal list command */
6401 void
6402 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6403 u_char use_json, json_object *json_ar)
6404 {
6405 json_object *json_status = NULL;
6406 json_object *json_net = NULL;
6407 char buff[BUFSIZ];
6408 /* Route status display. */
6409 if (use_json)
6410 {
6411 json_status = json_object_new_object();
6412 json_net = json_object_new_object();
6413 }
6414 else
6415 {
6416 vty_out (vty, "*");
6417 vty_out (vty, ">");
6418 vty_out (vty, " ");
6419 }
6420
6421 /* print prefix and mask */
6422 if (use_json)
6423 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6424 else
6425 route_vty_out_route (p, vty);
6426
6427 /* Print attribute */
6428 if (attr)
6429 {
6430 if (use_json)
6431 {
6432 if (p->family == AF_INET &&
6433 (safi == SAFI_MPLS_VPN ||
6434 safi == SAFI_ENCAP ||
6435 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6436 {
6437 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6438 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6439 else
6440 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6441 }
6442 #ifdef HAVE_IPV6
6443 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6444 {
6445 char buf[BUFSIZ];
6446
6447 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6448 buf, BUFSIZ));
6449 }
6450 #endif /* HAVE_IPV6 */
6451
6452 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6453 json_object_int_add(json_net, "metric", attr->med);
6454
6455 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6456 json_object_int_add(json_net, "localPref", attr->local_pref);
6457
6458 if (attr->extra)
6459 json_object_int_add(json_net, "weight", attr->extra->weight);
6460 else
6461 json_object_int_add(json_net, "weight", 0);
6462
6463 /* Print aspath */
6464 if (attr->aspath)
6465 json_object_string_add(json_net, "asPath", attr->aspath->str);
6466
6467 /* Print origin */
6468 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6469 }
6470 else
6471 {
6472 if (p->family == AF_INET &&
6473 (safi == SAFI_MPLS_VPN ||
6474 safi == SAFI_ENCAP ||
6475 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6476 {
6477 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6478 vty_out (vty, "%-16s",
6479 inet_ntoa (attr->extra->mp_nexthop_global_in));
6480 else
6481 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6482 }
6483 #ifdef HAVE_IPV6
6484 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6485 {
6486 int len;
6487 char buf[BUFSIZ];
6488
6489 assert (attr->extra);
6490
6491 len = vty_out (vty, "%s",
6492 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6493 buf, BUFSIZ));
6494 len = 16 - len;
6495 if (len < 1)
6496 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6497 else
6498 vty_out (vty, "%*s", len, " ");
6499 }
6500 #endif /* HAVE_IPV6 */
6501 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6502 vty_out (vty, "%10u ", attr->med);
6503 else
6504 vty_out (vty, " ");
6505
6506 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6507 vty_out (vty, "%7u ", attr->local_pref);
6508 else
6509 vty_out (vty, " ");
6510
6511 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6512
6513 /* Print aspath */
6514 if (attr->aspath)
6515 aspath_print_vty (vty, "%s", attr->aspath, " ");
6516
6517 /* Print origin */
6518 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6519 }
6520 }
6521 if (use_json)
6522 {
6523 json_object_boolean_true_add(json_status, "*");
6524 json_object_boolean_true_add(json_status, ">");
6525 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6526 char buf_cut[BUFSIZ];
6527 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6528 }
6529 else
6530 vty_out (vty, "%s", VTY_NEWLINE);
6531 }
6532
6533 void
6534 route_vty_out_tag (struct vty *vty, struct prefix *p,
6535 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6536 {
6537 json_object *json_out = NULL;
6538 struct attr *attr;
6539 u_int32_t label = 0;
6540
6541 if (!binfo->extra)
6542 return;
6543
6544 if (json)
6545 json_out = json_object_new_object();
6546
6547 /* short status lead text */
6548 route_vty_short_status_out (vty, binfo, json_out);
6549
6550 /* print prefix and mask */
6551 if (json == NULL)
6552 {
6553 if (! display)
6554 route_vty_out_route (p, vty);
6555 else
6556 vty_out (vty, "%*s", 17, " ");
6557 }
6558
6559 /* Print attribute */
6560 attr = binfo->attr;
6561 if (attr)
6562 {
6563 if (p->family == AF_INET
6564 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6565 {
6566 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6567 {
6568 if (json)
6569 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6570 else
6571 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6572 }
6573 else
6574 {
6575 if (json)
6576 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6577 else
6578 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6579 }
6580 }
6581 #ifdef HAVE_IPV6
6582 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6583 {
6584 assert (attr->extra);
6585 char buf_a[BUFSIZ];
6586 char buf_b[BUFSIZ];
6587 char buf_c[BUFSIZ];
6588 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6589 {
6590 if (json)
6591 json_object_string_add(json_out, "mpNexthopGlobalIn",
6592 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6593 else
6594 vty_out (vty, "%s",
6595 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6596 buf_a, BUFSIZ));
6597 }
6598 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6599 {
6600 if (json)
6601 {
6602 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6603 buf_a, BUFSIZ);
6604 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6605 buf_b, BUFSIZ);
6606 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6607 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6608 }
6609 else
6610 vty_out (vty, "%s(%s)",
6611 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6612 buf_a, BUFSIZ),
6613 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6614 buf_b, BUFSIZ));
6615 }
6616
6617 }
6618 #endif /* HAVE_IPV6 */
6619 }
6620
6621 label = decode_label (binfo->extra->tag);
6622
6623 if (json)
6624 {
6625 if (label)
6626 json_object_int_add(json_out, "notag", label);
6627 json_object_array_add(json, json_out);
6628 }
6629 else
6630 {
6631 vty_out (vty, "notag/%d", label);
6632 vty_out (vty, "%s", VTY_NEWLINE);
6633 }
6634 }
6635
6636 /* dampening route */
6637 static void
6638 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6639 int display, safi_t safi, u_char use_json, json_object *json)
6640 {
6641 struct attr *attr;
6642 int len;
6643 char timebuf[BGP_UPTIME_LEN];
6644
6645 /* short status lead text */
6646 route_vty_short_status_out (vty, binfo, json);
6647
6648 /* print prefix and mask */
6649 if (!use_json)
6650 {
6651 if (! display)
6652 route_vty_out_route (p, vty);
6653 else
6654 vty_out (vty, "%*s", 17, " ");
6655 }
6656
6657 len = vty_out (vty, "%s", binfo->peer->host);
6658 len = 17 - len;
6659 if (len < 1)
6660 {
6661 if (!use_json)
6662 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6663 }
6664 else
6665 {
6666 if (use_json)
6667 json_object_int_add(json, "peerHost", len);
6668 else
6669 vty_out (vty, "%*s", len, " ");
6670 }
6671
6672 if (use_json)
6673 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6674 else
6675 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6676
6677 /* Print attribute */
6678 attr = binfo->attr;
6679 if (attr)
6680 {
6681 /* Print aspath */
6682 if (attr->aspath)
6683 {
6684 if (use_json)
6685 json_object_string_add(json, "asPath", attr->aspath->str);
6686 else
6687 aspath_print_vty (vty, "%s", attr->aspath, " ");
6688 }
6689
6690 /* Print origin */
6691 if (use_json)
6692 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6693 else
6694 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6695 }
6696 if (!use_json)
6697 vty_out (vty, "%s", VTY_NEWLINE);
6698 }
6699
6700 /* flap route */
6701 static void
6702 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6703 int display, safi_t safi, u_char use_json, json_object *json)
6704 {
6705 struct attr *attr;
6706 struct bgp_damp_info *bdi;
6707 char timebuf[BGP_UPTIME_LEN];
6708 int len;
6709
6710 if (!binfo->extra)
6711 return;
6712
6713 bdi = binfo->extra->damp_info;
6714
6715 /* short status lead text */
6716 route_vty_short_status_out (vty, binfo, json);
6717
6718 /* print prefix and mask */
6719 if (!use_json)
6720 {
6721 if (! display)
6722 route_vty_out_route (p, vty);
6723 else
6724 vty_out (vty, "%*s", 17, " ");
6725 }
6726
6727 len = vty_out (vty, "%s", binfo->peer->host);
6728 len = 16 - len;
6729 if (len < 1)
6730 {
6731 if (!use_json)
6732 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6733 }
6734 else
6735 {
6736 if (use_json)
6737 json_object_int_add(json, "peerHost", len);
6738 else
6739 vty_out (vty, "%*s", len, " ");
6740 }
6741
6742 len = vty_out (vty, "%d", bdi->flap);
6743 len = 5 - len;
6744 if (len < 1)
6745 {
6746 if (!use_json)
6747 vty_out (vty, " ");
6748 }
6749 else
6750 {
6751 if (use_json)
6752 json_object_int_add(json, "bdiFlap", len);
6753 else
6754 vty_out (vty, "%*s", len, " ");
6755 }
6756
6757 if (use_json)
6758 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6759 else
6760 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6761 timebuf, BGP_UPTIME_LEN, 0, NULL));
6762
6763 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6764 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6765 {
6766 if (use_json)
6767 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6768 else
6769 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6770 }
6771 else
6772 {
6773 if (!use_json)
6774 vty_out (vty, "%*s ", 8, " ");
6775 }
6776
6777 /* Print attribute */
6778 attr = binfo->attr;
6779 if (attr)
6780 {
6781 /* Print aspath */
6782 if (attr->aspath)
6783 {
6784 if (use_json)
6785 json_object_string_add(json, "asPath", attr->aspath->str);
6786 else
6787 aspath_print_vty (vty, "%s", attr->aspath, " ");
6788 }
6789
6790 /* Print origin */
6791 if (use_json)
6792 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6793 else
6794 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6795 }
6796 if (!use_json)
6797 vty_out (vty, "%s", VTY_NEWLINE);
6798 }
6799
6800 static void
6801 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6802 const char *header, json_object *json_adv_to)
6803 {
6804 char buf1[INET6_ADDRSTRLEN];
6805 json_object *json_peer = NULL;
6806
6807 if (json_adv_to)
6808 {
6809 /* 'advertised-to' is a dictionary of peers we have advertised this
6810 * prefix too. The key is the peer's IP or swpX, the value is the
6811 * hostname if we know it and "" if not.
6812 */
6813 json_peer = json_object_new_object();
6814
6815 if (peer->hostname)
6816 json_object_string_add(json_peer, "hostname", peer->hostname);
6817
6818 if (peer->conf_if)
6819 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6820 else
6821 json_object_object_add(json_adv_to,
6822 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6823 json_peer);
6824 }
6825 else
6826 {
6827 if (*first)
6828 {
6829 vty_out (vty, "%s", header);
6830 *first = 0;
6831 }
6832
6833 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6834 {
6835 if (peer->conf_if)
6836 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6837 else
6838 vty_out (vty, " %s(%s)", peer->hostname,
6839 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6840 }
6841 else
6842 {
6843 if (peer->conf_if)
6844 vty_out (vty, " %s", peer->conf_if);
6845 else
6846 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6847 }
6848 }
6849 }
6850
6851 static void
6852 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6853 struct bgp_info *binfo, afi_t afi, safi_t safi,
6854 json_object *json_paths)
6855 {
6856 char buf[INET6_ADDRSTRLEN];
6857 char buf1[BUFSIZ];
6858 struct attr *attr;
6859 int sockunion_vty_out (struct vty *, union sockunion *);
6860 #ifdef HAVE_CLOCK_MONOTONIC
6861 time_t tbuf;
6862 #endif
6863 json_object *json_bestpath = NULL;
6864 json_object *json_cluster_list = NULL;
6865 json_object *json_cluster_list_list = NULL;
6866 json_object *json_ext_community = NULL;
6867 json_object *json_last_update = NULL;
6868 json_object *json_nexthop_global = NULL;
6869 json_object *json_nexthop_ll = NULL;
6870 json_object *json_nexthops = NULL;
6871 json_object *json_path = NULL;
6872 json_object *json_peer = NULL;
6873 json_object *json_string = NULL;
6874 json_object *json_adv_to = NULL;
6875 int first = 0;
6876 struct listnode *node, *nnode;
6877 struct peer *peer;
6878 int addpath_capable;
6879 int has_adj;
6880 unsigned int first_as;
6881
6882 if (json_paths)
6883 {
6884 json_path = json_object_new_object();
6885 json_peer = json_object_new_object();
6886 json_nexthop_global = json_object_new_object();
6887 }
6888
6889 attr = binfo->attr;
6890
6891 if (attr)
6892 {
6893 /* Line1 display AS-path, Aggregator */
6894 if (attr->aspath)
6895 {
6896 if (json_paths)
6897 {
6898 json_object_lock(attr->aspath->json);
6899 json_object_object_add(json_path, "aspath", attr->aspath->json);
6900 }
6901 else
6902 {
6903 if (attr->aspath->segments)
6904 aspath_print_vty (vty, " %s", attr->aspath, "");
6905 else
6906 vty_out (vty, " Local");
6907 }
6908 }
6909
6910 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6911 {
6912 if (json_paths)
6913 json_object_boolean_true_add(json_path, "removed");
6914 else
6915 vty_out (vty, ", (removed)");
6916 }
6917
6918 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6919 {
6920 if (json_paths)
6921 json_object_boolean_true_add(json_path, "stale");
6922 else
6923 vty_out (vty, ", (stale)");
6924 }
6925
6926 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6927 {
6928 if (json_paths)
6929 {
6930 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6931 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6932 }
6933 else
6934 {
6935 vty_out (vty, ", (aggregated by %u %s)",
6936 attr->extra->aggregator_as,
6937 inet_ntoa (attr->extra->aggregator_addr));
6938 }
6939 }
6940
6941 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6942 {
6943 if (json_paths)
6944 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6945 else
6946 vty_out (vty, ", (Received from a RR-client)");
6947 }
6948
6949 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6950 {
6951 if (json_paths)
6952 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6953 else
6954 vty_out (vty, ", (Received from a RS-client)");
6955 }
6956
6957 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6958 {
6959 if (json_paths)
6960 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6961 else
6962 vty_out (vty, ", (history entry)");
6963 }
6964 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6965 {
6966 if (json_paths)
6967 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6968 else
6969 vty_out (vty, ", (suppressed due to dampening)");
6970 }
6971
6972 if (!json_paths)
6973 vty_out (vty, "%s", VTY_NEWLINE);
6974
6975 /* Line2 display Next-hop, Neighbor, Router-id */
6976 /* Display the nexthop */
6977 if (p->family == AF_INET &&
6978 (safi == SAFI_MPLS_VPN ||
6979 safi == SAFI_ENCAP ||
6980 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6981 {
6982 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6983 {
6984 if (json_paths)
6985 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6986 else
6987 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6988 }
6989 else
6990 {
6991 if (json_paths)
6992 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6993 else
6994 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6995 }
6996
6997 if (json_paths)
6998 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6999 }
7000 else
7001 {
7002 assert (attr->extra);
7003 if (json_paths)
7004 {
7005 json_object_string_add(json_nexthop_global, "ip",
7006 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7007 buf, INET6_ADDRSTRLEN));
7008 json_object_string_add(json_nexthop_global, "afi", "ipv6");
7009 json_object_string_add(json_nexthop_global, "scope", "global");
7010 }
7011 else
7012 {
7013 vty_out (vty, " %s",
7014 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7015 buf, INET6_ADDRSTRLEN));
7016 }
7017 }
7018
7019 /* Display the IGP cost or 'inaccessible' */
7020 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7021 {
7022 if (json_paths)
7023 json_object_boolean_false_add(json_nexthop_global, "accessible");
7024 else
7025 vty_out (vty, " (inaccessible)");
7026 }
7027 else
7028 {
7029 if (binfo->extra && binfo->extra->igpmetric)
7030 {
7031 if (json_paths)
7032 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
7033 else
7034 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7035 }
7036
7037 /* IGP cost is 0, display this only for json */
7038 else
7039 {
7040 if (json_paths)
7041 json_object_int_add(json_nexthop_global, "metric", 0);
7042 }
7043
7044 if (json_paths)
7045 json_object_boolean_true_add(json_nexthop_global, "accessible");
7046 }
7047
7048 /* Display peer "from" output */
7049 /* This path was originated locally */
7050 if (binfo->peer == bgp->peer_self)
7051 {
7052
7053 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
7054 {
7055 if (json_paths)
7056 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7057 else
7058 vty_out (vty, " from 0.0.0.0 ");
7059 }
7060 else
7061 {
7062 if (json_paths)
7063 json_object_string_add(json_peer, "peerId", "::");
7064 else
7065 vty_out (vty, " from :: ");
7066 }
7067
7068 if (json_paths)
7069 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7070 else
7071 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7072 }
7073
7074 /* We RXed this path from one of our peers */
7075 else
7076 {
7077
7078 if (json_paths)
7079 {
7080 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7081 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7082
7083 if (binfo->peer->hostname)
7084 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7085
7086 if (binfo->peer->domainname)
7087 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7088
7089 if (binfo->peer->conf_if)
7090 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7091 }
7092 else
7093 {
7094 if (binfo->peer->conf_if)
7095 {
7096 if (binfo->peer->hostname &&
7097 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7098 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7099 binfo->peer->conf_if);
7100 else
7101 vty_out (vty, " from %s", binfo->peer->conf_if);
7102 }
7103 else
7104 {
7105 if (binfo->peer->hostname &&
7106 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7107 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7108 binfo->peer->host);
7109 else
7110 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7111 }
7112
7113 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7114 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7115 else
7116 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7117 }
7118 }
7119
7120 if (!json_paths)
7121 vty_out (vty, "%s", VTY_NEWLINE);
7122
7123 /* display the link-local nexthop */
7124 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7125 {
7126 if (json_paths)
7127 {
7128 json_nexthop_ll = json_object_new_object();
7129 json_object_string_add(json_nexthop_ll, "ip",
7130 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7131 buf, INET6_ADDRSTRLEN));
7132 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7133 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7134
7135 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7136
7137 if (!attr->extra->mp_nexthop_prefer_global)
7138 json_object_boolean_true_add(json_nexthop_ll, "used");
7139 else
7140 json_object_boolean_true_add(json_nexthop_global, "used");
7141 }
7142 else
7143 {
7144 vty_out (vty, " (%s) %s%s",
7145 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7146 buf, INET6_ADDRSTRLEN),
7147 attr->extra->mp_nexthop_prefer_global ?
7148 "(prefer-global)" : "(used)",
7149 VTY_NEWLINE);
7150 }
7151 }
7152 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7153 else
7154 {
7155 if (json_paths)
7156 json_object_boolean_true_add(json_nexthop_global, "used");
7157 }
7158
7159 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7160 if (json_paths)
7161 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7162 else
7163 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7164
7165 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7166 {
7167 if (json_paths)
7168 json_object_int_add(json_path, "med", attr->med);
7169 else
7170 vty_out (vty, ", metric %u", attr->med);
7171 }
7172
7173 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7174 {
7175 if (json_paths)
7176 json_object_int_add(json_path, "localpref", attr->local_pref);
7177 else
7178 vty_out (vty, ", localpref %u", attr->local_pref);
7179 }
7180 else
7181 {
7182 if (json_paths)
7183 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7184 else
7185 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7186 }
7187
7188 if (attr->extra && attr->extra->weight != 0)
7189 {
7190 if (json_paths)
7191 json_object_int_add(json_path, "weight", attr->extra->weight);
7192 else
7193 vty_out (vty, ", weight %u", attr->extra->weight);
7194 }
7195
7196 if (attr->extra && attr->extra->tag != 0)
7197 {
7198 if (json_paths)
7199 json_object_int_add(json_path, "tag", attr->extra->tag);
7200 else
7201 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
7202 }
7203
7204 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7205 {
7206 if (json_paths)
7207 json_object_boolean_false_add(json_path, "valid");
7208 else
7209 vty_out (vty, ", invalid");
7210 }
7211 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7212 {
7213 if (json_paths)
7214 json_object_boolean_true_add(json_path, "valid");
7215 else
7216 vty_out (vty, ", valid");
7217 }
7218
7219 if (binfo->peer != bgp->peer_self)
7220 {
7221 if (binfo->peer->as == binfo->peer->local_as)
7222 {
7223 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7224 {
7225 if (json_paths)
7226 json_object_string_add(json_peer, "type", "confed-internal");
7227 else
7228 vty_out (vty, ", confed-internal");
7229 }
7230 else
7231 {
7232 if (json_paths)
7233 json_object_string_add(json_peer, "type", "internal");
7234 else
7235 vty_out (vty, ", internal");
7236 }
7237 }
7238 else
7239 {
7240 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7241 {
7242 if (json_paths)
7243 json_object_string_add(json_peer, "type", "confed-external");
7244 else
7245 vty_out (vty, ", confed-external");
7246 }
7247 else
7248 {
7249 if (json_paths)
7250 json_object_string_add(json_peer, "type", "external");
7251 else
7252 vty_out (vty, ", external");
7253 }
7254 }
7255 }
7256 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7257 {
7258 if (json_paths)
7259 {
7260 json_object_boolean_true_add(json_path, "aggregated");
7261 json_object_boolean_true_add(json_path, "local");
7262 }
7263 else
7264 {
7265 vty_out (vty, ", aggregated, local");
7266 }
7267 }
7268 else if (binfo->type != ZEBRA_ROUTE_BGP)
7269 {
7270 if (json_paths)
7271 json_object_boolean_true_add(json_path, "sourced");
7272 else
7273 vty_out (vty, ", sourced");
7274 }
7275 else
7276 {
7277 if (json_paths)
7278 {
7279 json_object_boolean_true_add(json_path, "sourced");
7280 json_object_boolean_true_add(json_path, "local");
7281 }
7282 else
7283 {
7284 vty_out (vty, ", sourced, local");
7285 }
7286 }
7287
7288 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7289 {
7290 if (json_paths)
7291 json_object_boolean_true_add(json_path, "atomicAggregate");
7292 else
7293 vty_out (vty, ", atomic-aggregate");
7294 }
7295
7296 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7297 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7298 bgp_info_mpath_count (binfo)))
7299 {
7300 if (json_paths)
7301 json_object_boolean_true_add(json_path, "multipath");
7302 else
7303 vty_out (vty, ", multipath");
7304 }
7305
7306 // Mark the bestpath(s)
7307 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7308 {
7309 first_as = aspath_get_first_as(attr->aspath);
7310
7311 if (json_paths)
7312 {
7313 if (!json_bestpath)
7314 json_bestpath = json_object_new_object();
7315 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7316 }
7317 else
7318 {
7319 if (first_as)
7320 vty_out (vty, ", bestpath-from-AS %d", first_as);
7321 else
7322 vty_out (vty, ", bestpath-from-AS Local");
7323 }
7324 }
7325
7326 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7327 {
7328 if (json_paths)
7329 {
7330 if (!json_bestpath)
7331 json_bestpath = json_object_new_object();
7332 json_object_boolean_true_add(json_bestpath, "overall");
7333 }
7334 else
7335 vty_out (vty, ", best");
7336 }
7337
7338 if (json_bestpath)
7339 json_object_object_add(json_path, "bestpath", json_bestpath);
7340
7341 if (!json_paths)
7342 vty_out (vty, "%s", VTY_NEWLINE);
7343
7344 /* Line 4 display Community */
7345 if (attr->community)
7346 {
7347 if (json_paths)
7348 {
7349 json_object_lock(attr->community->json);
7350 json_object_object_add(json_path, "community", attr->community->json);
7351 }
7352 else
7353 {
7354 vty_out (vty, " Community: %s%s", attr->community->str,
7355 VTY_NEWLINE);
7356 }
7357 }
7358
7359 /* Line 5 display Extended-community */
7360 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7361 {
7362 if (json_paths)
7363 {
7364 json_ext_community = json_object_new_object();
7365 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7366 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7367 }
7368 else
7369 {
7370 vty_out (vty, " Extended Community: %s%s",
7371 attr->extra->ecommunity->str, VTY_NEWLINE);
7372 }
7373 }
7374
7375 /* Line 6 display Originator, Cluster-id */
7376 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7377 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7378 {
7379 assert (attr->extra);
7380 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7381 {
7382 if (json_paths)
7383 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7384 else
7385 vty_out (vty, " Originator: %s",
7386 inet_ntoa (attr->extra->originator_id));
7387 }
7388
7389 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7390 {
7391 int i;
7392
7393 if (json_paths)
7394 {
7395 json_cluster_list = json_object_new_object();
7396 json_cluster_list_list = json_object_new_array();
7397
7398 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7399 {
7400 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7401 json_object_array_add(json_cluster_list_list, json_string);
7402 }
7403
7404 /* struct cluster_list does not have "str" variable like
7405 * aspath and community do. Add this someday if someone
7406 * asks for it.
7407 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7408 */
7409 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7410 json_object_object_add(json_path, "clusterList", json_cluster_list);
7411 }
7412 else
7413 {
7414 vty_out (vty, ", Cluster list: ");
7415
7416 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7417 {
7418 vty_out (vty, "%s ",
7419 inet_ntoa (attr->extra->cluster->list[i]));
7420 }
7421 }
7422 }
7423
7424 if (!json_paths)
7425 vty_out (vty, "%s", VTY_NEWLINE);
7426 }
7427
7428 if (binfo->extra && binfo->extra->damp_info)
7429 bgp_damp_info_vty (vty, binfo, json_path);
7430
7431 /* Line 7 display Addpath IDs */
7432 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7433 {
7434 if (json_paths)
7435 {
7436 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7437 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7438 }
7439 else
7440 {
7441 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7442 binfo->addpath_rx_id, binfo->addpath_tx_id,
7443 VTY_NEWLINE);
7444 }
7445 }
7446
7447 /* If we used addpath to TX a non-bestpath we need to display
7448 * "Advertised to" on a path-by-path basis */
7449 if (bgp->addpath_tx_used[afi][safi])
7450 {
7451 first = 1;
7452
7453 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7454 {
7455 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7456 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7457
7458 if ((addpath_capable && has_adj) ||
7459 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7460 {
7461 if (json_path && !json_adv_to)
7462 json_adv_to = json_object_new_object();
7463
7464 route_vty_out_advertised_to(vty, peer, &first,
7465 " Advertised to:",
7466 json_adv_to);
7467 }
7468 }
7469
7470 if (json_path)
7471 {
7472 if (json_adv_to)
7473 {
7474 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7475 }
7476 }
7477 else
7478 {
7479 if (!first)
7480 {
7481 vty_out (vty, "%s", VTY_NEWLINE);
7482 }
7483 }
7484 }
7485
7486 /* Line 8 display Uptime */
7487 #ifdef HAVE_CLOCK_MONOTONIC
7488 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7489 if (json_paths)
7490 {
7491 json_last_update = json_object_new_object();
7492 json_object_int_add(json_last_update, "epoch", tbuf);
7493 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7494 json_object_object_add(json_path, "lastUpdate", json_last_update);
7495 }
7496 else
7497 vty_out (vty, " Last update: %s", ctime(&tbuf));
7498 #else
7499 if (json_paths)
7500 {
7501 json_last_update = json_object_new_object();
7502 json_object_int_add(json_last_update, "epoch", tbuf);
7503 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7504 json_object_object_add(json_path, "lastUpdate", json_last_update);
7505 }
7506 else
7507 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7508 #endif /* HAVE_CLOCK_MONOTONIC */
7509 }
7510
7511 /* We've constructed the json object for this path, add it to the json
7512 * array of paths
7513 */
7514 if (json_paths)
7515 {
7516 if (json_nexthop_global || json_nexthop_ll)
7517 {
7518 json_nexthops = json_object_new_array();
7519
7520 if (json_nexthop_global)
7521 json_object_array_add(json_nexthops, json_nexthop_global);
7522
7523 if (json_nexthop_ll)
7524 json_object_array_add(json_nexthops, json_nexthop_ll);
7525
7526 json_object_object_add(json_path, "nexthops", json_nexthops);
7527 }
7528
7529 json_object_object_add(json_path, "peer", json_peer);
7530 json_object_array_add(json_paths, json_path);
7531 }
7532 else
7533 vty_out (vty, "%s", VTY_NEWLINE);
7534 }
7535
7536 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7537 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7538 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7539
7540 enum bgp_show_type
7541 {
7542 bgp_show_type_normal,
7543 bgp_show_type_regexp,
7544 bgp_show_type_prefix_list,
7545 bgp_show_type_filter_list,
7546 bgp_show_type_route_map,
7547 bgp_show_type_neighbor,
7548 bgp_show_type_cidr_only,
7549 bgp_show_type_prefix_longer,
7550 bgp_show_type_community_all,
7551 bgp_show_type_community,
7552 bgp_show_type_community_exact,
7553 bgp_show_type_community_list,
7554 bgp_show_type_community_list_exact,
7555 bgp_show_type_flap_statistics,
7556 bgp_show_type_flap_address,
7557 bgp_show_type_flap_prefix,
7558 bgp_show_type_flap_cidr_only,
7559 bgp_show_type_flap_regexp,
7560 bgp_show_type_flap_filter_list,
7561 bgp_show_type_flap_prefix_list,
7562 bgp_show_type_flap_prefix_longer,
7563 bgp_show_type_flap_route_map,
7564 bgp_show_type_flap_neighbor,
7565 bgp_show_type_dampend_paths,
7566 bgp_show_type_damp_neighbor
7567 };
7568
7569 static int
7570 bgp_show_prefix_list (struct vty *vty, const char *name,
7571 const char *prefix_list_str, afi_t afi,
7572 safi_t safi, enum bgp_show_type type);
7573 static int
7574 bgp_show_filter_list (struct vty *vty, const char *name,
7575 const char *filter, afi_t afi,
7576 safi_t safi, enum bgp_show_type type);
7577 static int
7578 bgp_show_route_map (struct vty *vty, const char *name,
7579 const char *rmap_str, afi_t afi,
7580 safi_t safi, enum bgp_show_type type);
7581 static int
7582 bgp_show_community_list (struct vty *vty, const char *name,
7583 const char *com, int exact,
7584 afi_t afi, safi_t safi);
7585 static int
7586 bgp_show_prefix_longer (struct vty *vty, const char *name,
7587 const char *prefix, afi_t afi,
7588 safi_t safi, enum bgp_show_type type);
7589
7590 static int
7591 bgp_show_table (struct vty *vty, struct bgp_table *table,
7592 struct in_addr *router_id, enum bgp_show_type type,
7593 void *output_arg, u_char use_json, json_object *json)
7594 {
7595 struct bgp_info *ri;
7596 struct bgp_node *rn;
7597 int header = 1;
7598 int display;
7599 unsigned long output_count;
7600 unsigned long total_count;
7601 struct prefix *p;
7602 char buf[BUFSIZ];
7603 char buf2[BUFSIZ];
7604 json_object *json_paths = NULL;
7605 json_object *json_routes = NULL;
7606
7607 if (use_json)
7608 {
7609 if (json == NULL)
7610 json = json_object_new_object();
7611
7612 json_object_int_add(json, "tableVersion", table->version);
7613 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7614 json_routes = json_object_new_object();
7615 }
7616
7617 /* This is first entry point, so reset total line. */
7618 output_count = 0;
7619 total_count = 0;
7620
7621 /* Start processing of routes. */
7622 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7623 if (rn->info != NULL)
7624 {
7625 display = 0;
7626
7627 if (use_json)
7628 json_paths = json_object_new_array();
7629 else
7630 json_paths = NULL;
7631
7632 for (ri = rn->info; ri; ri = ri->next)
7633 {
7634 total_count++;
7635 if (type == bgp_show_type_flap_statistics
7636 || type == bgp_show_type_flap_address
7637 || type == bgp_show_type_flap_prefix
7638 || type == bgp_show_type_flap_cidr_only
7639 || type == bgp_show_type_flap_regexp
7640 || type == bgp_show_type_flap_filter_list
7641 || type == bgp_show_type_flap_prefix_list
7642 || type == bgp_show_type_flap_prefix_longer
7643 || type == bgp_show_type_flap_route_map
7644 || type == bgp_show_type_flap_neighbor
7645 || type == bgp_show_type_dampend_paths
7646 || type == bgp_show_type_damp_neighbor)
7647 {
7648 if (!(ri->extra && ri->extra->damp_info))
7649 continue;
7650 }
7651 if (type == bgp_show_type_regexp
7652 || type == bgp_show_type_flap_regexp)
7653 {
7654 regex_t *regex = output_arg;
7655
7656 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7657 continue;
7658 }
7659 if (type == bgp_show_type_prefix_list
7660 || type == bgp_show_type_flap_prefix_list)
7661 {
7662 struct prefix_list *plist = output_arg;
7663
7664 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7665 continue;
7666 }
7667 if (type == bgp_show_type_filter_list
7668 || type == bgp_show_type_flap_filter_list)
7669 {
7670 struct as_list *as_list = output_arg;
7671
7672 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7673 continue;
7674 }
7675 if (type == bgp_show_type_route_map
7676 || type == bgp_show_type_flap_route_map)
7677 {
7678 struct route_map *rmap = output_arg;
7679 struct bgp_info binfo;
7680 struct attr dummy_attr;
7681 struct attr_extra dummy_extra;
7682 int ret;
7683
7684 dummy_attr.extra = &dummy_extra;
7685 bgp_attr_dup (&dummy_attr, ri->attr);
7686
7687 binfo.peer = ri->peer;
7688 binfo.attr = &dummy_attr;
7689
7690 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7691 if (ret == RMAP_DENYMATCH)
7692 continue;
7693 }
7694 if (type == bgp_show_type_neighbor
7695 || type == bgp_show_type_flap_neighbor
7696 || type == bgp_show_type_damp_neighbor)
7697 {
7698 union sockunion *su = output_arg;
7699
7700 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7701 continue;
7702 }
7703 if (type == bgp_show_type_cidr_only
7704 || type == bgp_show_type_flap_cidr_only)
7705 {
7706 u_int32_t destination;
7707
7708 destination = ntohl (rn->p.u.prefix4.s_addr);
7709 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7710 continue;
7711 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7712 continue;
7713 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7714 continue;
7715 }
7716 if (type == bgp_show_type_prefix_longer
7717 || type == bgp_show_type_flap_prefix_longer)
7718 {
7719 struct prefix *p = output_arg;
7720
7721 if (! prefix_match (p, &rn->p))
7722 continue;
7723 }
7724 if (type == bgp_show_type_community_all)
7725 {
7726 if (! ri->attr->community)
7727 continue;
7728 }
7729 if (type == bgp_show_type_community)
7730 {
7731 struct community *com = output_arg;
7732
7733 if (! ri->attr->community ||
7734 ! community_match (ri->attr->community, com))
7735 continue;
7736 }
7737 if (type == bgp_show_type_community_exact)
7738 {
7739 struct community *com = output_arg;
7740
7741 if (! ri->attr->community ||
7742 ! community_cmp (ri->attr->community, com))
7743 continue;
7744 }
7745 if (type == bgp_show_type_community_list)
7746 {
7747 struct community_list *list = output_arg;
7748
7749 if (! community_list_match (ri->attr->community, list))
7750 continue;
7751 }
7752 if (type == bgp_show_type_community_list_exact)
7753 {
7754 struct community_list *list = output_arg;
7755
7756 if (! community_list_exact_match (ri->attr->community, list))
7757 continue;
7758 }
7759 if (type == bgp_show_type_flap_address
7760 || type == bgp_show_type_flap_prefix)
7761 {
7762 struct prefix *p = output_arg;
7763
7764 if (! prefix_match (&rn->p, p))
7765 continue;
7766
7767 if (type == bgp_show_type_flap_prefix)
7768 if (p->prefixlen != rn->p.prefixlen)
7769 continue;
7770 }
7771 if (type == bgp_show_type_dampend_paths
7772 || type == bgp_show_type_damp_neighbor)
7773 {
7774 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7775 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7776 continue;
7777 }
7778
7779 if (!use_json && header)
7780 {
7781 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7782 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7783 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7784 if (type == bgp_show_type_dampend_paths
7785 || type == bgp_show_type_damp_neighbor)
7786 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7787 else if (type == bgp_show_type_flap_statistics
7788 || type == bgp_show_type_flap_address
7789 || type == bgp_show_type_flap_prefix
7790 || type == bgp_show_type_flap_cidr_only
7791 || type == bgp_show_type_flap_regexp
7792 || type == bgp_show_type_flap_filter_list
7793 || type == bgp_show_type_flap_prefix_list
7794 || type == bgp_show_type_flap_prefix_longer
7795 || type == bgp_show_type_flap_route_map
7796 || type == bgp_show_type_flap_neighbor)
7797 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7798 else
7799 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7800 header = 0;
7801 }
7802
7803 if (type == bgp_show_type_dampend_paths
7804 || type == bgp_show_type_damp_neighbor)
7805 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7806 else if (type == bgp_show_type_flap_statistics
7807 || type == bgp_show_type_flap_address
7808 || type == bgp_show_type_flap_prefix
7809 || type == bgp_show_type_flap_cidr_only
7810 || type == bgp_show_type_flap_regexp
7811 || type == bgp_show_type_flap_filter_list
7812 || type == bgp_show_type_flap_prefix_list
7813 || type == bgp_show_type_flap_prefix_longer
7814 || type == bgp_show_type_flap_route_map
7815 || type == bgp_show_type_flap_neighbor)
7816 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7817 else
7818 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7819 display++;
7820 }
7821
7822 if (display)
7823 {
7824 output_count++;
7825 if (use_json)
7826 {
7827 p = &rn->p;
7828 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7829 json_object_object_add(json_routes, buf2, json_paths);
7830 }
7831 }
7832 }
7833
7834 if (use_json)
7835 {
7836 /* This can produce a LOT of text so do not use
7837 * JSON_C_TO_STRING_PRETTY here
7838 */
7839 json_object_object_add(json, "routes", json_routes);
7840 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7841 json_object_free(json);
7842 }
7843 else
7844 {
7845 /* No route is displayed */
7846 if (output_count == 0)
7847 {
7848 if (type == bgp_show_type_normal)
7849 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7850 }
7851 else
7852 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
7853 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7854 }
7855
7856 return CMD_SUCCESS;
7857 }
7858
7859 static int
7860 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7861 enum bgp_show_type type, void *output_arg, u_char use_json)
7862 {
7863 struct bgp_table *table;
7864
7865 if (bgp == NULL)
7866 {
7867 bgp = bgp_get_default ();
7868 }
7869
7870 if (bgp == NULL)
7871 {
7872 if (!use_json)
7873 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7874 return CMD_WARNING;
7875 }
7876
7877 table = bgp->rib[afi][safi];
7878
7879 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7880 use_json, NULL);
7881 }
7882
7883 static void
7884 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7885 u_char use_json)
7886 {
7887 struct listnode *node, *nnode;
7888 struct bgp *bgp;
7889 struct bgp_table *table;
7890 json_object *json = NULL;
7891 int is_first = 1;
7892
7893 if (use_json)
7894 vty_out (vty, "{%s", VTY_NEWLINE);
7895
7896 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7897 {
7898 if (use_json)
7899 {
7900 if (!(json = json_object_new_object()))
7901 {
7902 zlog_err("Unable to allocate memory for JSON object");
7903 vty_out (vty,
7904 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7905 VTY_NEWLINE);
7906 return;
7907 }
7908 json_object_int_add(json, "vrfId",
7909 (bgp->vrf_id == VRF_UNKNOWN)
7910 ? -1 : bgp->vrf_id);
7911 json_object_string_add(json, "vrfName",
7912 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7913 ? "Default" : bgp->name);
7914 if (! is_first)
7915 vty_out (vty, ",%s", VTY_NEWLINE);
7916 else
7917 is_first = 0;
7918
7919 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7920 ? "Default" : bgp->name);
7921 }
7922 else
7923 {
7924 vty_out (vty, "%sInstance %s:%s",
7925 VTY_NEWLINE,
7926 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7927 ? "Default" : bgp->name,
7928 VTY_NEWLINE);
7929 }
7930 table = bgp->rib[afi][safi];
7931 bgp_show_table (vty, table, &bgp->router_id,
7932 bgp_show_type_normal, NULL, use_json, json);
7933
7934 }
7935
7936 if (use_json)
7937 vty_out (vty, "}%s", VTY_NEWLINE);
7938 }
7939
7940 /* Header of detailed BGP route information */
7941 static void
7942 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7943 struct bgp_node *rn,
7944 struct prefix_rd *prd, afi_t afi, safi_t safi,
7945 json_object *json)
7946 {
7947 struct bgp_info *ri;
7948 struct prefix *p;
7949 struct peer *peer;
7950 struct listnode *node, *nnode;
7951 char buf1[INET6_ADDRSTRLEN];
7952 char buf2[INET6_ADDRSTRLEN];
7953 int count = 0;
7954 int best = 0;
7955 int suppress = 0;
7956 int no_export = 0;
7957 int no_advertise = 0;
7958 int local_as = 0;
7959 int first = 1;
7960 json_object *json_adv_to = NULL;
7961
7962 p = &rn->p;
7963
7964 if (json)
7965 {
7966 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7967 json_object_int_add(json, "prefixlen", p->prefixlen);
7968 }
7969 else
7970 {
7971 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7972 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7973 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7974 safi == SAFI_MPLS_VPN ? ":" : "",
7975 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7976 p->prefixlen, VTY_NEWLINE);
7977 }
7978
7979 for (ri = rn->info; ri; ri = ri->next)
7980 {
7981 count++;
7982 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7983 {
7984 best = count;
7985 if (ri->extra && ri->extra->suppress)
7986 suppress = 1;
7987 if (ri->attr->community != NULL)
7988 {
7989 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7990 no_advertise = 1;
7991 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7992 no_export = 1;
7993 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7994 local_as = 1;
7995 }
7996 }
7997 }
7998
7999 if (!json)
8000 {
8001 vty_out (vty, "Paths: (%d available", count);
8002 if (best)
8003 {
8004 vty_out (vty, ", best #%d", best);
8005 if (safi == SAFI_UNICAST)
8006 vty_out (vty, ", table %s",
8007 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8008 ? "Default-IP-Routing-Table" : bgp->name);
8009 }
8010 else
8011 vty_out (vty, ", no best path");
8012
8013 if (no_advertise)
8014 vty_out (vty, ", not advertised to any peer");
8015 else if (no_export)
8016 vty_out (vty, ", not advertised to EBGP peer");
8017 else if (local_as)
8018 vty_out (vty, ", not advertised outside local AS");
8019
8020 if (suppress)
8021 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8022 vty_out (vty, ")%s", VTY_NEWLINE);
8023 }
8024
8025 /* If we are not using addpath then we can display Advertised to and that will
8026 * show what peers we advertised the bestpath to. If we are using addpath
8027 * though then we must display Advertised to on a path-by-path basis. */
8028 if (!bgp->addpath_tx_used[afi][safi])
8029 {
8030 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8031 {
8032 if (bgp_adj_out_lookup (peer, rn, 0))
8033 {
8034 if (json && !json_adv_to)
8035 json_adv_to = json_object_new_object();
8036
8037 route_vty_out_advertised_to(vty, peer, &first,
8038 " Advertised to non peer-group peers:\n ",
8039 json_adv_to);
8040 }
8041 }
8042
8043 if (json)
8044 {
8045 if (json_adv_to)
8046 {
8047 json_object_object_add(json, "advertisedTo", json_adv_to);
8048 }
8049 }
8050 else
8051 {
8052 if (first)
8053 vty_out (vty, " Not advertised to any peer");
8054 vty_out (vty, "%s", VTY_NEWLINE);
8055 }
8056 }
8057 }
8058
8059 /* Display specified route of BGP table. */
8060 static int
8061 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
8062 struct bgp_table *rib, const char *ip_str,
8063 afi_t afi, safi_t safi, struct prefix_rd *prd,
8064 int prefix_check, enum bgp_path_type pathtype,
8065 u_char use_json)
8066 {
8067 int ret;
8068 int header;
8069 int display = 0;
8070 struct prefix match;
8071 struct bgp_node *rn;
8072 struct bgp_node *rm;
8073 struct bgp_info *ri;
8074 struct bgp_table *table;
8075 json_object *json = NULL;
8076 json_object *json_paths = NULL;
8077
8078 /* Check IP address argument. */
8079 ret = str2prefix (ip_str, &match);
8080 if (! ret)
8081 {
8082 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8083 return CMD_WARNING;
8084 }
8085
8086 match.family = afi2family (afi);
8087
8088 if (use_json)
8089 {
8090 json = json_object_new_object();
8091 json_paths = json_object_new_array();
8092 }
8093
8094 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8095 {
8096 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8097 {
8098 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8099 continue;
8100
8101 if ((table = rn->info) != NULL)
8102 {
8103 header = 1;
8104
8105 if ((rm = bgp_node_match (table, &match)) != NULL)
8106 {
8107 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8108 {
8109 bgp_unlock_node (rm);
8110 continue;
8111 }
8112
8113 for (ri = rm->info; ri; ri = ri->next)
8114 {
8115 if (header)
8116 {
8117 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8118 AFI_IP, safi, json);
8119 header = 0;
8120 }
8121 display++;
8122
8123 if (pathtype == BGP_PATH_ALL ||
8124 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8125 (pathtype == BGP_PATH_MULTIPATH &&
8126 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8127 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8128 }
8129
8130 bgp_unlock_node (rm);
8131 }
8132 }
8133 }
8134 }
8135 else
8136 {
8137 header = 1;
8138
8139 if ((rn = bgp_node_match (rib, &match)) != NULL)
8140 {
8141 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8142 {
8143 for (ri = rn->info; ri; ri = ri->next)
8144 {
8145 if (header)
8146 {
8147 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8148 header = 0;
8149 }
8150 display++;
8151
8152 if (pathtype == BGP_PATH_ALL ||
8153 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8154 (pathtype == BGP_PATH_MULTIPATH &&
8155 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8156 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8157 }
8158 }
8159
8160 bgp_unlock_node (rn);
8161 }
8162 }
8163
8164 if (use_json)
8165 {
8166 if (display)
8167 json_object_object_add(json, "paths", json_paths);
8168
8169 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8170 json_object_free(json);
8171 }
8172 else
8173 {
8174 if (!display)
8175 {
8176 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8177 return CMD_WARNING;
8178 }
8179 }
8180
8181 return CMD_SUCCESS;
8182 }
8183
8184 /* Display specified route of Main RIB */
8185 static int
8186 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8187 afi_t afi, safi_t safi, struct prefix_rd *prd,
8188 int prefix_check, enum bgp_path_type pathtype,
8189 u_char use_json)
8190 {
8191 struct bgp *bgp;
8192
8193 /* BGP structure lookup. */
8194 if (view_name)
8195 {
8196 bgp = bgp_lookup_by_name (view_name);
8197 if (bgp == NULL)
8198 {
8199 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8200 return CMD_WARNING;
8201 }
8202 }
8203 else
8204 {
8205 bgp = bgp_get_default ();
8206 if (bgp == NULL)
8207 {
8208 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8209 return CMD_WARNING;
8210 }
8211 }
8212
8213 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8214 afi, safi, prd, prefix_check, pathtype,
8215 use_json);
8216 }
8217
8218 /* BGP route print out function. */
8219 DEFUN (show_ip_bgp,
8220 show_ip_bgp_cmd,
8221 "show ip bgp {json}",
8222 SHOW_STR
8223 IP_STR
8224 BGP_STR
8225 "JavaScript Object Notation\n")
8226 {
8227 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8228 }
8229
8230 DEFUN (show_ip_bgp_ipv4,
8231 show_ip_bgp_ipv4_cmd,
8232 "show ip bgp ipv4 (unicast|multicast) {json}",
8233 SHOW_STR
8234 IP_STR
8235 BGP_STR
8236 "Address family\n"
8237 "Address Family modifier\n"
8238 "Address Family modifier\n"
8239 "JavaScript Object Notation\n")
8240 {
8241 u_char uj = use_json(argc, argv);
8242
8243 if (strncmp (argv[0], "m", 1) == 0)
8244 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
8245 NULL, uj);
8246
8247 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8248 }
8249
8250 ALIAS (show_ip_bgp_ipv4,
8251 show_bgp_ipv4_safi_cmd,
8252 "show bgp ipv4 (unicast|multicast) {json}",
8253 SHOW_STR
8254 BGP_STR
8255 "Address family\n"
8256 "Address Family modifier\n"
8257 "Address Family modifier\n"
8258 "JavaScript Object Notation\n")
8259
8260 DEFUN (show_ip_bgp_route,
8261 show_ip_bgp_route_cmd,
8262 "show ip bgp A.B.C.D {json}",
8263 SHOW_STR
8264 IP_STR
8265 BGP_STR
8266 "Network in the BGP routing table to display\n"
8267 "JavaScript Object Notation\n")
8268 {
8269 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8270 }
8271
8272 DEFUN (show_ip_bgp_route_pathtype,
8273 show_ip_bgp_route_pathtype_cmd,
8274 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8275 SHOW_STR
8276 IP_STR
8277 BGP_STR
8278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8279 "Display only the bestpath\n"
8280 "Display only multipaths\n"
8281 "JavaScript Object Notation\n")
8282 {
8283 u_char uj = use_json(argc, argv);
8284
8285 if (strncmp (argv[1], "b", 1) == 0)
8286 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8287 else
8288 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8289 }
8290
8291 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8292 show_bgp_ipv4_safi_route_pathtype_cmd,
8293 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
8294 SHOW_STR
8295 BGP_STR
8296 "Address family\n"
8297 "Address Family modifier\n"
8298 "Address Family modifier\n"
8299 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8300 "Display only the bestpath\n"
8301 "Display only multipaths\n"
8302 "JavaScript Object Notation\n")
8303 {
8304 u_char uj = use_json(argc, argv);
8305
8306 if (strncmp (argv[0], "m", 1) == 0)
8307 if (strncmp (argv[2], "b", 1) == 0)
8308 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8309 else
8310 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8311 else
8312 if (strncmp (argv[2], "b", 1) == 0)
8313 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8314 else
8315 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8316 }
8317
8318 DEFUN (show_bgp_ipv4_prefix,
8319 show_bgp_ipv4_prefix_cmd,
8320 "show bgp ipv4 A.B.C.D/M {json}",
8321 SHOW_STR
8322 BGP_STR
8323 IP_STR
8324 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8325 JSON_STR)
8326 {
8327 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8328 }
8329
8330 DEFUN (show_bgp_ipv6_route,
8331 show_bgp_ipv6_route_cmd,
8332 "show bgp ipv6 X:X::X:X {json}",
8333 SHOW_STR
8334 BGP_STR
8335 "Address family\n"
8336 "Network in the BGP routing table to display\n"
8337 JSON_STR)
8338 {
8339 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8340 }
8341
8342 DEFUN (show_bgp_ipv6_prefix,
8343 show_bgp_ipv6_prefix_cmd,
8344 "show bgp ipv6 X:X::X:X/M {json}",
8345 SHOW_STR
8346 BGP_STR
8347 IP_STR
8348 "IPv6 prefix <network>/<length>\n"
8349 JSON_STR)
8350 {
8351 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8352 }
8353
8354 DEFUN (show_ip_bgp_ipv4_route,
8355 show_ip_bgp_ipv4_route_cmd,
8356 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8357 SHOW_STR
8358 IP_STR
8359 BGP_STR
8360 "Address family\n"
8361 "Address Family modifier\n"
8362 "Address Family modifier\n"
8363 "Network in the BGP routing table to display\n"
8364 "JavaScript Object Notation\n")
8365 {
8366 u_char uj = use_json(argc, argv);
8367
8368 if (strncmp (argv[0], "m", 1) == 0)
8369 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8370
8371 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8372 }
8373
8374 ALIAS (show_ip_bgp_ipv4_route,
8375 show_bgp_ipv4_safi_route_cmd,
8376 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8377 SHOW_STR
8378 BGP_STR
8379 "Address family\n"
8380 "Address Family modifier\n"
8381 "Address Family modifier\n"
8382 "Network in the BGP routing table to display\n"
8383 "JavaScript Object Notation\n")
8384
8385 DEFUN (show_ip_bgp_vpnv4_all_route,
8386 show_ip_bgp_vpnv4_all_route_cmd,
8387 "show ip bgp vpnv4 all A.B.C.D {json}",
8388 SHOW_STR
8389 IP_STR
8390 BGP_STR
8391 "Display VPNv4 NLRI specific information\n"
8392 "Display information about all VPNv4 NLRIs\n"
8393 "Network in the BGP routing table to display\n"
8394 "JavaScript Object Notation\n")
8395 {
8396 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8397 }
8398
8399 DEFUN (show_bgp_ipv4_vpn_route,
8400 show_bgp_ipv4_vpn_route_cmd,
8401 "show bgp ipv4 vpn A.B.C.D {json}",
8402 SHOW_STR
8403 BGP_STR
8404 "Address Family\n"
8405 "Display VPN NLRI specific information\n"
8406 "Network in the BGP routing table to display\n"
8407 JSON_STR)
8408 {
8409 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8410 }
8411
8412 DEFUN (show_bgp_ipv6_vpn_route,
8413 show_bgp_ipv6_vpn_route_cmd,
8414 "show bgp ipv6 vpn X:X::X:X {json}",
8415 SHOW_STR
8416 BGP_STR
8417 "Address Family\n"
8418 "Display VPN NLRI specific information\n"
8419 "Network in the BGP routing table to display\n"
8420 JSON_STR)
8421 {
8422 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8423 }
8424
8425 DEFUN (show_bgp_ipv4_vpn_rd_route,
8426 show_bgp_ipv4_vpn_rd_route_cmd,
8427 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8428 SHOW_STR
8429 BGP_STR
8430 IP_STR
8431 "Display VPN NLRI specific information\n"
8432 "Display information for a route distinguisher\n"
8433 "VPN Route Distinguisher\n"
8434 "Network in the BGP routing table to display\n"
8435 JSON_STR)
8436 {
8437 int ret;
8438 struct prefix_rd prd;
8439
8440 ret = str2prefix_rd (argv[0], &prd);
8441 if (! ret)
8442 {
8443 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8444 return CMD_WARNING;
8445 }
8446 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8447 }
8448
8449 DEFUN (show_bgp_ipv6_vpn_rd_route,
8450 show_bgp_ipv6_vpn_rd_route_cmd,
8451 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8452 SHOW_STR
8453 BGP_STR
8454 "Address Family\n"
8455 "Display VPN NLRI specific information\n"
8456 "Display information for a route distinguisher\n"
8457 "VPN Route Distinguisher\n"
8458 "Network in the BGP routing table to display\n"
8459 JSON_STR)
8460 {
8461 int ret;
8462 struct prefix_rd prd;
8463
8464 ret = str2prefix_rd (argv[0], &prd);
8465 if (! ret)
8466 {
8467 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8468 return CMD_WARNING;
8469 }
8470 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8471 }
8472
8473 DEFUN (show_ip_bgp_vpnv4_rd_route,
8474 show_ip_bgp_vpnv4_rd_route_cmd,
8475 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8476 SHOW_STR
8477 IP_STR
8478 BGP_STR
8479 "Display VPNv4 NLRI specific information\n"
8480 "Display information for a route distinguisher\n"
8481 "VPN Route Distinguisher\n"
8482 "Network in the BGP routing table to display\n"
8483 "JavaScript Object Notation\n")
8484 {
8485 int ret;
8486 struct prefix_rd prd;
8487 u_char uj= use_json(argc, argv);
8488
8489 ret = str2prefix_rd (argv[0], &prd);
8490 if (! ret)
8491 {
8492 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8493 return CMD_WARNING;
8494 }
8495 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
8496 }
8497
8498 DEFUN (show_ip_bgp_prefix,
8499 show_ip_bgp_prefix_cmd,
8500 "show ip bgp A.B.C.D/M {json}",
8501 SHOW_STR
8502 IP_STR
8503 BGP_STR
8504 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8505 "JavaScript Object Notation\n")
8506 {
8507 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8508 }
8509
8510 DEFUN (show_ip_bgp_prefix_pathtype,
8511 show_ip_bgp_prefix_pathtype_cmd,
8512 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8513 SHOW_STR
8514 IP_STR
8515 BGP_STR
8516 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8517 "Display only the bestpath\n"
8518 "Display only multipaths\n"
8519 "JavaScript Object Notation\n")
8520 {
8521 u_char uj = use_json(argc, argv);
8522 if (strncmp (argv[1], "b", 1) == 0)
8523 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8524 else
8525 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8526 }
8527
8528 DEFUN (show_ip_bgp_ipv4_prefix,
8529 show_ip_bgp_ipv4_prefix_cmd,
8530 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8531 SHOW_STR
8532 IP_STR
8533 BGP_STR
8534 "Address family\n"
8535 "Address Family modifier\n"
8536 "Address Family modifier\n"
8537 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8538 "JavaScript Object Notation\n")
8539 {
8540 u_char uj = use_json(argc, argv);
8541
8542 if (strncmp (argv[0], "m", 1) == 0)
8543 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8544
8545 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8546 }
8547
8548 ALIAS (show_ip_bgp_ipv4_prefix,
8549 show_bgp_ipv4_safi_prefix_cmd,
8550 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8551 SHOW_STR
8552 BGP_STR
8553 "Address family\n"
8554 "Address Family modifier\n"
8555 "Address Family modifier\n"
8556 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8557 "JavaScript Object Notation\n")
8558
8559 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8560 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8561 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8562 SHOW_STR
8563 IP_STR
8564 BGP_STR
8565 "Address family\n"
8566 "Address Family modifier\n"
8567 "Address Family modifier\n"
8568 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8569 "Display only the bestpath\n"
8570 "Display only multipaths\n"
8571 "JavaScript Object Notation\n")
8572 {
8573 u_char uj = use_json(argc, argv);
8574
8575 if (strncmp (argv[0], "m", 1) == 0)
8576 if (strncmp (argv[2], "b", 1) == 0)
8577 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8578 else
8579 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8580 else
8581 if (strncmp (argv[2], "b", 1) == 0)
8582 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8583 else
8584 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8585 }
8586
8587 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8588 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8589 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8590 SHOW_STR
8591 BGP_STR
8592 "Address family\n"
8593 "Address Family modifier\n"
8594 "Address Family modifier\n"
8595 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8596 "Display only the bestpath\n"
8597 "Display only multipaths\n"
8598 "JavaScript Object Notation\n")
8599
8600 DEFUN (show_ip_bgp_vpnv4_all_prefix,
8601 show_ip_bgp_vpnv4_all_prefix_cmd,
8602 "show ip bgp vpnv4 all A.B.C.D/M {json}",
8603 SHOW_STR
8604 IP_STR
8605 BGP_STR
8606 "Display VPNv4 NLRI specific information\n"
8607 "Display information about all VPNv4 NLRIs\n"
8608 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8609 "JavaScript Object Notation\n")
8610 {
8611 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8612 }
8613
8614 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8615 show_ip_bgp_vpnv4_rd_prefix_cmd,
8616 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8617 SHOW_STR
8618 IP_STR
8619 BGP_STR
8620 "Display VPNv4 NLRI specific information\n"
8621 "Display information for a route distinguisher\n"
8622 "VPN Route Distinguisher\n"
8623 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8624 "JavaScript Object Notation\n")
8625 {
8626 int ret;
8627 struct prefix_rd prd;
8628
8629 ret = str2prefix_rd (argv[0], &prd);
8630 if (! ret)
8631 {
8632 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8633 return CMD_WARNING;
8634 }
8635 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
8636 }
8637
8638 DEFUN (show_ip_bgp_view,
8639 show_ip_bgp_instance_cmd,
8640 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8641 SHOW_STR
8642 IP_STR
8643 BGP_STR
8644 BGP_INSTANCE_HELP_STR
8645 "JavaScript Object Notation\n")
8646 {
8647 struct bgp *bgp;
8648
8649 /* BGP structure lookup. */
8650 bgp = bgp_lookup_by_name (argv[1]);
8651 if (bgp == NULL)
8652 {
8653 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8654 return CMD_WARNING;
8655 }
8656
8657 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8658 }
8659
8660 DEFUN (show_ip_bgp_instance_all,
8661 show_ip_bgp_instance_all_cmd,
8662 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8663 SHOW_STR
8664 IP_STR
8665 BGP_STR
8666 BGP_INSTANCE_ALL_HELP_STR
8667 "JavaScript Object Notation\n")
8668 {
8669 u_char uj = use_json(argc, argv);
8670
8671 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8672 return CMD_SUCCESS;
8673 }
8674
8675 DEFUN (show_ip_bgp_instance_route,
8676 show_ip_bgp_instance_route_cmd,
8677 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 BGP_INSTANCE_HELP_STR
8682 "Network in the BGP routing table to display\n"
8683 "JavaScript Object Notation\n")
8684 {
8685 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8686 }
8687
8688 DEFUN (show_ip_bgp_instance_route_pathtype,
8689 show_ip_bgp_instance_route_pathtype_cmd,
8690 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8691 SHOW_STR
8692 IP_STR
8693 BGP_STR
8694 BGP_INSTANCE_HELP_STR
8695 "Network in the BGP routing table to display\n"
8696 "Display only the bestpath\n"
8697 "Display only multipaths\n"
8698 "JavaScript Object Notation\n")
8699 {
8700 u_char uj = use_json(argc, argv);
8701
8702 if (strncmp (argv[3], "b", 1) == 0)
8703 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8704 else
8705 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8706 }
8707
8708 DEFUN (show_ip_bgp_instance_prefix,
8709 show_ip_bgp_instance_prefix_cmd,
8710 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8711 SHOW_STR
8712 IP_STR
8713 BGP_STR
8714 BGP_INSTANCE_HELP_STR
8715 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8716 "JavaScript Object Notation\n")
8717 {
8718 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8719 }
8720
8721 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8722 show_ip_bgp_instance_prefix_pathtype_cmd,
8723 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8724 SHOW_STR
8725 IP_STR
8726 BGP_STR
8727 BGP_INSTANCE_HELP_STR
8728 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8729 "Display only the bestpath\n"
8730 "Display only multipaths\n"
8731 "JavaScript Object Notation\n")
8732 {
8733 u_char uj = use_json(argc, argv);
8734 if (strncmp (argv[3], "b", 1) == 0)
8735 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8736 else
8737 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8738 }
8739
8740 #ifdef HAVE_IPV6
8741 DEFUN (show_bgp,
8742 show_bgp_cmd,
8743 "show bgp {json}",
8744 SHOW_STR
8745 BGP_STR
8746 "JavaScript Object Notation\n")
8747 {
8748 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8749 NULL, use_json(argc, argv));
8750 }
8751
8752 ALIAS (show_bgp,
8753 show_bgp_ipv6_cmd,
8754 "show bgp ipv6 {json}",
8755 SHOW_STR
8756 BGP_STR
8757 "Address family\n"
8758 "JavaScript Object Notation\n")
8759
8760 DEFUN (show_bgp_ipv6_safi,
8761 show_bgp_ipv6_safi_cmd,
8762 "show bgp ipv6 (unicast|multicast) {json}",
8763 SHOW_STR
8764 BGP_STR
8765 "Address family\n"
8766 "Address Family modifier\n"
8767 "Address Family modifier\n"
8768 "JavaScript Object Notation\n")
8769 {
8770 u_char uj = use_json(argc, argv);
8771 if (strncmp (argv[0], "m", 1) == 0)
8772 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8773 NULL, uj);
8774
8775 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8776 }
8777
8778 static void
8779 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8780 {
8781 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8782 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8783 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8784 }
8785
8786 /* old command */
8787 DEFUN (show_ipv6_bgp,
8788 show_ipv6_bgp_cmd,
8789 "show ipv6 bgp {json}",
8790 SHOW_STR
8791 IP_STR
8792 BGP_STR
8793 "JavaScript Object Notation\n")
8794 {
8795 bgp_show_ipv6_bgp_deprecate_warning(vty);
8796 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8797 NULL, use_json(argc, argv));
8798 }
8799
8800 DEFUN (show_bgp_route,
8801 show_bgp_route_cmd,
8802 "show bgp X:X::X:X {json}",
8803 SHOW_STR
8804 BGP_STR
8805 "Network in the BGP routing table to display\n"
8806 "JavaScript Object Notation\n")
8807 {
8808 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8809 }
8810
8811 DEFUN (show_bgp_ipv6_safi_route,
8812 show_bgp_ipv6_safi_route_cmd,
8813 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8814 SHOW_STR
8815 BGP_STR
8816 "Address family\n"
8817 "Address Family modifier\n"
8818 "Address Family modifier\n"
8819 "Network in the BGP routing table to display\n"
8820 "JavaScript Object Notation\n")
8821 {
8822 u_char uj = use_json(argc, argv);
8823 if (strncmp (argv[0], "m", 1) == 0)
8824 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8825
8826 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8827 }
8828
8829 DEFUN (show_bgp_route_pathtype,
8830 show_bgp_route_pathtype_cmd,
8831 "show bgp X:X::X:X (bestpath|multipath) {json}",
8832 SHOW_STR
8833 BGP_STR
8834 "Network in the BGP routing table to display\n"
8835 "Display only the bestpath\n"
8836 "Display only multipaths\n"
8837 "JavaScript Object Notation\n")
8838 {
8839 u_char uj = use_json(argc, argv);
8840 if (strncmp (argv[1], "b", 1) == 0)
8841 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8842 else
8843 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8844 }
8845
8846 ALIAS (show_bgp_route_pathtype,
8847 show_bgp_ipv6_route_pathtype_cmd,
8848 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8849 SHOW_STR
8850 BGP_STR
8851 "Address family\n"
8852 "Network in the BGP routing table to display\n"
8853 "Display only the bestpath\n"
8854 "Display only multipaths\n"
8855 "JavaScript Object Notation\n")
8856
8857 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8858 show_bgp_ipv6_safi_route_pathtype_cmd,
8859 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8860 SHOW_STR
8861 BGP_STR
8862 "Address family\n"
8863 "Address Family modifier\n"
8864 "Address Family modifier\n"
8865 "Network in the BGP routing table to display\n"
8866 "Display only the bestpath\n"
8867 "Display only multipaths\n"
8868 "JavaScript Object Notation\n")
8869 {
8870 u_char uj = use_json(argc, argv);
8871 if (strncmp (argv[0], "m", 1) == 0)
8872 if (strncmp (argv[2], "b", 1) == 0)
8873 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8874 else
8875 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8876 else
8877 if (strncmp (argv[2], "b", 1) == 0)
8878 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8879 else
8880 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8881 }
8882
8883 /* old command */
8884 DEFUN (show_ipv6_bgp_route,
8885 show_ipv6_bgp_route_cmd,
8886 "show ipv6 bgp X:X::X:X {json}",
8887 SHOW_STR
8888 IP_STR
8889 BGP_STR
8890 "Network in the BGP routing table to display\n"
8891 "JavaScript Object Notation\n")
8892 {
8893 bgp_show_ipv6_bgp_deprecate_warning(vty);
8894 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8895 }
8896
8897 DEFUN (show_bgp_prefix,
8898 show_bgp_prefix_cmd,
8899 "show bgp X:X::X:X/M {json}",
8900 SHOW_STR
8901 BGP_STR
8902 "IPv6 prefix <network>/<length>\n"
8903 "JavaScript Object Notation\n")
8904 {
8905 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8906 }
8907
8908 DEFUN (show_bgp_ipv6_safi_prefix,
8909 show_bgp_ipv6_safi_prefix_cmd,
8910 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8911 SHOW_STR
8912 BGP_STR
8913 "Address family\n"
8914 "Address Family modifier\n"
8915 "Address Family modifier\n"
8916 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8917 "JavaScript Object Notation\n")
8918 {
8919 u_char uj = use_json(argc, argv);
8920 if (strncmp (argv[0], "m", 1) == 0)
8921 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8922
8923 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8924 }
8925
8926 DEFUN (show_bgp_prefix_pathtype,
8927 show_bgp_prefix_pathtype_cmd,
8928 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8929 SHOW_STR
8930 BGP_STR
8931 "IPv6 prefix <network>/<length>\n"
8932 "Display only the bestpath\n"
8933 "Display only multipaths\n"
8934 "JavaScript Object Notation\n")
8935 {
8936 u_char uj = use_json(argc, argv);
8937 if (strncmp (argv[1], "b", 1) == 0)
8938 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8939 else
8940 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8941 }
8942
8943 ALIAS (show_bgp_prefix_pathtype,
8944 show_bgp_ipv6_prefix_pathtype_cmd,
8945 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8946 SHOW_STR
8947 BGP_STR
8948 "Address family\n"
8949 "IPv6 prefix <network>/<length>\n"
8950 "Display only the bestpath\n"
8951 "Display only multipaths\n"
8952 "JavaScript Object Notation\n")
8953
8954 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8955 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8956 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8957 SHOW_STR
8958 BGP_STR
8959 "Address family\n"
8960 "Address Family modifier\n"
8961 "Address Family modifier\n"
8962 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8963 "Display only the bestpath\n"
8964 "Display only multipaths\n"
8965 "JavaScript Object Notation\n")
8966 {
8967 u_char uj = use_json(argc, argv);
8968 if (strncmp (argv[0], "m", 1) == 0)
8969 if (strncmp (argv[2], "b", 1) == 0)
8970 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8971 else
8972 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8973 else
8974 if (strncmp (argv[2], "b", 1) == 0)
8975 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8976 else
8977 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8978 }
8979
8980 /* old command */
8981 DEFUN (show_ipv6_bgp_prefix,
8982 show_ipv6_bgp_prefix_cmd,
8983 "show ipv6 bgp X:X::X:X/M {json}",
8984 SHOW_STR
8985 IP_STR
8986 BGP_STR
8987 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8988 "JavaScript Object Notation\n")
8989 {
8990 bgp_show_ipv6_bgp_deprecate_warning(vty);
8991 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8992 }
8993
8994 DEFUN (show_bgp_view,
8995 show_bgp_instance_cmd,
8996 "show bgp " BGP_INSTANCE_CMD " {json}",
8997 SHOW_STR
8998 BGP_STR
8999 BGP_INSTANCE_HELP_STR
9000 "JavaScript Object Notation\n")
9001 {
9002 struct bgp *bgp;
9003
9004 /* BGP structure lookup. */
9005 bgp = bgp_lookup_by_name (argv[1]);
9006 if (bgp == NULL)
9007 {
9008 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
9009 return CMD_WARNING;
9010 }
9011
9012 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
9013 }
9014
9015 DEFUN (show_bgp_instance_all,
9016 show_bgp_instance_all_cmd,
9017 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
9018 SHOW_STR
9019 BGP_STR
9020 BGP_INSTANCE_ALL_HELP_STR
9021 "JavaScript Object Notation\n")
9022 {
9023 u_char uj = use_json(argc, argv);
9024
9025 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
9026 return CMD_SUCCESS;
9027 }
9028
9029 ALIAS (show_bgp_view,
9030 show_bgp_instance_ipv6_cmd,
9031 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
9032 SHOW_STR
9033 BGP_STR
9034 BGP_INSTANCE_HELP_STR
9035 "Address family\n"
9036 "JavaScript Object Notation\n")
9037
9038 DEFUN (show_bgp_instance_route,
9039 show_bgp_instance_route_cmd,
9040 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
9041 SHOW_STR
9042 BGP_STR
9043 BGP_INSTANCE_HELP_STR
9044 "Network in the BGP routing table to display\n"
9045 "JavaScript Object Notation\n")
9046 {
9047 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9048 }
9049
9050 ALIAS (show_bgp_instance_route,
9051 show_bgp_instance_ipv6_route_cmd,
9052 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
9053 SHOW_STR
9054 BGP_STR
9055 BGP_INSTANCE_HELP_STR
9056 "Address family\n"
9057 "Network in the BGP routing table to display\n"
9058 "JavaScript Object Notation\n")
9059
9060 DEFUN (show_bgp_instance_route_pathtype,
9061 show_bgp_instance_route_pathtype_cmd,
9062 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
9063 SHOW_STR
9064 BGP_STR
9065 BGP_INSTANCE_HELP_STR
9066 "Network in the BGP routing table to display\n"
9067 "Display only the bestpath\n"
9068 "Display only multipaths\n"
9069 "JavaScript Object Notation\n")
9070 {
9071 u_char uj = use_json(argc, argv);
9072 if (strncmp (argv[3], "b", 1) == 0)
9073 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
9074 else
9075 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
9076 }
9077
9078 ALIAS (show_bgp_instance_route_pathtype,
9079 show_bgp_instance_ipv6_route_pathtype_cmd,
9080 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
9081 SHOW_STR
9082 BGP_STR
9083 BGP_INSTANCE_HELP_STR
9084 "Address family\n"
9085 "Network in the BGP routing table to display\n"
9086 "Display only the bestpath\n"
9087 "Display only multipaths\n"
9088 "JavaScript Object Notation\n")
9089
9090 DEFUN (show_bgp_instance_prefix,
9091 show_bgp_instance_prefix_cmd,
9092 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
9093 SHOW_STR
9094 BGP_STR
9095 BGP_INSTANCE_HELP_STR
9096 "IPv6 prefix <network>/<length>\n"
9097 "JavaScript Object Notation\n")
9098 {
9099 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9100 }
9101
9102 ALIAS (show_bgp_instance_prefix,
9103 show_bgp_instance_ipv6_prefix_cmd,
9104 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
9105 SHOW_STR
9106 BGP_STR
9107 BGP_INSTANCE_HELP_STR
9108 "Address family\n"
9109 "IPv6 prefix <network>/<length>\n"
9110 "JavaScript Object Notation\n")
9111
9112 DEFUN (show_bgp_instance_prefix_pathtype,
9113 show_bgp_instance_prefix_pathtype_cmd,
9114 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
9115 SHOW_STR
9116 BGP_STR
9117 BGP_INSTANCE_HELP_STR
9118 "IPv6 prefix <network>/<length>\n"
9119 "Display only the bestpath\n"
9120 "Display only multipaths\n"
9121 "JavaScript Object Notation\n")
9122 {
9123 u_char uj = use_json(argc, argv);
9124 if (strncmp (argv[3], "b", 1) == 0)
9125 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9126 else
9127 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9128 }
9129
9130 ALIAS (show_bgp_instance_prefix_pathtype,
9131 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9132 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
9133 SHOW_STR
9134 BGP_STR
9135 BGP_INSTANCE_HELP_STR
9136 "Address family\n"
9137 "IPv6 prefix <network>/<length>\n"
9138 "Display only the bestpath\n"
9139 "Display only multipaths\n"
9140 "JavaScript Object Notation\n")
9141
9142 DEFUN (show_bgp_instance_prefix_list,
9143 show_bgp_instance_prefix_list_cmd,
9144 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9145 SHOW_STR
9146 BGP_STR
9147 BGP_INSTANCE_HELP_STR
9148 "Display routes conforming to the prefix-list\n"
9149 "IPv6 prefix-list name\n")
9150 {
9151 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9152 bgp_show_type_prefix_list);
9153 }
9154
9155 ALIAS (show_bgp_instance_prefix_list,
9156 show_bgp_instance_ipv6_prefix_list_cmd,
9157 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9158 SHOW_STR
9159 BGP_STR
9160 BGP_INSTANCE_HELP_STR
9161 "Address family\n"
9162 "Display routes conforming to the prefix-list\n"
9163 "IPv6 prefix-list name\n")
9164
9165 DEFUN (show_bgp_instance_filter_list,
9166 show_bgp_instance_filter_list_cmd,
9167 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9168 SHOW_STR
9169 BGP_STR
9170 BGP_INSTANCE_HELP_STR
9171 "Display routes conforming to the filter-list\n"
9172 "Regular expression access list name\n")
9173 {
9174 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9175 bgp_show_type_filter_list);
9176 }
9177
9178 ALIAS (show_bgp_instance_filter_list,
9179 show_bgp_instance_ipv6_filter_list_cmd,
9180 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9181 SHOW_STR
9182 BGP_STR
9183 BGP_INSTANCE_HELP_STR
9184 "Address family\n"
9185 "Display routes conforming to the filter-list\n"
9186 "Regular expression access list name\n")
9187
9188 DEFUN (show_bgp_instance_route_map,
9189 show_bgp_instance_route_map_cmd,
9190 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9191 SHOW_STR
9192 BGP_STR
9193 BGP_INSTANCE_HELP_STR
9194 "Display routes matching the route-map\n"
9195 "A route-map to match on\n")
9196 {
9197 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9198 bgp_show_type_route_map);
9199 }
9200
9201 ALIAS (show_bgp_instance_route_map,
9202 show_bgp_instance_ipv6_route_map_cmd,
9203 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9204 SHOW_STR
9205 BGP_STR
9206 BGP_INSTANCE_HELP_STR
9207 "Address family\n"
9208 "Display routes matching the route-map\n"
9209 "A route-map to match on\n")
9210
9211 DEFUN (show_bgp_instance_community_list,
9212 show_bgp_instance_community_list_cmd,
9213 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9214 SHOW_STR
9215 BGP_STR
9216 BGP_INSTANCE_HELP_STR
9217 "Display routes matching the community-list\n"
9218 "community-list number\n"
9219 "community-list name\n")
9220 {
9221 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9222 }
9223
9224 ALIAS (show_bgp_instance_community_list,
9225 show_bgp_instance_ipv6_community_list_cmd,
9226 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9227 SHOW_STR
9228 BGP_STR
9229 BGP_INSTANCE_HELP_STR
9230 "Address family\n"
9231 "Display routes matching the community-list\n"
9232 "community-list number\n"
9233 "community-list name\n")
9234
9235 DEFUN (show_bgp_instance_prefix_longer,
9236 show_bgp_instance_prefix_longer_cmd,
9237 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9238 SHOW_STR
9239 BGP_STR
9240 BGP_INSTANCE_HELP_STR
9241 "IPv6 prefix <network>/<length>\n"
9242 "Display route and more specific routes\n")
9243 {
9244 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9245 bgp_show_type_prefix_longer);
9246 }
9247
9248 ALIAS (show_bgp_instance_prefix_longer,
9249 show_bgp_instance_ipv6_prefix_longer_cmd,
9250 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9251 SHOW_STR
9252 BGP_STR
9253 BGP_INSTANCE_HELP_STR
9254 "Address family\n"
9255 "IPv6 prefix <network>/<length>\n"
9256 "Display route and more specific routes\n")
9257
9258 /* old command */
9259 DEFUN (show_ipv6_mbgp,
9260 show_ipv6_mbgp_cmd,
9261 "show ipv6 mbgp {json}",
9262 SHOW_STR
9263 IP_STR
9264 MBGP_STR
9265 "JavaScript Object Notation\n")
9266 {
9267 bgp_show_ipv6_bgp_deprecate_warning(vty);
9268 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9269 NULL, use_json(argc, argv));
9270 }
9271
9272 /* old command */
9273 DEFUN (show_ipv6_mbgp_route,
9274 show_ipv6_mbgp_route_cmd,
9275 "show ipv6 mbgp X:X::X:X {json}",
9276 SHOW_STR
9277 IP_STR
9278 MBGP_STR
9279 "Network in the MBGP routing table to display\n"
9280 "JavaScript Object Notation\n")
9281 {
9282 bgp_show_ipv6_bgp_deprecate_warning(vty);
9283 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9284 }
9285
9286 /* old command */
9287 DEFUN (show_ipv6_mbgp_prefix,
9288 show_ipv6_mbgp_prefix_cmd,
9289 "show ipv6 mbgp X:X::X:X/M {json}",
9290 SHOW_STR
9291 IP_STR
9292 MBGP_STR
9293 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9294 "JavaScript Object Notation\n")
9295 {
9296 bgp_show_ipv6_bgp_deprecate_warning(vty);
9297 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9298 }
9299 #endif
9300
9301
9302 static int
9303 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9304 safi_t safi, enum bgp_show_type type)
9305 {
9306 int i;
9307 struct buffer *b;
9308 char *regstr;
9309 int first;
9310 regex_t *regex;
9311 int rc;
9312
9313 first = 0;
9314 b = buffer_new (1024);
9315 for (i = 0; i < argc; i++)
9316 {
9317 if (first)
9318 buffer_putc (b, ' ');
9319 else
9320 {
9321 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9322 continue;
9323 first = 1;
9324 }
9325
9326 buffer_putstr (b, argv[i]);
9327 }
9328 buffer_putc (b, '\0');
9329
9330 regstr = buffer_getstr (b);
9331 buffer_free (b);
9332
9333 regex = bgp_regcomp (regstr);
9334 XFREE(MTYPE_TMP, regstr);
9335 if (! regex)
9336 {
9337 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9338 VTY_NEWLINE);
9339 return CMD_WARNING;
9340 }
9341
9342 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9343 bgp_regex_free (regex);
9344 return rc;
9345 }
9346
9347 DEFUN (show_ip_bgp_regexp,
9348 show_ip_bgp_regexp_cmd,
9349 "show ip bgp regexp .LINE",
9350 SHOW_STR
9351 IP_STR
9352 BGP_STR
9353 "Display routes matching the AS path regular expression\n"
9354 "A regular-expression to match the BGP AS paths\n")
9355 {
9356 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9357 bgp_show_type_regexp);
9358 }
9359
9360 DEFUN (show_ip_bgp_flap_regexp,
9361 show_ip_bgp_flap_regexp_cmd,
9362 "show ip bgp flap-statistics regexp .LINE",
9363 SHOW_STR
9364 IP_STR
9365 BGP_STR
9366 "Display flap statistics of routes\n"
9367 "Display routes matching the AS path regular expression\n"
9368 "A regular-expression to match the BGP AS paths\n")
9369 {
9370 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9371 bgp_show_type_flap_regexp);
9372 }
9373
9374 ALIAS (show_ip_bgp_flap_regexp,
9375 show_ip_bgp_damp_flap_regexp_cmd,
9376 "show ip bgp dampening flap-statistics regexp .LINE",
9377 SHOW_STR
9378 IP_STR
9379 BGP_STR
9380 "Display detailed information about dampening\n"
9381 "Display flap statistics of routes\n"
9382 "Display routes matching the AS path regular expression\n"
9383 "A regular-expression to match the BGP AS paths\n")
9384
9385 DEFUN (show_ip_bgp_ipv4_regexp,
9386 show_ip_bgp_ipv4_regexp_cmd,
9387 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9388 SHOW_STR
9389 IP_STR
9390 BGP_STR
9391 "Address family\n"
9392 "Address Family modifier\n"
9393 "Address Family modifier\n"
9394 "Display routes matching the AS path regular expression\n"
9395 "A regular-expression to match the BGP AS paths\n")
9396 {
9397 if (strncmp (argv[0], "m", 1) == 0)
9398 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9399 bgp_show_type_regexp);
9400
9401 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9402 bgp_show_type_regexp);
9403 }
9404
9405 #ifdef HAVE_IPV6
9406 DEFUN (show_bgp_regexp,
9407 show_bgp_regexp_cmd,
9408 "show bgp regexp .LINE",
9409 SHOW_STR
9410 BGP_STR
9411 "Display routes matching the AS path regular expression\n"
9412 "A regular-expression to match the BGP AS paths\n")
9413 {
9414 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9415 bgp_show_type_regexp);
9416 }
9417
9418 ALIAS (show_bgp_regexp,
9419 show_bgp_ipv6_regexp_cmd,
9420 "show bgp ipv6 regexp .LINE",
9421 SHOW_STR
9422 BGP_STR
9423 "Address family\n"
9424 "Display routes matching the AS path regular expression\n"
9425 "A regular-expression to match the BGP AS paths\n")
9426
9427 /* old command */
9428 DEFUN (show_ipv6_bgp_regexp,
9429 show_ipv6_bgp_regexp_cmd,
9430 "show ipv6 bgp regexp .LINE",
9431 SHOW_STR
9432 IP_STR
9433 BGP_STR
9434 "Display routes matching the AS path regular expression\n"
9435 "A regular-expression to match the BGP AS paths\n")
9436 {
9437 bgp_show_ipv6_bgp_deprecate_warning(vty);
9438 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9439 bgp_show_type_regexp);
9440 }
9441
9442 /* old command */
9443 DEFUN (show_ipv6_mbgp_regexp,
9444 show_ipv6_mbgp_regexp_cmd,
9445 "show ipv6 mbgp regexp .LINE",
9446 SHOW_STR
9447 IP_STR
9448 BGP_STR
9449 "Display routes matching the AS path regular expression\n"
9450 "A regular-expression to match the MBGP AS paths\n")
9451 {
9452 bgp_show_ipv6_bgp_deprecate_warning(vty);
9453 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9454 bgp_show_type_regexp);
9455 }
9456 #endif /* HAVE_IPV6 */
9457
9458 static int
9459 bgp_show_prefix_list (struct vty *vty, const char *name,
9460 const char *prefix_list_str, afi_t afi,
9461 safi_t safi, enum bgp_show_type type)
9462 {
9463 struct prefix_list *plist;
9464 struct bgp *bgp = NULL;
9465
9466 if (name && !(bgp = bgp_lookup_by_name(name)))
9467 {
9468 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9469 return CMD_WARNING;
9470 }
9471
9472 plist = prefix_list_lookup (afi, prefix_list_str);
9473 if (plist == NULL)
9474 {
9475 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9476 prefix_list_str, VTY_NEWLINE);
9477 return CMD_WARNING;
9478 }
9479
9480 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9481 }
9482
9483 DEFUN (show_ip_bgp_prefix_list,
9484 show_ip_bgp_prefix_list_cmd,
9485 "show ip bgp prefix-list WORD",
9486 SHOW_STR
9487 IP_STR
9488 BGP_STR
9489 "Display routes conforming to the prefix-list\n"
9490 "IP prefix-list name\n")
9491 {
9492 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9493 bgp_show_type_prefix_list);
9494 }
9495
9496 DEFUN (show_ip_bgp_instance_prefix_list,
9497 show_ip_bgp_instance_prefix_list_cmd,
9498 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9499 SHOW_STR
9500 IP_STR
9501 BGP_STR
9502 BGP_INSTANCE_HELP_STR
9503 "Display routes conforming to the prefix-list\n"
9504 "IP prefix-list name\n")
9505 {
9506 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9507 bgp_show_type_prefix_list);
9508 }
9509
9510 DEFUN (show_ip_bgp_flap_prefix_list,
9511 show_ip_bgp_flap_prefix_list_cmd,
9512 "show ip bgp flap-statistics prefix-list WORD",
9513 SHOW_STR
9514 IP_STR
9515 BGP_STR
9516 "Display flap statistics of routes\n"
9517 "Display routes conforming to the prefix-list\n"
9518 "IP prefix-list name\n")
9519 {
9520 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9521 bgp_show_type_flap_prefix_list);
9522 }
9523
9524 ALIAS (show_ip_bgp_flap_prefix_list,
9525 show_ip_bgp_damp_flap_prefix_list_cmd,
9526 "show ip bgp dampening flap-statistics prefix-list WORD",
9527 SHOW_STR
9528 IP_STR
9529 BGP_STR
9530 "Display detailed information about dampening\n"
9531 "Display flap statistics of routes\n"
9532 "Display routes conforming to the prefix-list\n"
9533 "IP prefix-list name\n")
9534
9535 DEFUN (show_ip_bgp_ipv4_prefix_list,
9536 show_ip_bgp_ipv4_prefix_list_cmd,
9537 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9538 SHOW_STR
9539 IP_STR
9540 BGP_STR
9541 "Address family\n"
9542 "Address Family modifier\n"
9543 "Address Family modifier\n"
9544 "Display routes conforming to the prefix-list\n"
9545 "IP prefix-list name\n")
9546 {
9547 if (strncmp (argv[0], "m", 1) == 0)
9548 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9549 bgp_show_type_prefix_list);
9550
9551 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9552 bgp_show_type_prefix_list);
9553 }
9554
9555 #ifdef HAVE_IPV6
9556 DEFUN (show_bgp_prefix_list,
9557 show_bgp_prefix_list_cmd,
9558 "show bgp prefix-list WORD",
9559 SHOW_STR
9560 BGP_STR
9561 "Display routes conforming to the prefix-list\n"
9562 "IPv6 prefix-list name\n")
9563 {
9564 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9565 bgp_show_type_prefix_list);
9566 }
9567
9568 ALIAS (show_bgp_prefix_list,
9569 show_bgp_ipv6_prefix_list_cmd,
9570 "show bgp ipv6 prefix-list WORD",
9571 SHOW_STR
9572 BGP_STR
9573 "Address family\n"
9574 "Display routes conforming to the prefix-list\n"
9575 "IPv6 prefix-list name\n")
9576
9577 /* old command */
9578 DEFUN (show_ipv6_bgp_prefix_list,
9579 show_ipv6_bgp_prefix_list_cmd,
9580 "show ipv6 bgp prefix-list WORD",
9581 SHOW_STR
9582 IPV6_STR
9583 BGP_STR
9584 "Display routes matching the prefix-list\n"
9585 "IPv6 prefix-list name\n")
9586 {
9587 bgp_show_ipv6_bgp_deprecate_warning(vty);
9588 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9589 bgp_show_type_prefix_list);
9590 }
9591
9592 /* old command */
9593 DEFUN (show_ipv6_mbgp_prefix_list,
9594 show_ipv6_mbgp_prefix_list_cmd,
9595 "show ipv6 mbgp prefix-list WORD",
9596 SHOW_STR
9597 IPV6_STR
9598 MBGP_STR
9599 "Display routes matching the prefix-list\n"
9600 "IPv6 prefix-list name\n")
9601 {
9602 bgp_show_ipv6_bgp_deprecate_warning(vty);
9603 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9604 bgp_show_type_prefix_list);
9605 }
9606 #endif /* HAVE_IPV6 */
9607
9608 static int
9609 bgp_show_filter_list (struct vty *vty, const char *name,
9610 const char *filter, afi_t afi,
9611 safi_t safi, enum bgp_show_type type)
9612 {
9613 struct as_list *as_list;
9614 struct bgp *bgp = NULL;
9615
9616 if (name && !(bgp = bgp_lookup_by_name(name)))
9617 {
9618 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9619 return CMD_WARNING;
9620 }
9621
9622 as_list = as_list_lookup (filter);
9623 if (as_list == NULL)
9624 {
9625 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9626 return CMD_WARNING;
9627 }
9628
9629 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9630 }
9631
9632 DEFUN (show_ip_bgp_filter_list,
9633 show_ip_bgp_filter_list_cmd,
9634 "show ip bgp filter-list WORD",
9635 SHOW_STR
9636 IP_STR
9637 BGP_STR
9638 "Display routes conforming to the filter-list\n"
9639 "Regular expression access list name\n")
9640 {
9641 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9642 bgp_show_type_filter_list);
9643 }
9644
9645 DEFUN (show_ip_bgp_instance_filter_list,
9646 show_ip_bgp_instance_filter_list_cmd,
9647 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9648 SHOW_STR
9649 IP_STR
9650 BGP_STR
9651 BGP_INSTANCE_HELP_STR
9652 "Display routes conforming to the filter-list\n"
9653 "Regular expression access list name\n")
9654 {
9655 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9656 bgp_show_type_filter_list);
9657 }
9658
9659 DEFUN (show_ip_bgp_flap_filter_list,
9660 show_ip_bgp_flap_filter_list_cmd,
9661 "show ip bgp flap-statistics filter-list WORD",
9662 SHOW_STR
9663 IP_STR
9664 BGP_STR
9665 "Display flap statistics of routes\n"
9666 "Display routes conforming to the filter-list\n"
9667 "Regular expression access list name\n")
9668 {
9669 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9670 bgp_show_type_flap_filter_list);
9671 }
9672
9673 ALIAS (show_ip_bgp_flap_filter_list,
9674 show_ip_bgp_damp_flap_filter_list_cmd,
9675 "show ip bgp dampening flap-statistics filter-list WORD",
9676 SHOW_STR
9677 IP_STR
9678 BGP_STR
9679 "Display detailed information about dampening\n"
9680 "Display flap statistics of routes\n"
9681 "Display routes conforming to the filter-list\n"
9682 "Regular expression access list name\n")
9683
9684 DEFUN (show_ip_bgp_ipv4_filter_list,
9685 show_ip_bgp_ipv4_filter_list_cmd,
9686 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9687 SHOW_STR
9688 IP_STR
9689 BGP_STR
9690 "Address family\n"
9691 "Address Family modifier\n"
9692 "Address Family modifier\n"
9693 "Display routes conforming to the filter-list\n"
9694 "Regular expression access list name\n")
9695 {
9696 if (strncmp (argv[0], "m", 1) == 0)
9697 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9698 bgp_show_type_filter_list);
9699
9700 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9701 bgp_show_type_filter_list);
9702 }
9703
9704 #ifdef HAVE_IPV6
9705 DEFUN (show_bgp_filter_list,
9706 show_bgp_filter_list_cmd,
9707 "show bgp filter-list WORD",
9708 SHOW_STR
9709 BGP_STR
9710 "Display routes conforming to the filter-list\n"
9711 "Regular expression access list name\n")
9712 {
9713 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9714 bgp_show_type_filter_list);
9715 }
9716
9717 ALIAS (show_bgp_filter_list,
9718 show_bgp_ipv6_filter_list_cmd,
9719 "show bgp ipv6 filter-list WORD",
9720 SHOW_STR
9721 BGP_STR
9722 "Address family\n"
9723 "Display routes conforming to the filter-list\n"
9724 "Regular expression access list name\n")
9725
9726 /* old command */
9727 DEFUN (show_ipv6_bgp_filter_list,
9728 show_ipv6_bgp_filter_list_cmd,
9729 "show ipv6 bgp filter-list WORD",
9730 SHOW_STR
9731 IPV6_STR
9732 BGP_STR
9733 "Display routes conforming to the filter-list\n"
9734 "Regular expression access list name\n")
9735 {
9736 bgp_show_ipv6_bgp_deprecate_warning(vty);
9737 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9738 bgp_show_type_filter_list);
9739 }
9740
9741 /* old command */
9742 DEFUN (show_ipv6_mbgp_filter_list,
9743 show_ipv6_mbgp_filter_list_cmd,
9744 "show ipv6 mbgp filter-list WORD",
9745 SHOW_STR
9746 IPV6_STR
9747 MBGP_STR
9748 "Display routes conforming to the filter-list\n"
9749 "Regular expression access list name\n")
9750 {
9751 bgp_show_ipv6_bgp_deprecate_warning(vty);
9752 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9753 bgp_show_type_filter_list);
9754 }
9755 #endif /* HAVE_IPV6 */
9756
9757 DEFUN (show_ip_bgp_dampening_info,
9758 show_ip_bgp_dampening_params_cmd,
9759 "show ip bgp dampening parameters",
9760 SHOW_STR
9761 IP_STR
9762 BGP_STR
9763 "Display detailed information about dampening\n"
9764 "Display detail of configured dampening parameters\n")
9765 {
9766 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9767 }
9768
9769
9770 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9771 show_ip_bgp_ipv4_dampening_parameters_cmd,
9772 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
9773 SHOW_STR
9774 IP_STR
9775 BGP_STR
9776 "Address family\n"
9777 "Address Family modifier\n"
9778 "Address Family modifier\n"
9779 "Display detailed information about dampening\n"
9780 "Display detail of configured dampening parameters\n")
9781 {
9782 if (strncmp(argv[0], "m", 1) == 0)
9783 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
9784
9785 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9786 }
9787
9788
9789 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9790 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9791 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
9792 SHOW_STR
9793 IP_STR
9794 BGP_STR
9795 "Address family\n"
9796 "Address Family modifier\n"
9797 "Address Family modifier\n"
9798 "Display detailed information about dampening\n"
9799 "Display flap statistics of routes\n")
9800 {
9801 if (strncmp(argv[0], "m", 1) == 0)
9802 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9803 bgp_show_type_flap_statistics, NULL, 0);
9804
9805 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9806 bgp_show_type_flap_statistics, NULL, 0);
9807 }
9808
9809 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9810 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9811 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
9812 SHOW_STR
9813 IP_STR
9814 BGP_STR
9815 "Address family\n"
9816 "Address Family modifier\n"
9817 "Address Family modifier\n"
9818 "Display detailed information about dampening\n"
9819 "Display paths suppressed due to dampening\n")
9820 {
9821 if (strncmp(argv[0], "m", 1) == 0)
9822 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9823 bgp_show_type_dampend_paths, NULL, 0);
9824
9825 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9826 bgp_show_type_dampend_paths, NULL, 0);
9827 }
9828
9829 static int
9830 bgp_show_route_map (struct vty *vty, const char *name,
9831 const char *rmap_str, afi_t afi,
9832 safi_t safi, enum bgp_show_type type)
9833 {
9834 struct route_map *rmap;
9835 struct bgp *bgp = NULL;
9836
9837 if (name && !(bgp = bgp_lookup_by_name(name)))
9838 {
9839 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9840 return CMD_WARNING;
9841 }
9842
9843 rmap = route_map_lookup_by_name (rmap_str);
9844 if (! rmap)
9845 {
9846 vty_out (vty, "%% %s is not a valid route-map name%s",
9847 rmap_str, VTY_NEWLINE);
9848 return CMD_WARNING;
9849 }
9850
9851 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9852 }
9853
9854 DEFUN (show_ip_bgp_route_map,
9855 show_ip_bgp_route_map_cmd,
9856 "show ip bgp route-map WORD",
9857 SHOW_STR
9858 IP_STR
9859 BGP_STR
9860 "Display routes matching the route-map\n"
9861 "A route-map to match on\n")
9862 {
9863 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9864 bgp_show_type_route_map);
9865 }
9866
9867 DEFUN (show_ip_bgp_instance_route_map,
9868 show_ip_bgp_instance_route_map_cmd,
9869 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9870 SHOW_STR
9871 IP_STR
9872 BGP_STR
9873 BGP_INSTANCE_HELP_STR
9874 "Display routes matching the route-map\n"
9875 "A route-map to match on\n")
9876 {
9877 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9878 bgp_show_type_route_map);
9879 }
9880
9881 DEFUN (show_ip_bgp_flap_route_map,
9882 show_ip_bgp_flap_route_map_cmd,
9883 "show ip bgp flap-statistics route-map WORD",
9884 SHOW_STR
9885 IP_STR
9886 BGP_STR
9887 "Display flap statistics of routes\n"
9888 "Display routes matching the route-map\n"
9889 "A route-map to match on\n")
9890 {
9891 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9892 bgp_show_type_flap_route_map);
9893 }
9894
9895 ALIAS (show_ip_bgp_flap_route_map,
9896 show_ip_bgp_damp_flap_route_map_cmd,
9897 "show ip bgp dampening flap-statistics route-map WORD",
9898 SHOW_STR
9899 IP_STR
9900 BGP_STR
9901 "Display detailed information about dampening\n"
9902 "Display flap statistics of routes\n"
9903 "Display routes matching the route-map\n"
9904 "A route-map to match on\n")
9905
9906 DEFUN (show_ip_bgp_ipv4_route_map,
9907 show_ip_bgp_ipv4_route_map_cmd,
9908 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9909 SHOW_STR
9910 IP_STR
9911 BGP_STR
9912 "Address family\n"
9913 "Address Family modifier\n"
9914 "Address Family modifier\n"
9915 "Display routes matching the route-map\n"
9916 "A route-map to match on\n")
9917 {
9918 if (strncmp (argv[0], "m", 1) == 0)
9919 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9920 bgp_show_type_route_map);
9921
9922 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9923 bgp_show_type_route_map);
9924 }
9925
9926 DEFUN (show_bgp_route_map,
9927 show_bgp_route_map_cmd,
9928 "show bgp route-map WORD",
9929 SHOW_STR
9930 BGP_STR
9931 "Display routes matching the route-map\n"
9932 "A route-map to match on\n")
9933 {
9934 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9935 bgp_show_type_route_map);
9936 }
9937
9938 ALIAS (show_bgp_route_map,
9939 show_bgp_ipv6_route_map_cmd,
9940 "show bgp ipv6 route-map WORD",
9941 SHOW_STR
9942 BGP_STR
9943 "Address family\n"
9944 "Display routes matching the route-map\n"
9945 "A route-map to match on\n")
9946
9947 DEFUN (show_ip_bgp_cidr_only,
9948 show_ip_bgp_cidr_only_cmd,
9949 "show ip bgp cidr-only",
9950 SHOW_STR
9951 IP_STR
9952 BGP_STR
9953 "Display only routes with non-natural netmasks\n")
9954 {
9955 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9956 bgp_show_type_cidr_only, NULL, 0);
9957 }
9958
9959 DEFUN (show_ip_bgp_flap_cidr_only,
9960 show_ip_bgp_flap_cidr_only_cmd,
9961 "show ip bgp flap-statistics cidr-only",
9962 SHOW_STR
9963 IP_STR
9964 BGP_STR
9965 "Display flap statistics of routes\n"
9966 "Display only routes with non-natural netmasks\n")
9967 {
9968 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9969 bgp_show_type_flap_cidr_only, NULL, 0);
9970 }
9971
9972 ALIAS (show_ip_bgp_flap_cidr_only,
9973 show_ip_bgp_damp_flap_cidr_only_cmd,
9974 "show ip bgp dampening flap-statistics cidr-only",
9975 SHOW_STR
9976 IP_STR
9977 BGP_STR
9978 "Display detailed information about dampening\n"
9979 "Display flap statistics of routes\n"
9980 "Display only routes with non-natural netmasks\n")
9981
9982 DEFUN (show_ip_bgp_ipv4_cidr_only,
9983 show_ip_bgp_ipv4_cidr_only_cmd,
9984 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9985 SHOW_STR
9986 IP_STR
9987 BGP_STR
9988 "Address family\n"
9989 "Address Family modifier\n"
9990 "Address Family modifier\n"
9991 "Display only routes with non-natural netmasks\n")
9992 {
9993 if (strncmp (argv[0], "m", 1) == 0)
9994 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9995 bgp_show_type_cidr_only, NULL, 0);
9996
9997 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9998 bgp_show_type_cidr_only, NULL, 0);
9999 }
10000
10001 DEFUN (show_ip_bgp_community_all,
10002 show_ip_bgp_community_all_cmd,
10003 "show ip bgp community",
10004 SHOW_STR
10005 IP_STR
10006 BGP_STR
10007 "Display routes matching the communities\n")
10008 {
10009 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10010 bgp_show_type_community_all, NULL, 0);
10011 }
10012
10013 DEFUN (show_ip_bgp_ipv4_community_all,
10014 show_ip_bgp_ipv4_community_all_cmd,
10015 "show ip bgp ipv4 (unicast|multicast) community",
10016 SHOW_STR
10017 IP_STR
10018 BGP_STR
10019 "Address family\n"
10020 "Address Family modifier\n"
10021 "Address Family modifier\n"
10022 "Display routes matching the communities\n")
10023 {
10024 if (strncmp (argv[0], "m", 1) == 0)
10025 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
10026 bgp_show_type_community_all, NULL, 0);
10027
10028 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10029 bgp_show_type_community_all, NULL, 0);
10030 }
10031
10032 #ifdef HAVE_IPV6
10033 DEFUN (show_bgp_community_all,
10034 show_bgp_community_all_cmd,
10035 "show bgp community",
10036 SHOW_STR
10037 BGP_STR
10038 "Display routes matching the communities\n")
10039 {
10040 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
10041 bgp_show_type_community_all, NULL, 0);
10042 }
10043
10044 ALIAS (show_bgp_community_all,
10045 show_bgp_ipv6_community_all_cmd,
10046 "show bgp ipv6 community",
10047 SHOW_STR
10048 BGP_STR
10049 "Address family\n"
10050 "Display routes matching the communities\n")
10051
10052 /* old command */
10053 DEFUN (show_ipv6_bgp_community_all,
10054 show_ipv6_bgp_community_all_cmd,
10055 "show ipv6 bgp community",
10056 SHOW_STR
10057 IPV6_STR
10058 BGP_STR
10059 "Display routes matching the communities\n")
10060 {
10061 bgp_show_ipv6_bgp_deprecate_warning(vty);
10062 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
10063 bgp_show_type_community_all, NULL, 0);
10064 }
10065
10066 /* old command */
10067 DEFUN (show_ipv6_mbgp_community_all,
10068 show_ipv6_mbgp_community_all_cmd,
10069 "show ipv6 mbgp community",
10070 SHOW_STR
10071 IPV6_STR
10072 MBGP_STR
10073 "Display routes matching the communities\n")
10074 {
10075 bgp_show_ipv6_bgp_deprecate_warning(vty);
10076 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
10077 bgp_show_type_community_all, NULL, 0);
10078 }
10079 #endif /* HAVE_IPV6 */
10080
10081 static int
10082 bgp_show_community (struct vty *vty, const char *view_name, int argc,
10083 const char **argv, int exact, afi_t afi, safi_t safi)
10084 {
10085 struct community *com;
10086 struct buffer *b;
10087 struct bgp *bgp;
10088 int i;
10089 char *str;
10090 int first = 0;
10091
10092 /* BGP structure lookup */
10093 if (view_name)
10094 {
10095 bgp = bgp_lookup_by_name (view_name);
10096 if (bgp == NULL)
10097 {
10098 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
10099 return CMD_WARNING;
10100 }
10101 }
10102 else
10103 {
10104 bgp = bgp_get_default ();
10105 if (bgp == NULL)
10106 {
10107 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10108 return CMD_WARNING;
10109 }
10110 }
10111
10112 b = buffer_new (1024);
10113 for (i = 0; i < argc; i++)
10114 {
10115 if (first)
10116 buffer_putc (b, ' ');
10117 else
10118 {
10119 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10120 continue;
10121 first = 1;
10122 }
10123
10124 buffer_putstr (b, argv[i]);
10125 }
10126 buffer_putc (b, '\0');
10127
10128 str = buffer_getstr (b);
10129 buffer_free (b);
10130
10131 com = community_str2com (str);
10132 XFREE (MTYPE_TMP, str);
10133 if (! com)
10134 {
10135 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10136 return CMD_WARNING;
10137 }
10138
10139 return bgp_show (vty, bgp, afi, safi,
10140 (exact ? bgp_show_type_community_exact :
10141 bgp_show_type_community), com, 0);
10142 }
10143
10144 DEFUN (show_ip_bgp_community,
10145 show_ip_bgp_community_cmd,
10146 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
10147 SHOW_STR
10148 IP_STR
10149 BGP_STR
10150 "Display routes matching the communities\n"
10151 COMMUNITY_AANN_STR
10152 "Do not send outside local AS (well-known community)\n"
10153 "Do not advertise to any peer (well-known community)\n"
10154 "Do not export to next AS (well-known community)\n")
10155 {
10156 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10157 }
10158
10159 ALIAS (show_ip_bgp_community,
10160 show_ip_bgp_community2_cmd,
10161 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10162 SHOW_STR
10163 IP_STR
10164 BGP_STR
10165 "Display routes matching the communities\n"
10166 COMMUNITY_AANN_STR
10167 "Do not send outside local AS (well-known community)\n"
10168 "Do not advertise to any peer (well-known community)\n"
10169 "Do not export to next AS (well-known community)\n"
10170 COMMUNITY_AANN_STR
10171 "Do not send outside local AS (well-known community)\n"
10172 "Do not advertise to any peer (well-known community)\n"
10173 "Do not export to next AS (well-known community)\n")
10174
10175 ALIAS (show_ip_bgp_community,
10176 show_ip_bgp_community3_cmd,
10177 "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)",
10178 SHOW_STR
10179 IP_STR
10180 BGP_STR
10181 "Display routes matching the communities\n"
10182 COMMUNITY_AANN_STR
10183 "Do not send outside local AS (well-known community)\n"
10184 "Do not advertise to any peer (well-known community)\n"
10185 "Do not export to next AS (well-known community)\n"
10186 COMMUNITY_AANN_STR
10187 "Do not send outside local AS (well-known community)\n"
10188 "Do not advertise to any peer (well-known community)\n"
10189 "Do not export to next AS (well-known community)\n"
10190 COMMUNITY_AANN_STR
10191 "Do not send outside local AS (well-known community)\n"
10192 "Do not advertise to any peer (well-known community)\n"
10193 "Do not export to next AS (well-known community)\n")
10194
10195 ALIAS (show_ip_bgp_community,
10196 show_ip_bgp_community4_cmd,
10197 "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)",
10198 SHOW_STR
10199 IP_STR
10200 BGP_STR
10201 "Display routes matching the communities\n"
10202 COMMUNITY_AANN_STR
10203 "Do not send outside local AS (well-known community)\n"
10204 "Do not advertise to any peer (well-known community)\n"
10205 "Do not export to next AS (well-known community)\n"
10206 COMMUNITY_AANN_STR
10207 "Do not send outside local AS (well-known community)\n"
10208 "Do not advertise to any peer (well-known community)\n"
10209 "Do not export to next AS (well-known community)\n"
10210 COMMUNITY_AANN_STR
10211 "Do not send outside local AS (well-known community)\n"
10212 "Do not advertise to any peer (well-known community)\n"
10213 "Do not export to next AS (well-known community)\n"
10214 COMMUNITY_AANN_STR
10215 "Do not send outside local AS (well-known community)\n"
10216 "Do not advertise to any peer (well-known community)\n"
10217 "Do not export to next AS (well-known community)\n")
10218
10219 DEFUN (show_ip_bgp_ipv4_community,
10220 show_ip_bgp_ipv4_community_cmd,
10221 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10222 SHOW_STR
10223 IP_STR
10224 BGP_STR
10225 "Address family\n"
10226 "Address Family modifier\n"
10227 "Address Family modifier\n"
10228 "Display routes matching the communities\n"
10229 COMMUNITY_AANN_STR
10230 "Do not send outside local AS (well-known community)\n"
10231 "Do not advertise to any peer (well-known community)\n"
10232 "Do not export to next AS (well-known community)\n")
10233 {
10234 if (strncmp (argv[0], "m", 1) == 0)
10235 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
10236
10237 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10238 }
10239
10240 ALIAS (show_ip_bgp_ipv4_community,
10241 show_ip_bgp_ipv4_community2_cmd,
10242 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10243 SHOW_STR
10244 IP_STR
10245 BGP_STR
10246 "Address family\n"
10247 "Address Family modifier\n"
10248 "Address Family modifier\n"
10249 "Display routes matching the communities\n"
10250 COMMUNITY_AANN_STR
10251 "Do not send outside local AS (well-known community)\n"
10252 "Do not advertise to any peer (well-known community)\n"
10253 "Do not export to next AS (well-known community)\n"
10254 COMMUNITY_AANN_STR
10255 "Do not send outside local AS (well-known community)\n"
10256 "Do not advertise to any peer (well-known community)\n"
10257 "Do not export to next AS (well-known community)\n")
10258
10259 ALIAS (show_ip_bgp_ipv4_community,
10260 show_ip_bgp_ipv4_community3_cmd,
10261 "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)",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
10265 "Address family\n"
10266 "Address Family modifier\n"
10267 "Address Family modifier\n"
10268 "Display routes matching the communities\n"
10269 COMMUNITY_AANN_STR
10270 "Do not send outside local AS (well-known community)\n"
10271 "Do not advertise to any peer (well-known community)\n"
10272 "Do not export to next AS (well-known community)\n"
10273 COMMUNITY_AANN_STR
10274 "Do not send outside local AS (well-known community)\n"
10275 "Do not advertise to any peer (well-known community)\n"
10276 "Do not export to next AS (well-known community)\n"
10277 COMMUNITY_AANN_STR
10278 "Do not send outside local AS (well-known community)\n"
10279 "Do not advertise to any peer (well-known community)\n"
10280 "Do not export to next AS (well-known community)\n")
10281
10282 ALIAS (show_ip_bgp_ipv4_community,
10283 show_ip_bgp_ipv4_community4_cmd,
10284 "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)",
10285 SHOW_STR
10286 IP_STR
10287 BGP_STR
10288 "Address family\n"
10289 "Address Family modifier\n"
10290 "Address Family modifier\n"
10291 "Display routes matching the communities\n"
10292 COMMUNITY_AANN_STR
10293 "Do not send outside local AS (well-known community)\n"
10294 "Do not advertise to any peer (well-known community)\n"
10295 "Do not export to next AS (well-known community)\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
10309 DEFUN (show_bgp_instance_afi_safi_community_all,
10310 show_bgp_instance_afi_safi_community_all_cmd,
10311 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
10312 SHOW_STR
10313 BGP_STR
10314 BGP_INSTANCE_HELP_STR
10315 "Address family\n"
10316 "Address family\n"
10317 "Address Family modifier\n"
10318 "Address Family modifier\n"
10319 "Display routes matching the communities\n")
10320 {
10321 int afi;
10322 int safi;
10323 struct bgp *bgp;
10324
10325 /* BGP structure lookup. */
10326 bgp = bgp_lookup_by_name (argv[1]);
10327 if (bgp == NULL)
10328 {
10329 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10330 return CMD_WARNING;
10331 }
10332
10333 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10334 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10335 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10336 }
10337
10338 DEFUN (show_bgp_instance_afi_safi_community,
10339 show_bgp_instance_afi_safi_community_cmd,
10340 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10341 SHOW_STR
10342 BGP_STR
10343 BGP_INSTANCE_HELP_STR
10344 "Address family\n"
10345 "Address family\n"
10346 "Address family modifier\n"
10347 "Address family modifier\n"
10348 "Display routes matching the communities\n"
10349 COMMUNITY_AANN_STR
10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n")
10353 {
10354 int afi;
10355 int safi;
10356
10357 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10358 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10359 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10360 }
10361
10362 ALIAS (show_bgp_instance_afi_safi_community,
10363 show_bgp_instance_afi_safi_community2_cmd,
10364 "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)",
10365 SHOW_STR
10366 BGP_STR
10367 BGP_INSTANCE_HELP_STR
10368 "Address family\n"
10369 "Address family\n"
10370 "Address family modifier\n"
10371 "Address family modifier\n"
10372 "Display routes matching the communities\n"
10373 COMMUNITY_AANN_STR
10374 "Do not send outside local AS (well-known community)\n"
10375 "Do not advertise to any peer (well-known community)\n"
10376 "Do not export to next AS (well-known community)\n"
10377 COMMUNITY_AANN_STR
10378 "Do not send outside local AS (well-known community)\n"
10379 "Do not advertise to any peer (well-known community)\n"
10380 "Do not export to next AS (well-known community)\n")
10381
10382 ALIAS (show_bgp_instance_afi_safi_community,
10383 show_bgp_instance_afi_safi_community3_cmd,
10384 "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)",
10385 SHOW_STR
10386 BGP_STR
10387 BGP_INSTANCE_HELP_STR
10388 "Address family\n"
10389 "Address family\n"
10390 "Address family modifier\n"
10391 "Address family modifier\n"
10392 "Display routes matching the communities\n"
10393 COMMUNITY_AANN_STR
10394 "Do not send outside local AS (well-known community)\n"
10395 "Do not advertise to any peer (well-known community)\n"
10396 "Do not export to next AS (well-known community)\n"
10397 COMMUNITY_AANN_STR
10398 "Do not send outside local AS (well-known community)\n"
10399 "Do not advertise to any peer (well-known community)\n"
10400 "Do not export to next AS (well-known community)\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
10406 ALIAS (show_bgp_instance_afi_safi_community,
10407 show_bgp_instance_afi_safi_community4_cmd,
10408 "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)",
10409 SHOW_STR
10410 BGP_STR
10411 BGP_INSTANCE_HELP_STR
10412 "Address family\n"
10413 "Address family\n"
10414 "Address family modifier\n"
10415 "Address family modifier\n"
10416 "Display routes matching the communities\n"
10417 COMMUNITY_AANN_STR
10418 "Do not send outside local AS (well-known community)\n"
10419 "Do not advertise to any peer (well-known community)\n"
10420 "Do not export to next AS (well-known community)\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
10434 DEFUN (show_ip_bgp_community_exact,
10435 show_ip_bgp_community_exact_cmd,
10436 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10437 SHOW_STR
10438 IP_STR
10439 BGP_STR
10440 "Display routes matching the communities\n"
10441 COMMUNITY_AANN_STR
10442 "Do not send outside local AS (well-known community)\n"
10443 "Do not advertise to any peer (well-known community)\n"
10444 "Do not export to next AS (well-known community)\n"
10445 "Exact match of the communities")
10446 {
10447 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10448 }
10449
10450 ALIAS (show_ip_bgp_community_exact,
10451 show_ip_bgp_community2_exact_cmd,
10452 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10453 SHOW_STR
10454 IP_STR
10455 BGP_STR
10456 "Display routes matching the communities\n"
10457 COMMUNITY_AANN_STR
10458 "Do not send outside local AS (well-known community)\n"
10459 "Do not advertise to any peer (well-known community)\n"
10460 "Do not export to next AS (well-known community)\n"
10461 COMMUNITY_AANN_STR
10462 "Do not send outside local AS (well-known community)\n"
10463 "Do not advertise to any peer (well-known community)\n"
10464 "Do not export to next AS (well-known community)\n"
10465 "Exact match of the communities")
10466
10467 ALIAS (show_ip_bgp_community_exact,
10468 show_ip_bgp_community3_exact_cmd,
10469 "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",
10470 SHOW_STR
10471 IP_STR
10472 BGP_STR
10473 "Display routes matching the communities\n"
10474 COMMUNITY_AANN_STR
10475 "Do not send outside local AS (well-known community)\n"
10476 "Do not advertise to any peer (well-known community)\n"
10477 "Do not export to next AS (well-known community)\n"
10478 COMMUNITY_AANN_STR
10479 "Do not send outside local AS (well-known community)\n"
10480 "Do not advertise to any peer (well-known community)\n"
10481 "Do not export to next AS (well-known community)\n"
10482 COMMUNITY_AANN_STR
10483 "Do not send outside local AS (well-known community)\n"
10484 "Do not advertise to any peer (well-known community)\n"
10485 "Do not export to next AS (well-known community)\n"
10486 "Exact match of the communities")
10487
10488 ALIAS (show_ip_bgp_community_exact,
10489 show_ip_bgp_community4_exact_cmd,
10490 "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",
10491 SHOW_STR
10492 IP_STR
10493 BGP_STR
10494 "Display routes matching the communities\n"
10495 COMMUNITY_AANN_STR
10496 "Do not send outside local AS (well-known community)\n"
10497 "Do not advertise to any peer (well-known community)\n"
10498 "Do not export to next AS (well-known community)\n"
10499 COMMUNITY_AANN_STR
10500 "Do not send outside local AS (well-known community)\n"
10501 "Do not advertise to any peer (well-known community)\n"
10502 "Do not export to next AS (well-known community)\n"
10503 COMMUNITY_AANN_STR
10504 "Do not send outside local AS (well-known community)\n"
10505 "Do not advertise to any peer (well-known community)\n"
10506 "Do not export to next AS (well-known community)\n"
10507 COMMUNITY_AANN_STR
10508 "Do not send outside local AS (well-known community)\n"
10509 "Do not advertise to any peer (well-known community)\n"
10510 "Do not export to next AS (well-known community)\n"
10511 "Exact match of the communities")
10512
10513 DEFUN (show_ip_bgp_ipv4_community_exact,
10514 show_ip_bgp_ipv4_community_exact_cmd,
10515 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10516 SHOW_STR
10517 IP_STR
10518 BGP_STR
10519 "Address family\n"
10520 "Address Family modifier\n"
10521 "Address Family modifier\n"
10522 "Display routes matching the communities\n"
10523 COMMUNITY_AANN_STR
10524 "Do not send outside local AS (well-known community)\n"
10525 "Do not advertise to any peer (well-known community)\n"
10526 "Do not export to next AS (well-known community)\n"
10527 "Exact match of the communities")
10528 {
10529 if (strncmp (argv[0], "m", 1) == 0)
10530 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
10531
10532 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10533 }
10534
10535 ALIAS (show_ip_bgp_ipv4_community_exact,
10536 show_ip_bgp_ipv4_community2_exact_cmd,
10537 "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",
10538 SHOW_STR
10539 IP_STR
10540 BGP_STR
10541 "Address family\n"
10542 "Address Family modifier\n"
10543 "Address Family modifier\n"
10544 "Display routes matching the communities\n"
10545 COMMUNITY_AANN_STR
10546 "Do not send outside local AS (well-known community)\n"
10547 "Do not advertise to any peer (well-known community)\n"
10548 "Do not export to next AS (well-known community)\n"
10549 COMMUNITY_AANN_STR
10550 "Do not send outside local AS (well-known community)\n"
10551 "Do not advertise to any peer (well-known community)\n"
10552 "Do not export to next AS (well-known community)\n"
10553 "Exact match of the communities")
10554
10555 ALIAS (show_ip_bgp_ipv4_community_exact,
10556 show_ip_bgp_ipv4_community3_exact_cmd,
10557 "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",
10558 SHOW_STR
10559 IP_STR
10560 BGP_STR
10561 "Address family\n"
10562 "Address Family modifier\n"
10563 "Address Family modifier\n"
10564 "Display routes matching the communities\n"
10565 COMMUNITY_AANN_STR
10566 "Do not send outside local AS (well-known community)\n"
10567 "Do not advertise to any peer (well-known community)\n"
10568 "Do not export to next AS (well-known community)\n"
10569 COMMUNITY_AANN_STR
10570 "Do not send outside local AS (well-known community)\n"
10571 "Do not advertise to any peer (well-known community)\n"
10572 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10578
10579 ALIAS (show_ip_bgp_ipv4_community_exact,
10580 show_ip_bgp_ipv4_community4_exact_cmd,
10581 "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",
10582 SHOW_STR
10583 IP_STR
10584 BGP_STR
10585 "Address family\n"
10586 "Address Family modifier\n"
10587 "Address Family modifier\n"
10588 "Display routes matching the communities\n"
10589 COMMUNITY_AANN_STR
10590 "Do not send outside local AS (well-known community)\n"
10591 "Do not advertise to any peer (well-known community)\n"
10592 "Do not export to next AS (well-known community)\n"
10593 COMMUNITY_AANN_STR
10594 "Do not send outside local AS (well-known community)\n"
10595 "Do not advertise to any peer (well-known community)\n"
10596 "Do not export to next AS (well-known community)\n"
10597 COMMUNITY_AANN_STR
10598 "Do not send outside local AS (well-known community)\n"
10599 "Do not advertise to any peer (well-known community)\n"
10600 "Do not export to next AS (well-known community)\n"
10601 COMMUNITY_AANN_STR
10602 "Do not send outside local AS (well-known community)\n"
10603 "Do not advertise to any peer (well-known community)\n"
10604 "Do not export to next AS (well-known community)\n"
10605 "Exact match of the communities")
10606
10607 #ifdef HAVE_IPV6
10608 DEFUN (show_bgp_community,
10609 show_bgp_community_cmd,
10610 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10611 SHOW_STR
10612 BGP_STR
10613 "Display routes matching the communities\n"
10614 COMMUNITY_AANN_STR
10615 "Do not send outside local AS (well-known community)\n"
10616 "Do not advertise to any peer (well-known community)\n"
10617 "Do not export to next AS (well-known community)\n")
10618 {
10619 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10620 }
10621
10622 ALIAS (show_bgp_community,
10623 show_bgp_ipv6_community_cmd,
10624 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10625 SHOW_STR
10626 BGP_STR
10627 "Address family\n"
10628 "Display routes matching the communities\n"
10629 COMMUNITY_AANN_STR
10630 "Do not send outside local AS (well-known community)\n"
10631 "Do not advertise to any peer (well-known community)\n"
10632 "Do not export to next AS (well-known community)\n")
10633
10634 ALIAS (show_bgp_community,
10635 show_bgp_community2_cmd,
10636 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10637 SHOW_STR
10638 BGP_STR
10639 "Display routes matching the communities\n"
10640 COMMUNITY_AANN_STR
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
10644 COMMUNITY_AANN_STR
10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n")
10648
10649 ALIAS (show_bgp_community,
10650 show_bgp_ipv6_community2_cmd,
10651 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10652 SHOW_STR
10653 BGP_STR
10654 "Address family\n"
10655 "Display routes matching the communities\n"
10656 COMMUNITY_AANN_STR
10657 "Do not send outside local AS (well-known community)\n"
10658 "Do not advertise to any peer (well-known community)\n"
10659 "Do not export to next AS (well-known community)\n"
10660 COMMUNITY_AANN_STR
10661 "Do not send outside local AS (well-known community)\n"
10662 "Do not advertise to any peer (well-known community)\n"
10663 "Do not export to next AS (well-known community)\n")
10664
10665 ALIAS (show_bgp_community,
10666 show_bgp_community3_cmd,
10667 "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)",
10668 SHOW_STR
10669 BGP_STR
10670 "Display routes matching the communities\n"
10671 COMMUNITY_AANN_STR
10672 "Do not send outside local AS (well-known community)\n"
10673 "Do not advertise to any peer (well-known community)\n"
10674 "Do not export to next AS (well-known community)\n"
10675 COMMUNITY_AANN_STR
10676 "Do not send outside local AS (well-known community)\n"
10677 "Do not advertise to any peer (well-known community)\n"
10678 "Do not export to next AS (well-known community)\n"
10679 COMMUNITY_AANN_STR
10680 "Do not send outside local AS (well-known community)\n"
10681 "Do not advertise to any peer (well-known community)\n"
10682 "Do not export to next AS (well-known community)\n")
10683
10684 ALIAS (show_bgp_community,
10685 show_bgp_ipv6_community3_cmd,
10686 "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)",
10687 SHOW_STR
10688 BGP_STR
10689 "Address family\n"
10690 "Display routes matching the communities\n"
10691 COMMUNITY_AANN_STR
10692 "Do not send outside local AS (well-known community)\n"
10693 "Do not advertise to any peer (well-known community)\n"
10694 "Do not export to next AS (well-known community)\n"
10695 COMMUNITY_AANN_STR
10696 "Do not send outside local AS (well-known community)\n"
10697 "Do not advertise to any peer (well-known community)\n"
10698 "Do not export to next AS (well-known community)\n"
10699 COMMUNITY_AANN_STR
10700 "Do not send outside local AS (well-known community)\n"
10701 "Do not advertise to any peer (well-known community)\n"
10702 "Do not export to next AS (well-known community)\n")
10703
10704 ALIAS (show_bgp_community,
10705 show_bgp_community4_cmd,
10706 "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)",
10707 SHOW_STR
10708 BGP_STR
10709 "Display routes matching the communities\n"
10710 COMMUNITY_AANN_STR
10711 "Do not send outside local AS (well-known community)\n"
10712 "Do not advertise to any peer (well-known community)\n"
10713 "Do not export to next AS (well-known community)\n"
10714 COMMUNITY_AANN_STR
10715 "Do not send outside local AS (well-known community)\n"
10716 "Do not advertise to any peer (well-known community)\n"
10717 "Do not export to next AS (well-known community)\n"
10718 COMMUNITY_AANN_STR
10719 "Do not send outside local AS (well-known community)\n"
10720 "Do not advertise to any peer (well-known community)\n"
10721 "Do not export to next AS (well-known community)\n"
10722 COMMUNITY_AANN_STR
10723 "Do not send outside local AS (well-known community)\n"
10724 "Do not advertise to any peer (well-known community)\n"
10725 "Do not export to next AS (well-known community)\n")
10726
10727 ALIAS (show_bgp_community,
10728 show_bgp_ipv6_community4_cmd,
10729 "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)",
10730 SHOW_STR
10731 BGP_STR
10732 "Address family\n"
10733 "Display routes matching the communities\n"
10734 COMMUNITY_AANN_STR
10735 "Do not send outside local AS (well-known community)\n"
10736 "Do not advertise to any peer (well-known community)\n"
10737 "Do not export to next AS (well-known community)\n"
10738 COMMUNITY_AANN_STR
10739 "Do not send outside local AS (well-known community)\n"
10740 "Do not advertise to any peer (well-known community)\n"
10741 "Do not export to next AS (well-known community)\n"
10742 COMMUNITY_AANN_STR
10743 "Do not send outside local AS (well-known community)\n"
10744 "Do not advertise to any peer (well-known community)\n"
10745 "Do not export to next AS (well-known community)\n"
10746 COMMUNITY_AANN_STR
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n")
10750
10751 /* old command */
10752 DEFUN (show_ipv6_bgp_community,
10753 show_ipv6_bgp_community_cmd,
10754 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10755 SHOW_STR
10756 IPV6_STR
10757 BGP_STR
10758 "Display routes matching the communities\n"
10759 COMMUNITY_AANN_STR
10760 "Do not send outside local AS (well-known community)\n"
10761 "Do not advertise to any peer (well-known community)\n"
10762 "Do not export to next AS (well-known community)\n")
10763 {
10764 bgp_show_ipv6_bgp_deprecate_warning(vty);
10765 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10766 }
10767
10768 /* old command */
10769 ALIAS (show_ipv6_bgp_community,
10770 show_ipv6_bgp_community2_cmd,
10771 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10772 SHOW_STR
10773 IPV6_STR
10774 BGP_STR
10775 "Display routes matching the communities\n"
10776 COMMUNITY_AANN_STR
10777 "Do not send outside local AS (well-known community)\n"
10778 "Do not advertise to any peer (well-known community)\n"
10779 "Do not export to next AS (well-known community)\n"
10780 COMMUNITY_AANN_STR
10781 "Do not send outside local AS (well-known community)\n"
10782 "Do not advertise to any peer (well-known community)\n"
10783 "Do not export to next AS (well-known community)\n")
10784
10785 /* old command */
10786 ALIAS (show_ipv6_bgp_community,
10787 show_ipv6_bgp_community3_cmd,
10788 "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)",
10789 SHOW_STR
10790 IPV6_STR
10791 BGP_STR
10792 "Display routes matching the communities\n"
10793 COMMUNITY_AANN_STR
10794 "Do not send outside local AS (well-known community)\n"
10795 "Do not advertise to any peer (well-known community)\n"
10796 "Do not export to next AS (well-known community)\n"
10797 COMMUNITY_AANN_STR
10798 "Do not send outside local AS (well-known community)\n"
10799 "Do not advertise to any peer (well-known community)\n"
10800 "Do not export to next AS (well-known community)\n"
10801 COMMUNITY_AANN_STR
10802 "Do not send outside local AS (well-known community)\n"
10803 "Do not advertise to any peer (well-known community)\n"
10804 "Do not export to next AS (well-known community)\n")
10805
10806 /* old command */
10807 ALIAS (show_ipv6_bgp_community,
10808 show_ipv6_bgp_community4_cmd,
10809 "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)",
10810 SHOW_STR
10811 IPV6_STR
10812 BGP_STR
10813 "Display routes matching the communities\n"
10814 COMMUNITY_AANN_STR
10815 "Do not send outside local AS (well-known community)\n"
10816 "Do not advertise to any peer (well-known community)\n"
10817 "Do not export to next AS (well-known community)\n"
10818 COMMUNITY_AANN_STR
10819 "Do not send outside local AS (well-known community)\n"
10820 "Do not advertise to any peer (well-known community)\n"
10821 "Do not export to next AS (well-known community)\n"
10822 COMMUNITY_AANN_STR
10823 "Do not send outside local AS (well-known community)\n"
10824 "Do not advertise to any peer (well-known community)\n"
10825 "Do not export to next AS (well-known community)\n"
10826 COMMUNITY_AANN_STR
10827 "Do not send outside local AS (well-known community)\n"
10828 "Do not advertise to any peer (well-known community)\n"
10829 "Do not export to next AS (well-known community)\n")
10830
10831 DEFUN (show_bgp_community_exact,
10832 show_bgp_community_exact_cmd,
10833 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10834 SHOW_STR
10835 BGP_STR
10836 "Display routes matching the communities\n"
10837 COMMUNITY_AANN_STR
10838 "Do not send outside local AS (well-known community)\n"
10839 "Do not advertise to any peer (well-known community)\n"
10840 "Do not export to next AS (well-known community)\n"
10841 "Exact match of the communities")
10842 {
10843 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10844 }
10845
10846 ALIAS (show_bgp_community_exact,
10847 show_bgp_ipv6_community_exact_cmd,
10848 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10849 SHOW_STR
10850 BGP_STR
10851 "Address family\n"
10852 "Display routes matching the communities\n"
10853 COMMUNITY_AANN_STR
10854 "Do not send outside local AS (well-known community)\n"
10855 "Do not advertise to any peer (well-known community)\n"
10856 "Do not export to next AS (well-known community)\n"
10857 "Exact match of the communities")
10858
10859 ALIAS (show_bgp_community_exact,
10860 show_bgp_community2_exact_cmd,
10861 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10862 SHOW_STR
10863 BGP_STR
10864 "Display routes matching the communities\n"
10865 COMMUNITY_AANN_STR
10866 "Do not send outside local AS (well-known community)\n"
10867 "Do not advertise to any peer (well-known community)\n"
10868 "Do not export to next AS (well-known community)\n"
10869 COMMUNITY_AANN_STR
10870 "Do not send outside local AS (well-known community)\n"
10871 "Do not advertise to any peer (well-known community)\n"
10872 "Do not export to next AS (well-known community)\n"
10873 "Exact match of the communities")
10874
10875 ALIAS (show_bgp_community_exact,
10876 show_bgp_ipv6_community2_exact_cmd,
10877 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10878 SHOW_STR
10879 BGP_STR
10880 "Address family\n"
10881 "Display routes matching the communities\n"
10882 COMMUNITY_AANN_STR
10883 "Do not send outside local AS (well-known community)\n"
10884 "Do not advertise to any peer (well-known community)\n"
10885 "Do not export to next AS (well-known community)\n"
10886 COMMUNITY_AANN_STR
10887 "Do not send outside local AS (well-known community)\n"
10888 "Do not advertise to any peer (well-known community)\n"
10889 "Do not export to next AS (well-known community)\n"
10890 "Exact match of the communities")
10891
10892 ALIAS (show_bgp_community_exact,
10893 show_bgp_community3_exact_cmd,
10894 "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",
10895 SHOW_STR
10896 BGP_STR
10897 "Display routes matching the communities\n"
10898 COMMUNITY_AANN_STR
10899 "Do not send outside local AS (well-known community)\n"
10900 "Do not advertise to any peer (well-known community)\n"
10901 "Do not export to next AS (well-known community)\n"
10902 COMMUNITY_AANN_STR
10903 "Do not send outside local AS (well-known community)\n"
10904 "Do not advertise to any peer (well-known community)\n"
10905 "Do not export to next AS (well-known community)\n"
10906 COMMUNITY_AANN_STR
10907 "Do not send outside local AS (well-known community)\n"
10908 "Do not advertise to any peer (well-known community)\n"
10909 "Do not export to next AS (well-known community)\n"
10910 "Exact match of the communities")
10911
10912 ALIAS (show_bgp_community_exact,
10913 show_bgp_ipv6_community3_exact_cmd,
10914 "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",
10915 SHOW_STR
10916 BGP_STR
10917 "Address family\n"
10918 "Display routes matching the communities\n"
10919 COMMUNITY_AANN_STR
10920 "Do not send outside local AS (well-known community)\n"
10921 "Do not advertise to any peer (well-known community)\n"
10922 "Do not export to next AS (well-known community)\n"
10923 COMMUNITY_AANN_STR
10924 "Do not send outside local AS (well-known community)\n"
10925 "Do not advertise to any peer (well-known community)\n"
10926 "Do not export to next AS (well-known community)\n"
10927 COMMUNITY_AANN_STR
10928 "Do not send outside local AS (well-known community)\n"
10929 "Do not advertise to any peer (well-known community)\n"
10930 "Do not export to next AS (well-known community)\n"
10931 "Exact match of the communities")
10932
10933 ALIAS (show_bgp_community_exact,
10934 show_bgp_community4_exact_cmd,
10935 "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",
10936 SHOW_STR
10937 BGP_STR
10938 "Display routes matching the communities\n"
10939 COMMUNITY_AANN_STR
10940 "Do not send outside local AS (well-known community)\n"
10941 "Do not advertise to any peer (well-known community)\n"
10942 "Do not export to next AS (well-known community)\n"
10943 COMMUNITY_AANN_STR
10944 "Do not send outside local AS (well-known community)\n"
10945 "Do not advertise to any peer (well-known community)\n"
10946 "Do not export to next AS (well-known community)\n"
10947 COMMUNITY_AANN_STR
10948 "Do not send outside local AS (well-known community)\n"
10949 "Do not advertise to any peer (well-known community)\n"
10950 "Do not export to next AS (well-known community)\n"
10951 COMMUNITY_AANN_STR
10952 "Do not send outside local AS (well-known community)\n"
10953 "Do not advertise to any peer (well-known community)\n"
10954 "Do not export to next AS (well-known community)\n"
10955 "Exact match of the communities")
10956
10957 ALIAS (show_bgp_community_exact,
10958 show_bgp_ipv6_community4_exact_cmd,
10959 "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",
10960 SHOW_STR
10961 BGP_STR
10962 "Address family\n"
10963 "Display routes matching the communities\n"
10964 COMMUNITY_AANN_STR
10965 "Do not send outside local AS (well-known community)\n"
10966 "Do not advertise to any peer (well-known community)\n"
10967 "Do not export to next AS (well-known community)\n"
10968 COMMUNITY_AANN_STR
10969 "Do not send outside local AS (well-known community)\n"
10970 "Do not advertise to any peer (well-known community)\n"
10971 "Do not export to next AS (well-known community)\n"
10972 COMMUNITY_AANN_STR
10973 "Do not send outside local AS (well-known community)\n"
10974 "Do not advertise to any peer (well-known community)\n"
10975 "Do not export to next AS (well-known community)\n"
10976 COMMUNITY_AANN_STR
10977 "Do not send outside local AS (well-known community)\n"
10978 "Do not advertise to any peer (well-known community)\n"
10979 "Do not export to next AS (well-known community)\n"
10980 "Exact match of the communities")
10981
10982 /* old command */
10983 DEFUN (show_ipv6_bgp_community_exact,
10984 show_ipv6_bgp_community_exact_cmd,
10985 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10986 SHOW_STR
10987 IPV6_STR
10988 BGP_STR
10989 "Display routes matching the communities\n"
10990 COMMUNITY_AANN_STR
10991 "Do not send outside local AS (well-known community)\n"
10992 "Do not advertise to any peer (well-known community)\n"
10993 "Do not export to next AS (well-known community)\n"
10994 "Exact match of the communities")
10995 {
10996 bgp_show_ipv6_bgp_deprecate_warning(vty);
10997 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10998 }
10999
11000 /* old command */
11001 ALIAS (show_ipv6_bgp_community_exact,
11002 show_ipv6_bgp_community2_exact_cmd,
11003 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11004 SHOW_STR
11005 IPV6_STR
11006 BGP_STR
11007 "Display routes matching the communities\n"
11008 COMMUNITY_AANN_STR
11009 "Do not send outside local AS (well-known community)\n"
11010 "Do not advertise to any peer (well-known community)\n"
11011 "Do not export to next AS (well-known community)\n"
11012 COMMUNITY_AANN_STR
11013 "Do not send outside local AS (well-known community)\n"
11014 "Do not advertise to any peer (well-known community)\n"
11015 "Do not export to next AS (well-known community)\n"
11016 "Exact match of the communities")
11017
11018 /* old command */
11019 ALIAS (show_ipv6_bgp_community_exact,
11020 show_ipv6_bgp_community3_exact_cmd,
11021 "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",
11022 SHOW_STR
11023 IPV6_STR
11024 BGP_STR
11025 "Display routes matching the communities\n"
11026 COMMUNITY_AANN_STR
11027 "Do not send outside local AS (well-known community)\n"
11028 "Do not advertise to any peer (well-known community)\n"
11029 "Do not export to next AS (well-known community)\n"
11030 COMMUNITY_AANN_STR
11031 "Do not send outside local AS (well-known community)\n"
11032 "Do not advertise to any peer (well-known community)\n"
11033 "Do not export to next AS (well-known community)\n"
11034 COMMUNITY_AANN_STR
11035 "Do not send outside local AS (well-known community)\n"
11036 "Do not advertise to any peer (well-known community)\n"
11037 "Do not export to next AS (well-known community)\n"
11038 "Exact match of the communities")
11039
11040 /* old command */
11041 ALIAS (show_ipv6_bgp_community_exact,
11042 show_ipv6_bgp_community4_exact_cmd,
11043 "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",
11044 SHOW_STR
11045 IPV6_STR
11046 BGP_STR
11047 "Display routes matching the communities\n"
11048 COMMUNITY_AANN_STR
11049 "Do not send outside local AS (well-known community)\n"
11050 "Do not advertise to any peer (well-known community)\n"
11051 "Do not export to next AS (well-known community)\n"
11052 COMMUNITY_AANN_STR
11053 "Do not send outside local AS (well-known community)\n"
11054 "Do not advertise to any peer (well-known community)\n"
11055 "Do not export to next AS (well-known community)\n"
11056 COMMUNITY_AANN_STR
11057 "Do not send outside local AS (well-known community)\n"
11058 "Do not advertise to any peer (well-known community)\n"
11059 "Do not export to next AS (well-known community)\n"
11060 COMMUNITY_AANN_STR
11061 "Do not send outside local AS (well-known community)\n"
11062 "Do not advertise to any peer (well-known community)\n"
11063 "Do not export to next AS (well-known community)\n"
11064 "Exact match of the communities")
11065
11066 /* old command */
11067 DEFUN (show_ipv6_mbgp_community,
11068 show_ipv6_mbgp_community_cmd,
11069 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
11070 SHOW_STR
11071 IPV6_STR
11072 MBGP_STR
11073 "Display routes matching the communities\n"
11074 COMMUNITY_AANN_STR
11075 "Do not send outside local AS (well-known community)\n"
11076 "Do not advertise to any peer (well-known community)\n"
11077 "Do not export to next AS (well-known community)\n")
11078 {
11079 bgp_show_ipv6_bgp_deprecate_warning(vty);
11080 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
11081 }
11082
11083 /* old command */
11084 ALIAS (show_ipv6_mbgp_community,
11085 show_ipv6_mbgp_community2_cmd,
11086 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
11087 SHOW_STR
11088 IPV6_STR
11089 MBGP_STR
11090 "Display routes matching the communities\n"
11091 COMMUNITY_AANN_STR
11092 "Do not send outside local AS (well-known community)\n"
11093 "Do not advertise to any peer (well-known community)\n"
11094 "Do not export to next AS (well-known community)\n"
11095 COMMUNITY_AANN_STR
11096 "Do not send outside local AS (well-known community)\n"
11097 "Do not advertise to any peer (well-known community)\n"
11098 "Do not export to next AS (well-known community)\n")
11099
11100 /* old command */
11101 ALIAS (show_ipv6_mbgp_community,
11102 show_ipv6_mbgp_community3_cmd,
11103 "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)",
11104 SHOW_STR
11105 IPV6_STR
11106 MBGP_STR
11107 "Display routes matching the communities\n"
11108 COMMUNITY_AANN_STR
11109 "Do not send outside local AS (well-known community)\n"
11110 "Do not advertise to any peer (well-known community)\n"
11111 "Do not export to next AS (well-known community)\n"
11112 COMMUNITY_AANN_STR
11113 "Do not send outside local AS (well-known community)\n"
11114 "Do not advertise to any peer (well-known community)\n"
11115 "Do not export to next AS (well-known community)\n"
11116 COMMUNITY_AANN_STR
11117 "Do not send outside local AS (well-known community)\n"
11118 "Do not advertise to any peer (well-known community)\n"
11119 "Do not export to next AS (well-known community)\n")
11120
11121 /* old command */
11122 ALIAS (show_ipv6_mbgp_community,
11123 show_ipv6_mbgp_community4_cmd,
11124 "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)",
11125 SHOW_STR
11126 IPV6_STR
11127 MBGP_STR
11128 "Display routes matching the communities\n"
11129 COMMUNITY_AANN_STR
11130 "Do not send outside local AS (well-known community)\n"
11131 "Do not advertise to any peer (well-known community)\n"
11132 "Do not export to next AS (well-known community)\n"
11133 COMMUNITY_AANN_STR
11134 "Do not send outside local AS (well-known community)\n"
11135 "Do not advertise to any peer (well-known community)\n"
11136 "Do not export to next AS (well-known community)\n"
11137 COMMUNITY_AANN_STR
11138 "Do not send outside local AS (well-known community)\n"
11139 "Do not advertise to any peer (well-known community)\n"
11140 "Do not export to next AS (well-known community)\n"
11141 COMMUNITY_AANN_STR
11142 "Do not send outside local AS (well-known community)\n"
11143 "Do not advertise to any peer (well-known community)\n"
11144 "Do not export to next AS (well-known community)\n")
11145
11146 /* old command */
11147 DEFUN (show_ipv6_mbgp_community_exact,
11148 show_ipv6_mbgp_community_exact_cmd,
11149 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11150 SHOW_STR
11151 IPV6_STR
11152 MBGP_STR
11153 "Display routes matching the communities\n"
11154 COMMUNITY_AANN_STR
11155 "Do not send outside local AS (well-known community)\n"
11156 "Do not advertise to any peer (well-known community)\n"
11157 "Do not export to next AS (well-known community)\n"
11158 "Exact match of the communities")
11159 {
11160 bgp_show_ipv6_bgp_deprecate_warning(vty);
11161 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
11162 }
11163
11164 /* old command */
11165 ALIAS (show_ipv6_mbgp_community_exact,
11166 show_ipv6_mbgp_community2_exact_cmd,
11167 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11168 SHOW_STR
11169 IPV6_STR
11170 MBGP_STR
11171 "Display routes matching the communities\n"
11172 COMMUNITY_AANN_STR
11173 "Do not send outside local AS (well-known community)\n"
11174 "Do not advertise to any peer (well-known community)\n"
11175 "Do not export to next AS (well-known community)\n"
11176 COMMUNITY_AANN_STR
11177 "Do not send outside local AS (well-known community)\n"
11178 "Do not advertise to any peer (well-known community)\n"
11179 "Do not export to next AS (well-known community)\n"
11180 "Exact match of the communities")
11181
11182 /* old command */
11183 ALIAS (show_ipv6_mbgp_community_exact,
11184 show_ipv6_mbgp_community3_exact_cmd,
11185 "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",
11186 SHOW_STR
11187 IPV6_STR
11188 MBGP_STR
11189 "Display routes matching the communities\n"
11190 COMMUNITY_AANN_STR
11191 "Do not send outside local AS (well-known community)\n"
11192 "Do not advertise to any peer (well-known community)\n"
11193 "Do not export to next AS (well-known community)\n"
11194 COMMUNITY_AANN_STR
11195 "Do not send outside local AS (well-known community)\n"
11196 "Do not advertise to any peer (well-known community)\n"
11197 "Do not export to next AS (well-known community)\n"
11198 COMMUNITY_AANN_STR
11199 "Do not send outside local AS (well-known community)\n"
11200 "Do not advertise to any peer (well-known community)\n"
11201 "Do not export to next AS (well-known community)\n"
11202 "Exact match of the communities")
11203
11204 /* old command */
11205 ALIAS (show_ipv6_mbgp_community_exact,
11206 show_ipv6_mbgp_community4_exact_cmd,
11207 "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",
11208 SHOW_STR
11209 IPV6_STR
11210 MBGP_STR
11211 "Display routes matching the communities\n"
11212 COMMUNITY_AANN_STR
11213 "Do not send outside local AS (well-known community)\n"
11214 "Do not advertise to any peer (well-known community)\n"
11215 "Do not export to next AS (well-known community)\n"
11216 COMMUNITY_AANN_STR
11217 "Do not send outside local AS (well-known community)\n"
11218 "Do not advertise to any peer (well-known community)\n"
11219 "Do not export to next AS (well-known community)\n"
11220 COMMUNITY_AANN_STR
11221 "Do not send outside local AS (well-known community)\n"
11222 "Do not advertise to any peer (well-known community)\n"
11223 "Do not export to next AS (well-known community)\n"
11224 COMMUNITY_AANN_STR
11225 "Do not send outside local AS (well-known community)\n"
11226 "Do not advertise to any peer (well-known community)\n"
11227 "Do not export to next AS (well-known community)\n"
11228 "Exact match of the communities")
11229 #endif /* HAVE_IPV6 */
11230
11231 static int
11232 bgp_show_community_list (struct vty *vty, const char *name,
11233 const char *com, int exact,
11234 afi_t afi, safi_t safi)
11235 {
11236 struct community_list *list;
11237 struct bgp *bgp = NULL;
11238
11239 if (name && !(bgp = bgp_lookup_by_name(name)))
11240 {
11241 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11242 return CMD_WARNING;
11243 }
11244
11245 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11246 if (list == NULL)
11247 {
11248 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11249 VTY_NEWLINE);
11250 return CMD_WARNING;
11251 }
11252
11253 return bgp_show (vty, bgp, afi, safi,
11254 (exact ? bgp_show_type_community_list_exact :
11255 bgp_show_type_community_list), list, 0);
11256 }
11257
11258 DEFUN (show_ip_bgp_community_list,
11259 show_ip_bgp_community_list_cmd,
11260 "show ip bgp community-list (<1-500>|WORD)",
11261 SHOW_STR
11262 IP_STR
11263 BGP_STR
11264 "Display routes matching the community-list\n"
11265 "community-list number\n"
11266 "community-list name\n")
11267 {
11268 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11269 }
11270
11271 DEFUN (show_ip_bgp_instance_community_list,
11272 show_ip_bgp_instance_community_list_cmd,
11273 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11274 SHOW_STR
11275 IP_STR
11276 BGP_STR
11277 BGP_INSTANCE_HELP_STR
11278 "Display routes matching the community-list\n"
11279 "community-list number\n"
11280 "community-list name\n")
11281 {
11282 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11283 }
11284
11285 DEFUN (show_ip_bgp_ipv4_community_list,
11286 show_ip_bgp_ipv4_community_list_cmd,
11287 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11288 SHOW_STR
11289 IP_STR
11290 BGP_STR
11291 "Address family\n"
11292 "Address Family modifier\n"
11293 "Address Family modifier\n"
11294 "Display routes matching the community-list\n"
11295 "community-list number\n"
11296 "community-list name\n")
11297 {
11298 if (strncmp (argv[0], "m", 1) == 0)
11299 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11300
11301 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
11302 }
11303
11304 DEFUN (show_ip_bgp_community_list_exact,
11305 show_ip_bgp_community_list_exact_cmd,
11306 "show ip bgp community-list (<1-500>|WORD) exact-match",
11307 SHOW_STR
11308 IP_STR
11309 BGP_STR
11310 "Display routes matching the community-list\n"
11311 "community-list number\n"
11312 "community-list name\n"
11313 "Exact match of the communities\n")
11314 {
11315 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11316 }
11317
11318 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11319 show_ip_bgp_ipv4_community_list_exact_cmd,
11320 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11321 SHOW_STR
11322 IP_STR
11323 BGP_STR
11324 "Address family\n"
11325 "Address Family modifier\n"
11326 "Address Family modifier\n"
11327 "Display routes matching the community-list\n"
11328 "community-list number\n"
11329 "community-list name\n"
11330 "Exact match of the communities\n")
11331 {
11332 if (strncmp (argv[0], "m", 1) == 0)
11333 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11334
11335 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
11336 }
11337
11338 #ifdef HAVE_IPV6
11339 DEFUN (show_bgp_community_list,
11340 show_bgp_community_list_cmd,
11341 "show bgp community-list (<1-500>|WORD)",
11342 SHOW_STR
11343 BGP_STR
11344 "Display routes matching the community-list\n"
11345 "community-list number\n"
11346 "community-list name\n")
11347 {
11348 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11349 }
11350
11351 ALIAS (show_bgp_community_list,
11352 show_bgp_ipv6_community_list_cmd,
11353 "show bgp ipv6 community-list (<1-500>|WORD)",
11354 SHOW_STR
11355 BGP_STR
11356 "Address family\n"
11357 "Display routes matching the community-list\n"
11358 "community-list number\n"
11359 "community-list name\n")
11360
11361 /* old command */
11362 DEFUN (show_ipv6_bgp_community_list,
11363 show_ipv6_bgp_community_list_cmd,
11364 "show ipv6 bgp community-list WORD",
11365 SHOW_STR
11366 IPV6_STR
11367 BGP_STR
11368 "Display routes matching the community-list\n"
11369 "community-list name\n")
11370 {
11371 bgp_show_ipv6_bgp_deprecate_warning(vty);
11372 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11373 }
11374
11375 /* old command */
11376 DEFUN (show_ipv6_mbgp_community_list,
11377 show_ipv6_mbgp_community_list_cmd,
11378 "show ipv6 mbgp community-list WORD",
11379 SHOW_STR
11380 IPV6_STR
11381 MBGP_STR
11382 "Display routes matching the community-list\n"
11383 "community-list name\n")
11384 {
11385 bgp_show_ipv6_bgp_deprecate_warning(vty);
11386 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11387 }
11388
11389 DEFUN (show_bgp_community_list_exact,
11390 show_bgp_community_list_exact_cmd,
11391 "show bgp community-list (<1-500>|WORD) exact-match",
11392 SHOW_STR
11393 BGP_STR
11394 "Display routes matching the community-list\n"
11395 "community-list number\n"
11396 "community-list name\n"
11397 "Exact match of the communities\n")
11398 {
11399 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11400 }
11401
11402 ALIAS (show_bgp_community_list_exact,
11403 show_bgp_ipv6_community_list_exact_cmd,
11404 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11405 SHOW_STR
11406 BGP_STR
11407 "Address family\n"
11408 "Display routes matching the community-list\n"
11409 "community-list number\n"
11410 "community-list name\n"
11411 "Exact match of the communities\n")
11412
11413 /* old command */
11414 DEFUN (show_ipv6_bgp_community_list_exact,
11415 show_ipv6_bgp_community_list_exact_cmd,
11416 "show ipv6 bgp community-list WORD exact-match",
11417 SHOW_STR
11418 IPV6_STR
11419 BGP_STR
11420 "Display routes matching the community-list\n"
11421 "community-list name\n"
11422 "Exact match of the communities\n")
11423 {
11424 bgp_show_ipv6_bgp_deprecate_warning(vty);
11425 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11426 }
11427
11428 /* old command */
11429 DEFUN (show_ipv6_mbgp_community_list_exact,
11430 show_ipv6_mbgp_community_list_exact_cmd,
11431 "show ipv6 mbgp community-list WORD exact-match",
11432 SHOW_STR
11433 IPV6_STR
11434 MBGP_STR
11435 "Display routes matching the community-list\n"
11436 "community-list name\n"
11437 "Exact match of the communities\n")
11438 {
11439 bgp_show_ipv6_bgp_deprecate_warning(vty);
11440 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11441 }
11442 #endif /* HAVE_IPV6 */
11443
11444 static int
11445 bgp_show_prefix_longer (struct vty *vty, const char *name,
11446 const char *prefix, afi_t afi,
11447 safi_t safi, enum bgp_show_type type)
11448 {
11449 int ret;
11450 struct prefix *p;
11451 struct bgp *bgp = NULL;
11452
11453 if (name && !(bgp = bgp_lookup_by_name(name)))
11454 {
11455 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11456 return CMD_WARNING;
11457 }
11458
11459 p = prefix_new();
11460
11461 ret = str2prefix (prefix, p);
11462 if (! ret)
11463 {
11464 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467
11468 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11469 prefix_free(p);
11470 return ret;
11471 }
11472
11473 DEFUN (show_ip_bgp_prefix_longer,
11474 show_ip_bgp_prefix_longer_cmd,
11475 "show ip bgp A.B.C.D/M longer-prefixes",
11476 SHOW_STR
11477 IP_STR
11478 BGP_STR
11479 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11480 "Display route and more specific routes\n")
11481 {
11482 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11483 bgp_show_type_prefix_longer);
11484 }
11485
11486 DEFUN (show_ip_bgp_instance_prefix_longer,
11487 show_ip_bgp_instance_prefix_longer_cmd,
11488 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11489 SHOW_STR
11490 IP_STR
11491 BGP_STR
11492 BGP_INSTANCE_HELP_STR
11493 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11494 "Display route and more specific routes\n")
11495 {
11496 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11497 bgp_show_type_prefix_longer);
11498 }
11499
11500 DEFUN (show_ip_bgp_flap_prefix_longer,
11501 show_ip_bgp_flap_prefix_longer_cmd,
11502 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11503 SHOW_STR
11504 IP_STR
11505 BGP_STR
11506 "Display flap statistics of routes\n"
11507 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11508 "Display route and more specific routes\n")
11509 {
11510 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11511 bgp_show_type_flap_prefix_longer);
11512 }
11513
11514 ALIAS (show_ip_bgp_flap_prefix_longer,
11515 show_ip_bgp_damp_flap_prefix_longer_cmd,
11516 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11517 SHOW_STR
11518 IP_STR
11519 BGP_STR
11520 "Display detailed information about dampening\n"
11521 "Display flap statistics of routes\n"
11522 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11523 "Display route and more specific routes\n")
11524
11525 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11526 show_ip_bgp_ipv4_prefix_longer_cmd,
11527 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11528 SHOW_STR
11529 IP_STR
11530 BGP_STR
11531 "Address family\n"
11532 "Address Family modifier\n"
11533 "Address Family modifier\n"
11534 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11535 "Display route and more specific routes\n")
11536 {
11537 if (strncmp (argv[0], "m", 1) == 0)
11538 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
11539 bgp_show_type_prefix_longer);
11540
11541 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
11542 bgp_show_type_prefix_longer);
11543 }
11544
11545 DEFUN (show_ip_bgp_flap_address,
11546 show_ip_bgp_flap_address_cmd,
11547 "show ip bgp flap-statistics A.B.C.D",
11548 SHOW_STR
11549 IP_STR
11550 BGP_STR
11551 "Display flap statistics of routes\n"
11552 "Network in the BGP routing table to display\n")
11553 {
11554 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11555 bgp_show_type_flap_address);
11556 }
11557
11558 ALIAS (show_ip_bgp_flap_address,
11559 show_ip_bgp_damp_flap_address_cmd,
11560 "show ip bgp dampening flap-statistics A.B.C.D",
11561 SHOW_STR
11562 IP_STR
11563 BGP_STR
11564 "Display detailed information about dampening\n"
11565 "Display flap statistics of routes\n"
11566 "Network in the BGP routing table to display\n")
11567
11568 DEFUN (show_ip_bgp_flap_prefix,
11569 show_ip_bgp_flap_prefix_cmd,
11570 "show ip bgp flap-statistics A.B.C.D/M",
11571 SHOW_STR
11572 IP_STR
11573 BGP_STR
11574 "Display flap statistics of routes\n"
11575 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11576 {
11577 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11578 bgp_show_type_flap_prefix);
11579 }
11580
11581 ALIAS (show_ip_bgp_flap_prefix,
11582 show_ip_bgp_damp_flap_prefix_cmd,
11583 "show ip bgp dampening flap-statistics A.B.C.D/M",
11584 SHOW_STR
11585 IP_STR
11586 BGP_STR
11587 "Display detailed information about dampening\n"
11588 "Display flap statistics of routes\n"
11589 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11590
11591 #ifdef HAVE_IPV6
11592 DEFUN (show_bgp_prefix_longer,
11593 show_bgp_prefix_longer_cmd,
11594 "show bgp X:X::X:X/M longer-prefixes",
11595 SHOW_STR
11596 BGP_STR
11597 "IPv6 prefix <network>/<length>\n"
11598 "Display route and more specific routes\n")
11599 {
11600 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11601 bgp_show_type_prefix_longer);
11602 }
11603
11604 ALIAS (show_bgp_prefix_longer,
11605 show_bgp_ipv6_prefix_longer_cmd,
11606 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11607 SHOW_STR
11608 BGP_STR
11609 "Address family\n"
11610 "IPv6 prefix <network>/<length>\n"
11611 "Display route and more specific routes\n")
11612
11613 /* old command */
11614 DEFUN (show_ipv6_bgp_prefix_longer,
11615 show_ipv6_bgp_prefix_longer_cmd,
11616 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11617 SHOW_STR
11618 IPV6_STR
11619 BGP_STR
11620 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11621 "Display route and more specific routes\n")
11622 {
11623 bgp_show_ipv6_bgp_deprecate_warning(vty);
11624 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11625 bgp_show_type_prefix_longer);
11626 }
11627
11628 /* old command */
11629 DEFUN (show_ipv6_mbgp_prefix_longer,
11630 show_ipv6_mbgp_prefix_longer_cmd,
11631 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11632 SHOW_STR
11633 IPV6_STR
11634 MBGP_STR
11635 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11636 "Display route and more specific routes\n")
11637 {
11638 bgp_show_ipv6_bgp_deprecate_warning(vty);
11639 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11640 bgp_show_type_prefix_longer);
11641 }
11642 #endif /* HAVE_IPV6 */
11643
11644 static struct peer *
11645 peer_lookup_in_view (struct vty *vty, const char *view_name,
11646 const char *ip_str, u_char use_json)
11647 {
11648 int ret;
11649 struct bgp *bgp;
11650 struct peer *peer;
11651 union sockunion su;
11652
11653 /* BGP structure lookup. */
11654 if (view_name)
11655 {
11656 bgp = bgp_lookup_by_name (view_name);
11657 if (! bgp)
11658 {
11659 if (use_json)
11660 {
11661 json_object *json_no = NULL;
11662 json_no = json_object_new_object();
11663 json_object_string_add(json_no, "warning", "Can't find BGP view");
11664 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11665 json_object_free(json_no);
11666 }
11667 else
11668 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11669 return NULL;
11670 }
11671 }
11672 else
11673 {
11674 bgp = bgp_get_default ();
11675 if (! bgp)
11676 {
11677 if (use_json)
11678 {
11679 json_object *json_no = NULL;
11680 json_no = json_object_new_object();
11681 json_object_string_add(json_no, "warning", "No BGP process configured");
11682 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11683 json_object_free(json_no);
11684 }
11685 else
11686 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11687 return NULL;
11688 }
11689 }
11690
11691 /* Get peer sockunion. */
11692 ret = str2sockunion (ip_str, &su);
11693 if (ret < 0)
11694 {
11695 peer = peer_lookup_by_conf_if (bgp, ip_str);
11696 if (!peer)
11697 {
11698 peer = peer_lookup_by_hostname(bgp, ip_str);
11699
11700 if (!peer)
11701 {
11702 if (use_json)
11703 {
11704 json_object *json_no = NULL;
11705 json_no = json_object_new_object();
11706 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11707 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11708 json_object_free(json_no);
11709 }
11710 else
11711 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11712 return NULL;
11713 }
11714 }
11715 return peer;
11716 }
11717
11718 /* Peer structure lookup. */
11719 peer = peer_lookup (bgp, &su);
11720 if (! peer)
11721 {
11722 if (use_json)
11723 {
11724 json_object *json_no = NULL;
11725 json_no = json_object_new_object();
11726 json_object_string_add(json_no, "warning","No such neighbor");
11727 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11728 json_object_free(json_no);
11729 }
11730 else
11731 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11732 return NULL;
11733 }
11734
11735 return peer;
11736 }
11737
11738 enum bgp_stats
11739 {
11740 BGP_STATS_MAXBITLEN = 0,
11741 BGP_STATS_RIB,
11742 BGP_STATS_PREFIXES,
11743 BGP_STATS_TOTPLEN,
11744 BGP_STATS_UNAGGREGATEABLE,
11745 BGP_STATS_MAX_AGGREGATEABLE,
11746 BGP_STATS_AGGREGATES,
11747 BGP_STATS_SPACE,
11748 BGP_STATS_ASPATH_COUNT,
11749 BGP_STATS_ASPATH_MAXHOPS,
11750 BGP_STATS_ASPATH_TOTHOPS,
11751 BGP_STATS_ASPATH_MAXSIZE,
11752 BGP_STATS_ASPATH_TOTSIZE,
11753 BGP_STATS_ASN_HIGHEST,
11754 BGP_STATS_MAX,
11755 };
11756
11757 static const char *table_stats_strs[] =
11758 {
11759 [BGP_STATS_PREFIXES] = "Total Prefixes",
11760 [BGP_STATS_TOTPLEN] = "Average prefix length",
11761 [BGP_STATS_RIB] = "Total Advertisements",
11762 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11763 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11764 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11765 [BGP_STATS_SPACE] = "Address space advertised",
11766 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11767 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11768 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11769 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11770 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11771 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11772 [BGP_STATS_MAX] = NULL,
11773 };
11774
11775 struct bgp_table_stats
11776 {
11777 struct bgp_table *table;
11778 unsigned long long counts[BGP_STATS_MAX];
11779 };
11780
11781 #if 0
11782 #define TALLY_SIGFIG 100000
11783 static unsigned long
11784 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11785 {
11786 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11787 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11788 unsigned long ret = newtot / count;
11789
11790 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11791 return ret + 1;
11792 else
11793 return ret;
11794 }
11795 #endif
11796
11797 static int
11798 bgp_table_stats_walker (struct thread *t)
11799 {
11800 struct bgp_node *rn;
11801 struct bgp_node *top;
11802 struct bgp_table_stats *ts = THREAD_ARG (t);
11803 unsigned int space = 0;
11804
11805 if (!(top = bgp_table_top (ts->table)))
11806 return 0;
11807
11808 switch (top->p.family)
11809 {
11810 case AF_INET:
11811 space = IPV4_MAX_BITLEN;
11812 break;
11813 case AF_INET6:
11814 space = IPV6_MAX_BITLEN;
11815 break;
11816 }
11817
11818 ts->counts[BGP_STATS_MAXBITLEN] = space;
11819
11820 for (rn = top; rn; rn = bgp_route_next (rn))
11821 {
11822 struct bgp_info *ri;
11823 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11824 unsigned int rinum = 0;
11825
11826 if (rn == top)
11827 continue;
11828
11829 if (!rn->info)
11830 continue;
11831
11832 ts->counts[BGP_STATS_PREFIXES]++;
11833 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11834
11835 #if 0
11836 ts->counts[BGP_STATS_AVGPLEN]
11837 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11838 ts->counts[BGP_STATS_AVGPLEN],
11839 rn->p.prefixlen);
11840 #endif
11841
11842 /* check if the prefix is included by any other announcements */
11843 while (prn && !prn->info)
11844 prn = bgp_node_parent_nolock (prn);
11845
11846 if (prn == NULL || prn == top)
11847 {
11848 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11849 /* announced address space */
11850 if (space)
11851 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11852 }
11853 else if (prn->info)
11854 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11855
11856 for (ri = rn->info; ri; ri = ri->next)
11857 {
11858 rinum++;
11859 ts->counts[BGP_STATS_RIB]++;
11860
11861 if (ri->attr &&
11862 (CHECK_FLAG (ri->attr->flag,
11863 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11864 ts->counts[BGP_STATS_AGGREGATES]++;
11865
11866 /* as-path stats */
11867 if (ri->attr && ri->attr->aspath)
11868 {
11869 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11870 unsigned int size = aspath_size (ri->attr->aspath);
11871 as_t highest = aspath_highest (ri->attr->aspath);
11872
11873 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11874
11875 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11876 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11877
11878 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11879 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11880
11881 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11882 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11883 #if 0
11884 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11885 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11886 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11887 hops);
11888 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11889 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11890 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11891 size);
11892 #endif
11893 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11894 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11895 }
11896 }
11897 }
11898 return 0;
11899 }
11900
11901 static int
11902 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11903 {
11904 struct bgp_table_stats ts;
11905 unsigned int i;
11906
11907 if (!bgp->rib[afi][safi])
11908 {
11909 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11910 afi, safi, VTY_NEWLINE);
11911 return CMD_WARNING;
11912 }
11913
11914 memset (&ts, 0, sizeof (ts));
11915 ts.table = bgp->rib[afi][safi];
11916 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11917
11918 vty_out (vty, "BGP %s RIB statistics%s%s",
11919 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11920
11921 for (i = 0; i < BGP_STATS_MAX; i++)
11922 {
11923 if (!table_stats_strs[i])
11924 continue;
11925
11926 switch (i)
11927 {
11928 #if 0
11929 case BGP_STATS_ASPATH_AVGHOPS:
11930 case BGP_STATS_ASPATH_AVGSIZE:
11931 case BGP_STATS_AVGPLEN:
11932 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11933 vty_out (vty, "%12.2f",
11934 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11935 break;
11936 #endif
11937 case BGP_STATS_ASPATH_TOTHOPS:
11938 case BGP_STATS_ASPATH_TOTSIZE:
11939 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11940 vty_out (vty, "%12.2f",
11941 ts.counts[i] ?
11942 (float)ts.counts[i] /
11943 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11944 : 0);
11945 break;
11946 case BGP_STATS_TOTPLEN:
11947 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11948 vty_out (vty, "%12.2f",
11949 ts.counts[i] ?
11950 (float)ts.counts[i] /
11951 (float)ts.counts[BGP_STATS_PREFIXES]
11952 : 0);
11953 break;
11954 case BGP_STATS_SPACE:
11955 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11956 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11957 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11958 break;
11959 vty_out (vty, "%30s: ", "%% announced ");
11960 vty_out (vty, "%12.2f%s",
11961 100 * (float)ts.counts[BGP_STATS_SPACE] /
11962 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11963 VTY_NEWLINE);
11964 vty_out (vty, "%30s: ", "/8 equivalent ");
11965 vty_out (vty, "%12.2f%s",
11966 (float)ts.counts[BGP_STATS_SPACE] /
11967 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11968 VTY_NEWLINE);
11969 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11970 break;
11971 vty_out (vty, "%30s: ", "/24 equivalent ");
11972 vty_out (vty, "%12.2f",
11973 (float)ts.counts[BGP_STATS_SPACE] /
11974 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11975 break;
11976 default:
11977 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11978 vty_out (vty, "%12llu", ts.counts[i]);
11979 }
11980
11981 vty_out (vty, "%s", VTY_NEWLINE);
11982 }
11983 return CMD_SUCCESS;
11984 }
11985
11986 static int
11987 bgp_table_stats_vty (struct vty *vty, const char *name,
11988 const char *afi_str, const char *safi_str)
11989 {
11990 struct bgp *bgp;
11991 afi_t afi;
11992 safi_t safi;
11993
11994 if (name)
11995 bgp = bgp_lookup_by_name (name);
11996 else
11997 bgp = bgp_get_default ();
11998
11999 if (!bgp)
12000 {
12001 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
12002 return CMD_WARNING;
12003 }
12004 if (strncmp (afi_str, "ipv", 3) == 0)
12005 {
12006 if (strncmp (afi_str, "ipv4", 4) == 0)
12007 afi = AFI_IP;
12008 else if (strncmp (afi_str, "ipv6", 4) == 0)
12009 afi = AFI_IP6;
12010 else
12011 {
12012 vty_out (vty, "%% Invalid address family %s%s",
12013 afi_str, VTY_NEWLINE);
12014 return CMD_WARNING;
12015 }
12016 if (strncmp (safi_str, "m", 1) == 0)
12017 safi = SAFI_MULTICAST;
12018 else if (strncmp (safi_str, "u", 1) == 0)
12019 safi = SAFI_UNICAST;
12020 else if (strncmp (safi_str, "e", 1) == 0)
12021 safi = SAFI_ENCAP;
12022 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
12023 safi = SAFI_MPLS_VPN;
12024 else
12025 {
12026 vty_out (vty, "%% Invalid subsequent address family %s%s",
12027 safi_str, VTY_NEWLINE);
12028 return CMD_WARNING;
12029 }
12030 }
12031 else
12032 {
12033 vty_out (vty, "%% Invalid address family \"%s\"%s",
12034 afi_str, VTY_NEWLINE);
12035 return CMD_WARNING;
12036 }
12037
12038 return bgp_table_stats (vty, bgp, afi, safi);
12039 }
12040
12041 DEFUN (show_bgp_statistics,
12042 show_bgp_statistics_cmd,
12043 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
12044 SHOW_STR
12045 BGP_STR
12046 "Address family\n"
12047 "Address family\n"
12048 "Address Family modifier\n"
12049 "Address Family modifier\n"
12050 "Address Family modifier\n"
12051 "Address Family modifier\n"
12052 "BGP RIB advertisement statistics\n")
12053 {
12054 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12055 }
12056
12057 DEFUN (show_bgp_statistics_view,
12058 show_bgp_statistics_view_cmd,
12059 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics",
12060 SHOW_STR
12061 BGP_STR
12062 BGP_INSTANCE_HELP_STR
12063 "Address family\n"
12064 "Address family\n"
12065 "Address Family modifier\n"
12066 "Address Family modifier\n"
12067 "Address Family modifier\n"
12068 "Address Family modifier\n"
12069 "BGP RIB advertisement statistics\n")
12070 {
12071 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
12072 }
12073
12074 enum bgp_pcounts
12075 {
12076 PCOUNT_ADJ_IN = 0,
12077 PCOUNT_DAMPED,
12078 PCOUNT_REMOVED,
12079 PCOUNT_HISTORY,
12080 PCOUNT_STALE,
12081 PCOUNT_VALID,
12082 PCOUNT_ALL,
12083 PCOUNT_COUNTED,
12084 PCOUNT_PFCNT, /* the figure we display to users */
12085 PCOUNT_MAX,
12086 };
12087
12088 static const char *pcount_strs[] =
12089 {
12090 [PCOUNT_ADJ_IN] = "Adj-in",
12091 [PCOUNT_DAMPED] = "Damped",
12092 [PCOUNT_REMOVED] = "Removed",
12093 [PCOUNT_HISTORY] = "History",
12094 [PCOUNT_STALE] = "Stale",
12095 [PCOUNT_VALID] = "Valid",
12096 [PCOUNT_ALL] = "All RIB",
12097 [PCOUNT_COUNTED] = "PfxCt counted",
12098 [PCOUNT_PFCNT] = "Useable",
12099 [PCOUNT_MAX] = NULL,
12100 };
12101
12102 struct peer_pcounts
12103 {
12104 unsigned int count[PCOUNT_MAX];
12105 const struct peer *peer;
12106 const struct bgp_table *table;
12107 };
12108
12109 static int
12110 bgp_peer_count_walker (struct thread *t)
12111 {
12112 struct bgp_node *rn;
12113 struct peer_pcounts *pc = THREAD_ARG (t);
12114 const struct peer *peer = pc->peer;
12115
12116 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
12117 {
12118 struct bgp_adj_in *ain;
12119 struct bgp_info *ri;
12120
12121 for (ain = rn->adj_in; ain; ain = ain->next)
12122 if (ain->peer == peer)
12123 pc->count[PCOUNT_ADJ_IN]++;
12124
12125 for (ri = rn->info; ri; ri = ri->next)
12126 {
12127 char buf[SU_ADDRSTRLEN];
12128
12129 if (ri->peer != peer)
12130 continue;
12131
12132 pc->count[PCOUNT_ALL]++;
12133
12134 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
12135 pc->count[PCOUNT_DAMPED]++;
12136 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
12137 pc->count[PCOUNT_HISTORY]++;
12138 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
12139 pc->count[PCOUNT_REMOVED]++;
12140 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
12141 pc->count[PCOUNT_STALE]++;
12142 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
12143 pc->count[PCOUNT_VALID]++;
12144 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12145 pc->count[PCOUNT_PFCNT]++;
12146
12147 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12148 {
12149 pc->count[PCOUNT_COUNTED]++;
12150 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12151 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
12152 peer->host,
12153 inet_ntop(rn->p.family, &rn->p.u.prefix,
12154 buf, SU_ADDRSTRLEN),
12155 rn->p.prefixlen,
12156 ri->flags);
12157 }
12158 else
12159 {
12160 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12161 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
12162 peer->host,
12163 inet_ntop(rn->p.family, &rn->p.u.prefix,
12164 buf, SU_ADDRSTRLEN),
12165 rn->p.prefixlen,
12166 ri->flags);
12167 }
12168 }
12169 }
12170 return 0;
12171 }
12172
12173 static int
12174 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
12175 {
12176 struct peer_pcounts pcounts = { .peer = peer };
12177 unsigned int i;
12178 json_object *json = NULL;
12179 json_object *json_loop = NULL;
12180
12181 if (use_json)
12182 {
12183 json = json_object_new_object();
12184 json_loop = json_object_new_object();
12185 }
12186
12187 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12188 || !peer->bgp->rib[afi][safi])
12189 {
12190 if (use_json)
12191 {
12192 json_object_string_add(json, "warning", "No such neighbor or address family");
12193 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12194 json_object_free(json);
12195 }
12196 else
12197 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12198
12199 return CMD_WARNING;
12200 }
12201
12202 memset (&pcounts, 0, sizeof(pcounts));
12203 pcounts.peer = peer;
12204 pcounts.table = peer->bgp->rib[afi][safi];
12205
12206 /* in-place call via thread subsystem so as to record execution time
12207 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12208 * * on just vty_read()).
12209 * */
12210 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12211
12212 if (use_json)
12213 {
12214 json_object_string_add(json, "prefixCountsFor", peer->host);
12215 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12216 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12217
12218 for (i = 0; i < PCOUNT_MAX; i++)
12219 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12220
12221 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12222
12223 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12224 {
12225 json_object_string_add(json, "pfxctDriftFor", peer->host);
12226 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12227 }
12228 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12229 json_object_free(json);
12230 }
12231 else
12232 {
12233
12234 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12235 {
12236 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12237 peer->hostname, peer->host, afi_safi_print (afi, safi),
12238 VTY_NEWLINE);
12239 }
12240 else
12241 {
12242 vty_out (vty, "Prefix counts for %s, %s%s",
12243 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12244 }
12245
12246 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12247 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12248 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12249
12250 for (i = 0; i < PCOUNT_MAX; i++)
12251 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12252
12253 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12254 {
12255 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12256 peer->host, VTY_NEWLINE);
12257 vty_out (vty, "Please report this bug, with the above command output%s",
12258 VTY_NEWLINE);
12259 }
12260 }
12261
12262 return CMD_SUCCESS;
12263 }
12264
12265 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12266 show_ip_bgp_neighbor_prefix_counts_cmd,
12267 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12268 SHOW_STR
12269 IP_STR
12270 BGP_STR
12271 "Detailed information on TCP and BGP neighbor connections\n"
12272 "Neighbor to display information about\n"
12273 "Neighbor to display information about\n"
12274 "Neighbor on bgp configured interface\n"
12275 "Display detailed prefix count information\n"
12276 "JavaScript Object Notation\n")
12277 {
12278 struct peer *peer;
12279 u_char uj = use_json(argc, argv);
12280
12281 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12282 if (! peer)
12283 return CMD_WARNING;
12284
12285 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12286 }
12287
12288 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12289 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12290 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12291 SHOW_STR
12292 IP_STR
12293 BGP_STR
12294 BGP_INSTANCE_HELP_STR
12295 "Detailed information on TCP and BGP neighbor connections\n"
12296 "Neighbor to display information about\n"
12297 "Neighbor to display information about\n"
12298 "Neighbor on bgp configured interface\n"
12299 "Display detailed prefix count information\n"
12300 "JavaScript Object Notation\n")
12301 {
12302 struct peer *peer;
12303 u_char uj = use_json(argc, argv);
12304
12305 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12306 if (! peer)
12307 return CMD_WARNING;
12308
12309 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12310 }
12311
12312 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12313 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12314 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12315 SHOW_STR
12316 BGP_STR
12317 "Address family\n"
12318 "Detailed information on TCP and BGP neighbor connections\n"
12319 "Neighbor to display information about\n"
12320 "Neighbor to display information about\n"
12321 "Neighbor on bgp configured interface\n"
12322 "Display detailed prefix count information\n"
12323 "JavaScript Object Notation\n")
12324 {
12325 struct peer *peer;
12326 u_char uj = use_json(argc, argv);
12327
12328 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12329 if (! peer)
12330 return CMD_WARNING;
12331
12332 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12333 }
12334
12335 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12336 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12337 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12338 SHOW_STR
12339 BGP_STR
12340 BGP_INSTANCE_HELP_STR
12341 "Address family\n"
12342 "Detailed information on TCP and BGP neighbor connections\n"
12343 "Neighbor to display information about\n"
12344 "Neighbor to display information about\n"
12345 "Neighbor on bgp configured interface\n"
12346 "Display detailed prefix count information\n"
12347 "JavaScript Object Notation\n")
12348 {
12349 struct peer *peer;
12350 u_char uj = use_json(argc, argv);
12351
12352 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12353 if (! peer)
12354 return CMD_WARNING;
12355
12356 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12357 }
12358
12359 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12360 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12361 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12362 SHOW_STR
12363 IP_STR
12364 BGP_STR
12365 "Address family\n"
12366 "Address Family modifier\n"
12367 "Address Family modifier\n"
12368 "Detailed information on TCP and BGP neighbor connections\n"
12369 "Neighbor to display information about\n"
12370 "Neighbor to display information about\n"
12371 "Neighbor on bgp configured interface\n"
12372 "Display detailed prefix count information\n"
12373 "JavaScript Object Notation\n")
12374 {
12375 struct peer *peer;
12376 u_char uj = use_json(argc, argv);
12377
12378 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12379 if (! peer)
12380 return CMD_WARNING;
12381
12382 if (strncmp (argv[0], "m", 1) == 0)
12383 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
12384
12385 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12386 }
12387
12388 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12389 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12390 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12391 SHOW_STR
12392 IP_STR
12393 BGP_STR
12394 "Address family\n"
12395 "Address Family modifier\n"
12396 "Address Family modifier\n"
12397 "Detailed information on TCP and BGP neighbor connections\n"
12398 "Neighbor to display information about\n"
12399 "Neighbor to display information about\n"
12400 "Neighbor on bgp configured interface\n"
12401 "Display detailed prefix count information\n"
12402 "JavaScript Object Notation\n")
12403 {
12404 struct peer *peer;
12405 u_char uj = use_json(argc, argv);
12406
12407 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12408 if (! peer)
12409 return CMD_WARNING;
12410
12411 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
12412 }
12413
12414 static void
12415 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12416 int in, const char *rmap_name, u_char use_json, json_object *json)
12417 {
12418 struct bgp_table *table;
12419 struct bgp_adj_in *ain;
12420 struct bgp_adj_out *adj;
12421 unsigned long output_count;
12422 unsigned long filtered_count;
12423 struct bgp_node *rn;
12424 int header1 = 1;
12425 struct bgp *bgp;
12426 int header2 = 1;
12427 struct attr attr;
12428 struct attr_extra extra;
12429 int ret;
12430 struct update_subgroup *subgrp;
12431 json_object *json_scode = NULL;
12432 json_object *json_ocode = NULL;
12433 json_object *json_ar = NULL;
12434 struct peer_af *paf;
12435
12436 if (use_json)
12437 {
12438 json_scode = json_object_new_object();
12439 json_ocode = json_object_new_object();
12440 json_ar = json_object_new_object();
12441
12442 json_object_string_add(json_scode, "suppressed", "s");
12443 json_object_string_add(json_scode, "damped", "d");
12444 json_object_string_add(json_scode, "history", "h");
12445 json_object_string_add(json_scode, "valid", "*");
12446 json_object_string_add(json_scode, "best", ">");
12447 json_object_string_add(json_scode, "multipath", "=");
12448 json_object_string_add(json_scode, "internal", "i");
12449 json_object_string_add(json_scode, "ribFailure", "r");
12450 json_object_string_add(json_scode, "stale", "S");
12451 json_object_string_add(json_scode, "removed", "R");
12452
12453 json_object_string_add(json_ocode, "igp", "i");
12454 json_object_string_add(json_ocode, "egp", "e");
12455 json_object_string_add(json_ocode, "incomplete", "?");
12456 }
12457
12458 bgp = peer->bgp;
12459
12460 if (! bgp)
12461 {
12462 if (use_json)
12463 {
12464 json_object_string_add(json, "alert", "no BGP");
12465 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12466 json_object_free(json);
12467 }
12468 else
12469 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12470 return;
12471 }
12472
12473 table = bgp->rib[afi][safi];
12474
12475 output_count = filtered_count = 0;
12476 subgrp = peer_subgroup(peer, afi, safi);
12477
12478 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12479 {
12480 if (use_json)
12481 {
12482 json_object_int_add(json, "bgpTableVersion", table->version);
12483 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12484 json_object_object_add(json, "bgpStatusCodes", json_scode);
12485 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12486 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12487 }
12488 else
12489 {
12490 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12491 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12492 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12493
12494 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12495 VTY_NEWLINE, VTY_NEWLINE);
12496 }
12497 header1 = 0;
12498 }
12499
12500 attr.extra = &extra;
12501 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12502 {
12503 if (in)
12504 {
12505 for (ain = rn->adj_in; ain; ain = ain->next)
12506 {
12507 if (ain->peer == peer)
12508 {
12509 if (header1)
12510 {
12511 if (use_json)
12512 {
12513 json_object_int_add(json, "bgpTableVersion", 0);
12514 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12515 json_object_object_add(json, "bgpStatusCodes", json_scode);
12516 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12517 }
12518 else
12519 {
12520 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12521 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12522 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12523 }
12524 header1 = 0;
12525 }
12526 if (header2)
12527 {
12528 if (!use_json)
12529 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12530 header2 = 0;
12531 }
12532 if (ain->attr)
12533 {
12534 bgp_attr_dup(&attr, ain->attr);
12535 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12536 {
12537 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12538 output_count++;
12539 }
12540 else
12541 filtered_count++;
12542 }
12543 }
12544 }
12545 }
12546 else
12547 {
12548 for (adj = rn->adj_out; adj; adj = adj->next)
12549 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12550 if (paf->peer == peer)
12551 {
12552 if (header1)
12553 {
12554 if (use_json)
12555 {
12556 json_object_int_add(json, "bgpTableVersion", table->version);
12557 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12558 json_object_object_add(json, "bgpStatusCodes", json_scode);
12559 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12560 }
12561 else
12562 {
12563 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12564 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12565 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12566 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12567 }
12568 header1 = 0;
12569 }
12570
12571 if (header2)
12572 {
12573 if (!use_json)
12574 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12575 header2 = 0;
12576 }
12577
12578 if (adj->attr)
12579 {
12580 bgp_attr_dup(&attr, adj->attr);
12581 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12582 if (ret != RMAP_DENY)
12583 {
12584 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12585 output_count++;
12586 }
12587 else
12588 filtered_count++;
12589 }
12590 }
12591 }
12592 }
12593 if (use_json)
12594 json_object_object_add(json, "advertisedRoutes", json_ar);
12595
12596 if (output_count != 0)
12597 {
12598 if (use_json)
12599 json_object_int_add(json, "totalPrefixCounter", output_count);
12600 else
12601 vty_out (vty, "%sTotal number of prefixes %ld%s",
12602 VTY_NEWLINE, output_count, VTY_NEWLINE);
12603 }
12604 if (use_json)
12605 {
12606 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12607 json_object_free(json);
12608 }
12609
12610 }
12611
12612 static int
12613 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12614 int in, const char *rmap_name, u_char use_json)
12615 {
12616 json_object *json = NULL;
12617
12618 if (use_json)
12619 json = json_object_new_object();
12620
12621 if (!peer || !peer->afc[afi][safi])
12622 {
12623 if (use_json)
12624 {
12625 json_object_string_add(json, "warning", "No such neighbor or address family");
12626 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12627 json_object_free(json);
12628 }
12629 else
12630 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12631
12632 return CMD_WARNING;
12633 }
12634
12635 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12636 {
12637 if (use_json)
12638 {
12639 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12640 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12641 json_object_free(json);
12642 }
12643 else
12644 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12645
12646 return CMD_WARNING;
12647 }
12648
12649 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12650
12651 return CMD_SUCCESS;
12652 }
12653
12654 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12655 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12656 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12657 SHOW_STR
12658 IP_STR
12659 BGP_STR
12660 BGP_INSTANCE_HELP_STR
12661 "Detailed information on TCP and BGP neighbor connections\n"
12662 "Neighbor to display information about\n"
12663 "Neighbor to display information about\n"
12664 "Display the routes advertised to a BGP neighbor\n"
12665 "JavaScript Object Notation\n")
12666 {
12667 struct peer *peer;
12668 u_char uj = use_json(argc, argv);
12669
12670 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12671 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12672 else
12673 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12674
12675 if (! peer)
12676 return CMD_WARNING;
12677
12678 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12679 }
12680
12681 DEFUN (show_ip_bgp_neighbor_advertised_route,
12682 show_ip_bgp_neighbor_advertised_route_cmd,
12683 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12684 SHOW_STR
12685 IP_STR
12686 BGP_STR
12687 "Detailed information on TCP and BGP neighbor connections\n"
12688 "Neighbor to display information about\n"
12689 "Neighbor to display information about\n"
12690 "Neighbor on bgp configured interface\n"
12691 "Display the routes advertised to a BGP neighbor\n"
12692 "JavaScript Object Notation\n")
12693
12694 {
12695 struct peer *peer;
12696 const char *rmap_name = NULL;
12697 u_char uj = use_json(argc, argv);
12698
12699 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12700
12701 if (! peer)
12702 return CMD_WARNING;
12703
12704 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12705 || (argc == 3))
12706 rmap_name = argv[1];
12707
12708 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12709 }
12710
12711 ALIAS (show_ip_bgp_neighbor_advertised_route,
12712 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12713 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12714 SHOW_STR
12715 IP_STR
12716 BGP_STR
12717 "Detailed information on TCP and BGP neighbor connections\n"
12718 "Neighbor to display information about\n"
12719 "Neighbor to display information about\n"
12720 "Neighbor on bgp configured interface\n"
12721 "Display the routes advertised to a BGP neighbor\n"
12722 "JavaScript Object Notation\n")
12723
12724 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12725 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12726 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12727 SHOW_STR
12728 IP_STR
12729 BGP_STR
12730 BGP_INSTANCE_HELP_STR
12731 "Detailed information on TCP and BGP neighbor connections\n"
12732 "Neighbor to display information about\n"
12733 "Neighbor to display information about\n"
12734 "Neighbor on bgp configured interface\n"
12735 "Display the routes advertised to a BGP neighbor\n"
12736 "JavaScript Object Notation\n")
12737 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12738 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12739 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12740 SHOW_STR
12741 IP_STR
12742 BGP_STR
12743 "Address family\n"
12744 "Address Family modifier\n"
12745 "Address Family modifier\n"
12746 "Detailed information on TCP and BGP neighbor connections\n"
12747 "Neighbor to display information about\n"
12748 "Neighbor to display information about\n"
12749 "Neighbor on bgp configured interface\n"
12750 "Display the routes advertised to a BGP neighbor\n"
12751 "JavaScript Object Notation\n")
12752 {
12753 struct peer *peer;
12754 const char *rmap_name = NULL;
12755 u_char uj = use_json(argc, argv);
12756
12757 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12758 if (! peer)
12759 return CMD_WARNING;
12760
12761 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12762 rmap_name = argv[2];
12763
12764 if (strncmp (argv[0], "m", 1) == 0)
12765 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
12766 else
12767 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12768 }
12769
12770 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12771 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12772 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12773 SHOW_STR
12774 IP_STR
12775 BGP_STR
12776 "Address family\n"
12777 "Address Family modifier\n"
12778 "Address Family modifier\n"
12779 "Detailed information on TCP and BGP neighbor connections\n"
12780 "Neighbor to display information about\n"
12781 "Neighbor to display information about\n"
12782 "Neighbor on bgp configured interface\n"
12783 "Display the routes advertised to a BGP neighbor\n"
12784 "Route-map to control what is displayed\n"
12785 "JavaScript Object Notation\n")
12786
12787 #ifdef HAVE_IPV6
12788 DEFUN (show_bgp_instance_neighbor_advertised_route,
12789 show_bgp_instance_neighbor_advertised_route_cmd,
12790 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12791 SHOW_STR
12792 BGP_STR
12793 BGP_INSTANCE_HELP_STR
12794 "Detailed information on TCP and BGP neighbor connections\n"
12795 "Neighbor to display information about\n"
12796 "Neighbor to display information about\n"
12797 "Neighbor on bgp configured interface\n"
12798 "Display the routes advertised to a BGP neighbor\n"
12799 "JavaScript Object Notation\n")
12800 {
12801 struct peer *peer;
12802 u_char uj = use_json(argc, argv);
12803
12804 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12805 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12806 else
12807 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12808
12809 if (! peer)
12810 return CMD_WARNING;
12811
12812 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12813 }
12814
12815 ALIAS (show_bgp_instance_neighbor_advertised_route,
12816 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12817 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12818 SHOW_STR
12819 BGP_STR
12820 BGP_INSTANCE_HELP_STR
12821 "Address family\n"
12822 "Detailed information on TCP and BGP neighbor connections\n"
12823 "Neighbor to display information about\n"
12824 "Neighbor to display information about\n"
12825 "Neighbor on bgp configured interface\n"
12826 "Display the routes advertised to a BGP neighbor\n"
12827 "JavaScript Object Notation\n")
12828
12829 DEFUN (show_bgp_neighbor_advertised_route,
12830 show_bgp_neighbor_advertised_route_cmd,
12831 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12832 SHOW_STR
12833 BGP_STR
12834 "Detailed information on TCP and BGP neighbor connections\n"
12835 "Neighbor to display information about\n"
12836 "Neighbor to display information about\n"
12837 "Neighbor on bgp configured interface\n"
12838 "Display the routes advertised to a BGP neighbor\n"
12839 "JavaScript Object Notation\n")
12840
12841 {
12842 struct peer *peer;
12843 const char *rmap_name = NULL;
12844 u_char uj = use_json(argc, argv);
12845
12846 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12847
12848 if (!peer)
12849 return CMD_WARNING;
12850
12851 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12852 rmap_name = argv[1];
12853
12854 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12855 }
12856
12857 ALIAS (show_bgp_neighbor_advertised_route,
12858 show_bgp_ipv6_neighbor_advertised_route_cmd,
12859 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12860 SHOW_STR
12861 BGP_STR
12862 "Address family\n"
12863 "Detailed information on TCP and BGP neighbor connections\n"
12864 "Neighbor to display information about\n"
12865 "Neighbor to display information about\n"
12866 "Neighbor on bgp configured interface\n"
12867 "Display the routes advertised to a BGP neighbor\n"
12868 "JavaScript Object Notation\n")
12869
12870 /* old command */
12871 ALIAS (show_bgp_neighbor_advertised_route,
12872 ipv6_bgp_neighbor_advertised_route_cmd,
12873 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12874 SHOW_STR
12875 IPV6_STR
12876 BGP_STR
12877 "Detailed information on TCP and BGP neighbor connections\n"
12878 "Neighbor to display information about\n"
12879 "Neighbor to display information about\n"
12880 "Neighbor on bgp configured interface\n"
12881 "Display the routes advertised to a BGP neighbor\n"
12882 "JavaScript Object Notation\n")
12883
12884 /* old command */
12885 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12886 ipv6_mbgp_neighbor_advertised_route_cmd,
12887 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12888 SHOW_STR
12889 IPV6_STR
12890 MBGP_STR
12891 "Detailed information on TCP and BGP neighbor connections\n"
12892 "Neighbor to display information about\n"
12893 "Neighbor to display information about\n"
12894 "Neighbor on bgp configured interface\n"
12895 "Neighbor on bgp configured interface\n"
12896 "Display the routes advertised to a BGP neighbor\n"
12897 "JavaScript Object Notation\n")
12898 {
12899 struct peer *peer;
12900 u_char uj = use_json(argc, argv);
12901
12902 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12903 if (! peer)
12904 return CMD_WARNING;
12905
12906 bgp_show_ipv6_bgp_deprecate_warning(vty);
12907 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12908 }
12909 #endif /* HAVE_IPV6 */
12910
12911 DEFUN (show_bgp_instance_neighbor_received_routes,
12912 show_bgp_instance_neighbor_received_routes_cmd,
12913 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12914 SHOW_STR
12915 BGP_STR
12916 BGP_INSTANCE_HELP_STR
12917 "Detailed information on TCP and BGP neighbor connections\n"
12918 "Neighbor to display information about\n"
12919 "Neighbor to display information about\n"
12920 "Neighbor on bgp configured interface\n"
12921 "Display the received routes from neighbor\n"
12922 "JavaScript Object Notation\n")
12923 {
12924 struct peer *peer;
12925 u_char uj = use_json(argc, argv);
12926
12927 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12928 if (! peer)
12929 return CMD_WARNING;
12930
12931 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12932 }
12933
12934 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12935 show_ip_bgp_instance_neighbor_received_routes_cmd,
12936 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12937 SHOW_STR
12938 IP_STR
12939 BGP_STR
12940 BGP_INSTANCE_HELP_STR
12941 "Detailed information on TCP and BGP neighbor connections\n"
12942 "Neighbor to display information about\n"
12943 "Neighbor to display information about\n"
12944 "Neighbor on bgp configured interface\n"
12945 "Display the received routes from neighbor\n"
12946 "JavaScript Object Notation\n")
12947 {
12948 struct peer *peer;
12949 u_char uj = use_json(argc, argv);
12950
12951 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12952 if (! peer)
12953 return CMD_WARNING;
12954
12955 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12956 }
12957
12958 ALIAS (show_bgp_instance_neighbor_received_routes,
12959 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12960 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12961 SHOW_STR
12962 BGP_STR
12963 BGP_INSTANCE_HELP_STR
12964 "Address family\n"
12965 "Detailed information on TCP and BGP neighbor connections\n"
12966 "Neighbor to display information about\n"
12967 "Neighbor to display information about\n"
12968 "Neighbor on bgp configured interface\n"
12969 "Display the received routes from neighbor\n"
12970 "JavaScript Object Notation\n")
12971
12972 DEFUN (show_ip_bgp_neighbor_received_routes,
12973 show_ip_bgp_neighbor_received_routes_cmd,
12974 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12975 SHOW_STR
12976 IP_STR
12977 BGP_STR
12978 "Detailed information on TCP and BGP neighbor connections\n"
12979 "Neighbor to display information about\n"
12980 "Neighbor to display information about\n"
12981 "Neighbor on bgp configured interface\n"
12982 "Display the received routes from neighbor\n"
12983 "JavaScript Object Notation\n")
12984
12985 {
12986 struct peer *peer;
12987 const char *rmap_name = NULL;
12988 u_char uj = use_json(argc, argv);
12989
12990 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12991
12992 if (! peer)
12993 return CMD_WARNING;
12994
12995 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12996 rmap_name = argv[1];
12997
12998 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12999 }
13000
13001 ALIAS (show_ip_bgp_neighbor_received_routes,
13002 show_ip_bgp_neighbor_received_routes_rmap_cmd,
13003 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
13004 SHOW_STR
13005 IP_STR
13006 BGP_STR
13007 "Detailed information on TCP and BGP neighbor connections\n"
13008 "Neighbor to display information about\n"
13009 "Neighbor to display information about\n"
13010 "Neighbor on bgp configured interface\n"
13011 "Display the received routes from neighbor\n"
13012 "JavaScript Object Notation\n")
13013
13014 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
13015 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
13016 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
13017 SHOW_STR
13018 IP_STR
13019 BGP_STR
13020 BGP_INSTANCE_HELP_STR
13021 "Detailed information on TCP and BGP neighbor connections\n"
13022 "Neighbor to display information about\n"
13023 "Neighbor to display information about\n"
13024 "Neighbor on bgp configured interface\n"
13025 "Display the received routes from neighbor\n"
13026 "JavaScript Object Notation\n")
13027
13028 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
13029 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
13030 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13031 SHOW_STR
13032 IP_STR
13033 BGP_STR
13034 "Address family\n"
13035 "Address Family modifier\n"
13036 "Address Family modifier\n"
13037 "Detailed information on TCP and BGP neighbor connections\n"
13038 "Neighbor to display information about\n"
13039 "Neighbor to display information about\n"
13040 "Neighbor on bgp configured interface\n"
13041 "Display the received routes from neighbor\n"
13042 "JavaScript Object Notation\n")
13043 {
13044 struct peer *peer;
13045 const char *rmap_name = NULL;
13046 u_char uj = use_json(argc, argv);
13047
13048 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13049 if (! peer)
13050 return CMD_WARNING;
13051
13052 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13053 rmap_name = argv[2];
13054
13055 if (strncmp (argv[0], "m", 1) == 0)
13056 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
13057 else
13058 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
13059 }
13060
13061 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
13062 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
13063 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
13064 SHOW_STR
13065 IP_STR
13066 BGP_STR
13067 "Address family\n"
13068 "Address Family modifier\n"
13069 "Address Family modifier\n"
13070 "Detailed information on TCP and BGP neighbor connections\n"
13071 "Neighbor to display information about\n"
13072 "Neighbor to display information about\n"
13073 "Neighbor on bgp configured interface\n"
13074 "Display the received routes from neighbor\n"
13075 "JavaScript Object Notation\n")
13076
13077 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
13078 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
13079 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
13080 SHOW_STR
13081 BGP_STR
13082 BGP_INSTANCE_HELP_STR
13083 "Address family\n"
13084 "Address family\n"
13085 "Address family modifier\n"
13086 "Address family modifier\n"
13087 "Detailed information on TCP and BGP neighbor connections\n"
13088 "Neighbor to display information about\n"
13089 "Neighbor to display information about\n"
13090 "Neighbor on bgp configured interface\n"
13091 "Display the advertised routes to neighbor\n"
13092 "Display the received routes from neighbor\n"
13093 "JavaScript Object Notation\n")
13094 {
13095 int afi;
13096 int safi;
13097 int in;
13098 struct peer *peer;
13099 u_char uj = use_json(argc, argv);
13100
13101 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
13102
13103 if (! peer)
13104 return CMD_WARNING;
13105
13106 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13107 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13108 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
13109
13110 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
13111 }
13112
13113 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13114 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13115 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13116 SHOW_STR
13117 IP_STR
13118 BGP_STR
13119 "Detailed information on TCP and BGP neighbor connections\n"
13120 "Neighbor to display information about\n"
13121 "Neighbor to display information about\n"
13122 "Neighbor on bgp configured interface\n"
13123 "Display information received from a BGP neighbor\n"
13124 "Display the prefixlist filter\n"
13125 "JavaScript Object Notation\n")
13126 {
13127 char name[BUFSIZ];
13128 union sockunion su;
13129 struct peer *peer;
13130 int count, ret;
13131 u_char uj = use_json(argc, argv);
13132
13133 ret = str2sockunion (argv[0], &su);
13134 if (ret < 0)
13135 {
13136 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13137 if (! peer)
13138 {
13139 if (uj)
13140 {
13141 json_object *json_no = NULL;
13142 json_object *json_sub = NULL;
13143 json_no = json_object_new_object();
13144 json_sub = json_object_new_object();
13145 json_object_string_add(json_no, "warning", "Malformed address or name");
13146 json_object_string_add(json_sub, "warningCause", argv[0]);
13147 json_object_object_add(json_no, "detail", json_sub);
13148 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13149 json_object_free(json_no);
13150 }
13151 else
13152 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13153 return CMD_WARNING;
13154 }
13155 }
13156 else
13157 {
13158 peer = peer_lookup (NULL, &su);
13159 if (! peer)
13160 {
13161 if (uj)
13162 {
13163 json_object *json_no = NULL;
13164 json_no = json_object_new_object();
13165 json_object_string_add(json_no, "warning", "Peer not found");
13166 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13167 json_object_free(json_no);
13168 }
13169 else
13170 vty_out (vty, "No peer%s", VTY_NEWLINE);
13171 return CMD_WARNING;
13172 }
13173 }
13174
13175 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13176 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13177 if (count)
13178 {
13179 if (!uj)
13180 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13181 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13182 }
13183 else
13184 {
13185 if (uj)
13186 {
13187 json_object *json_no = NULL;
13188 json_no = json_object_new_object();
13189 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13190 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13191 json_object_free(json_no);
13192 }
13193 else
13194 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13195 }
13196
13197 return CMD_SUCCESS;
13198 }
13199
13200 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13201 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13202 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13203 SHOW_STR
13204 IP_STR
13205 BGP_STR
13206 "Address family\n"
13207 "Address Family modifier\n"
13208 "Address Family modifier\n"
13209 "Detailed information on TCP and BGP neighbor connections\n"
13210 "Neighbor to display information about\n"
13211 "Neighbor to display information about\n"
13212 "Neighbor on bgp configured interface\n"
13213 "Display information received from a BGP neighbor\n"
13214 "Display the prefixlist filter\n"
13215 "JavaScript Object Notation\n")
13216 {
13217 char name[BUFSIZ];
13218 union sockunion su;
13219 struct peer *peer;
13220 int count, ret;
13221 u_char uj = use_json(argc, argv);
13222
13223 ret = str2sockunion (argv[1], &su);
13224 if (ret < 0)
13225 {
13226 peer = peer_lookup_by_conf_if (NULL, argv[1]);
13227 if (! peer)
13228 {
13229 if (uj)
13230 {
13231 json_object *json_no = NULL;
13232 json_object *json_sub = NULL;
13233 json_no = json_object_new_object();
13234 json_sub = json_object_new_object();
13235 json_object_string_add(json_no, "warning", "Malformed address or name");
13236 json_object_string_add(json_sub, "warningCause", argv[1]);
13237 json_object_object_add(json_no, "detail", json_sub);
13238 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13239 json_object_free(json_no);
13240 }
13241 else
13242 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
13243 return CMD_WARNING;
13244 }
13245 }
13246 else
13247 {
13248 peer = peer_lookup (NULL, &su);
13249 if (! peer)
13250 {
13251 if (uj)
13252 {
13253 json_object *json_no = NULL;
13254 json_no = json_object_new_object();
13255 json_object_string_add(json_no, "warning", "Peer not found");
13256 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13257 json_object_free(json_no);
13258 }
13259 else
13260 vty_out (vty, "No peer%s", VTY_NEWLINE);
13261 return CMD_WARNING;
13262 }
13263 }
13264
13265 if (strncmp (argv[0], "m", 1) == 0)
13266 {
13267 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13268 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13269 if (count)
13270 {
13271 if (!uj)
13272 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13273 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13274 }
13275 else
13276 {
13277 if (uj)
13278 {
13279 json_object *json_no = NULL;
13280 json_no = json_object_new_object();
13281 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13282 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13283 json_object_free(json_no);
13284 }
13285 else
13286 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13287 }
13288 }
13289 else
13290 {
13291 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13292 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13293 if (count)
13294 {
13295 if (!uj)
13296 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13297 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13298 }
13299 else
13300 {
13301 if (uj)
13302 {
13303 json_object *json_no = NULL;
13304 json_no = json_object_new_object();
13305 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13306 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13307 json_object_free(json_no);
13308 }
13309 else
13310 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13311 }
13312 }
13313
13314 return CMD_SUCCESS;
13315 }
13316 #ifdef HAVE_IPV6
13317 DEFUN (show_bgp_neighbor_received_routes,
13318 show_bgp_neighbor_received_routes_cmd,
13319 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13320 SHOW_STR
13321 BGP_STR
13322 "Detailed information on TCP and BGP neighbor connections\n"
13323 "Neighbor to display information about\n"
13324 "Neighbor to display information about\n"
13325 "Neighbor on bgp configured interface\n"
13326 "Display the received routes from neighbor\n"
13327 "JavaScript Object Notation\n")
13328 {
13329 struct peer *peer;
13330 const char *rmap_name = NULL;
13331 u_char uj = use_json(argc, argv);
13332
13333 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13334
13335 if (! peer)
13336 return CMD_WARNING;
13337
13338 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13339 rmap_name = argv[1];
13340
13341 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13342 }
13343
13344 ALIAS (show_bgp_neighbor_received_routes,
13345 show_bgp_ipv6_neighbor_received_routes_cmd,
13346 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13347 SHOW_STR
13348 BGP_STR
13349 "Address family\n"
13350 "Detailed information on TCP and BGP neighbor connections\n"
13351 "Neighbor to display information about\n"
13352 "Neighbor to display information about\n"
13353 "Neighbor on bgp configured interface\n"
13354 "Display the received routes from neighbor\n"
13355 "JavaScript Object Notation\n")
13356
13357 DEFUN (show_bgp_neighbor_received_prefix_filter,
13358 show_bgp_neighbor_received_prefix_filter_cmd,
13359 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13360 SHOW_STR
13361 BGP_STR
13362 "Detailed information on TCP and BGP neighbor connections\n"
13363 "Neighbor to display information about\n"
13364 "Neighbor to display information about\n"
13365 "Neighbor on bgp configured interface\n"
13366 "Display information received from a BGP neighbor\n"
13367 "Display the prefixlist filter\n"
13368 "JavaScript Object Notation\n")
13369 {
13370 char name[BUFSIZ];
13371 union sockunion su;
13372 struct peer *peer;
13373 int count, ret;
13374 u_char uj = use_json(argc, argv);
13375
13376 ret = str2sockunion (argv[0], &su);
13377 if (ret < 0)
13378 {
13379 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13380 if (! peer)
13381 {
13382 if (uj)
13383 {
13384 json_object *json_no = NULL;
13385 json_object *json_sub = NULL;
13386 json_no = json_object_new_object();
13387 json_sub = json_object_new_object();
13388 json_object_string_add(json_no, "warning", "Malformed address or name");
13389 json_object_string_add(json_sub, "warningCause", argv[0]);
13390 json_object_object_add(json_no, "detail", json_sub);
13391 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13392 json_object_free(json_no);
13393 }
13394 else
13395 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13396 return CMD_WARNING;
13397 }
13398 }
13399 else
13400 {
13401 peer = peer_lookup (NULL, &su);
13402 if (! peer)
13403 {
13404 if (uj)
13405 {
13406 json_object *json_no = NULL;
13407 json_no = json_object_new_object();
13408 json_object_string_add(json_no, "warning", "No Peer");
13409 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13410 json_object_free(json_no);
13411 }
13412 else
13413 vty_out (vty, "No peer%s", VTY_NEWLINE);
13414 return CMD_WARNING;
13415 }
13416 }
13417
13418 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13419 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13420 if (count)
13421 {
13422 if (!uj)
13423 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13424 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13425 }
13426 else
13427 {
13428 if (uj)
13429 {
13430 json_object *json_no = NULL;
13431 json_no = json_object_new_object();
13432 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13433 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13434 json_object_free(json_no);
13435 }
13436 else
13437 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13438 }
13439
13440 return CMD_SUCCESS;
13441 }
13442
13443 ALIAS (show_bgp_neighbor_received_prefix_filter,
13444 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13445 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13446 SHOW_STR
13447 BGP_STR
13448 "Address family\n"
13449 "Detailed information on TCP and BGP neighbor connections\n"
13450 "Neighbor to display information about\n"
13451 "Neighbor to display information about\n"
13452 "Neighbor on bgp configured interface\n"
13453 "Display information received from a BGP neighbor\n"
13454 "Display the prefixlist filter\n"
13455 "JavaScript Object Notation\n")
13456
13457 /* old command */
13458 ALIAS (show_bgp_neighbor_received_routes,
13459 ipv6_bgp_neighbor_received_routes_cmd,
13460 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13461 SHOW_STR
13462 IPV6_STR
13463 BGP_STR
13464 "Detailed information on TCP and BGP neighbor connections\n"
13465 "Neighbor to display information about\n"
13466 "Neighbor to display information about\n"
13467 "Neighbor on bgp configured interface\n"
13468 "Display the received routes from neighbor\n"
13469 "JavaScript Object Notation\n")
13470
13471 /* old command */
13472 DEFUN (ipv6_mbgp_neighbor_received_routes,
13473 ipv6_mbgp_neighbor_received_routes_cmd,
13474 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13475 SHOW_STR
13476 IPV6_STR
13477 MBGP_STR
13478 "Detailed information on TCP and BGP neighbor connections\n"
13479 "Neighbor to display information about\n"
13480 "Neighbor to display information about\n"
13481 "Neighbor on bgp configured interface\n"
13482 "Display the received routes from neighbor\n"
13483 "JavaScript Object Notation\n")
13484 {
13485 struct peer *peer;
13486 u_char uj = use_json(argc, argv);
13487
13488 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13489 if (! peer)
13490 return CMD_WARNING;
13491
13492 bgp_show_ipv6_bgp_deprecate_warning(vty);
13493 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13494 }
13495
13496 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13497 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13498 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13499 SHOW_STR
13500 BGP_STR
13501 BGP_INSTANCE_HELP_STR
13502 "Detailed information on TCP and BGP neighbor connections\n"
13503 "Neighbor to display information about\n"
13504 "Neighbor to display information about\n"
13505 "Neighbor on bgp configured interface\n"
13506 "Display information received from a BGP neighbor\n"
13507 "Display the prefixlist filter\n"
13508 "JavaScript Object Notation\n")
13509 {
13510 char name[BUFSIZ];
13511 union sockunion su;
13512 struct peer *peer;
13513 struct bgp *bgp;
13514 int count, ret;
13515 u_char uj = use_json(argc, argv);
13516
13517 /* BGP structure lookup. */
13518 bgp = bgp_lookup_by_name (argv[1]);
13519 if (bgp == NULL)
13520 {
13521 if (uj)
13522 {
13523 json_object *json_no = NULL;
13524 json_no = json_object_new_object();
13525 json_object_string_add(json_no, "warning", "Can't find BGP view");
13526 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13527 json_object_free(json_no);
13528 }
13529 else
13530 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13531 return CMD_WARNING;
13532 }
13533
13534 ret = str2sockunion (argv[2], &su);
13535 if (ret < 0)
13536 {
13537 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13538 if (! peer)
13539 {
13540 if (uj)
13541 {
13542 json_object *json_no = NULL;
13543 json_object *json_sub = NULL;
13544 json_no = json_object_new_object();
13545 json_sub = json_object_new_object();
13546 json_object_string_add(json_no, "warning", "Malformed address or name");
13547 json_object_string_add(json_sub, "warningCause", argv[2]);
13548 json_object_object_add(json_no, "detail", json_sub);
13549 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13550 json_object_free(json_no);
13551 }
13552 else
13553 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13554 return CMD_WARNING;
13555 }
13556 }
13557 else
13558 {
13559 peer = peer_lookup (bgp, &su);
13560 if (! peer)
13561 {
13562 if (uj)
13563 {
13564 json_object *json_no = NULL;
13565 json_no = json_object_new_object();
13566 json_object_boolean_true_add(json_no, "noPeer");
13567 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13568 json_object_free(json_no);
13569 }
13570 else
13571 vty_out (vty, "No peer%s", VTY_NEWLINE);
13572 return CMD_WARNING;
13573 }
13574
13575 }
13576
13577 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13578 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13579 if (count)
13580 {
13581 if (!uj)
13582 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13583 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13584 }
13585
13586 return CMD_SUCCESS;
13587 }
13588 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13589 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13590 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13591 SHOW_STR
13592 BGP_STR
13593 BGP_INSTANCE_HELP_STR
13594 "Address family\n"
13595 "Detailed information on TCP and BGP neighbor connections\n"
13596 "Neighbor to display information about\n"
13597 "Neighbor to display information about\n"
13598 "Neighbor on bgp configured interface\n"
13599 "Display information received from a BGP neighbor\n"
13600 "Display the prefixlist filter\n"
13601 "JavaScript Object NOtation\n")
13602 #endif /* HAVE_IPV6 */
13603
13604 static int
13605 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13606 safi_t safi, enum bgp_show_type type, u_char use_json)
13607 {
13608 if (! peer || ! peer->afc[afi][safi])
13609 {
13610 if (use_json)
13611 {
13612 json_object *json_no = NULL;
13613 json_no = json_object_new_object();
13614 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13615 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13616 json_object_free(json_no);
13617 }
13618 else
13619 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13620 return CMD_WARNING;
13621 }
13622
13623 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13624 }
13625
13626 DEFUN (show_ip_bgp_neighbor_routes,
13627 show_ip_bgp_neighbor_routes_cmd,
13628 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13629 SHOW_STR
13630 IP_STR
13631 BGP_STR
13632 "Detailed information on TCP and BGP neighbor connections\n"
13633 "Neighbor to display information about\n"
13634 "Neighbor to display information about\n"
13635 "Neighbor on bgp configured interface\n"
13636 "Display routes learned from neighbor\n"
13637 "JavaScript Object Notation\n")
13638 {
13639 struct peer *peer;
13640 u_char uj = use_json(argc, argv);
13641
13642 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13643 if (! peer)
13644 return CMD_WARNING;
13645
13646 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13647 bgp_show_type_neighbor, uj);
13648 }
13649
13650 DEFUN (show_ip_bgp_instance_neighbor_routes,
13651 show_ip_bgp_instance_neighbor_routes_cmd,
13652 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13653 SHOW_STR
13654 IP_STR
13655 BGP_STR
13656 BGP_INSTANCE_HELP_STR
13657 "Detailed information on TCP and BGP neighbor connections\n"
13658 "Neighbor to display information about\n"
13659 "Neighbor to display information about\n"
13660 "Neighbor on bgp configured interface\n"
13661 "Display routes learned from neighbor\n"
13662 "JavaScript Object Notation\n")
13663 {
13664 struct peer *peer;
13665 u_char uj = use_json(argc, argv);
13666
13667 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13668 if (! peer)
13669 return CMD_WARNING;
13670
13671 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13672 bgp_show_type_neighbor, uj);
13673 }
13674
13675 DEFUN (show_ip_bgp_neighbor_flap,
13676 show_ip_bgp_neighbor_flap_cmd,
13677 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13678 SHOW_STR
13679 IP_STR
13680 BGP_STR
13681 "Detailed information on TCP and BGP neighbor connections\n"
13682 "Neighbor to display information about\n"
13683 "Neighbor to display information about\n"
13684 "Neighbor on bgp configured interface\n"
13685 "Display flap statistics of the routes learned from neighbor\n"
13686 "JavaScript Object Notation\n")
13687 {
13688 struct peer *peer;
13689 u_char uj = use_json(argc, argv);
13690
13691 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13692 if (! peer)
13693 return CMD_WARNING;
13694
13695 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13696 bgp_show_type_flap_neighbor, uj);
13697 }
13698
13699 DEFUN (show_ip_bgp_neighbor_damp,
13700 show_ip_bgp_neighbor_damp_cmd,
13701 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13702 SHOW_STR
13703 IP_STR
13704 BGP_STR
13705 "Detailed information on TCP and BGP neighbor connections\n"
13706 "Neighbor to display information about\n"
13707 "Neighbor to display information about\n"
13708 "Neighbor on bgp configured interface\n"
13709 "Display the dampened routes received from neighbor\n"
13710 "JavaScript Object Notation\n")
13711 {
13712 struct peer *peer;
13713 u_char uj = use_json(argc, argv);
13714
13715 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13716 if (! peer)
13717 return CMD_WARNING;
13718
13719 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13720 bgp_show_type_damp_neighbor, uj);
13721 }
13722
13723 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13724 show_ip_bgp_ipv4_neighbor_routes_cmd,
13725 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13726 SHOW_STR
13727 IP_STR
13728 BGP_STR
13729 "Address family\n"
13730 "Address Family modifier\n"
13731 "Address Family modifier\n"
13732 "Detailed information on TCP and BGP neighbor connections\n"
13733 "Neighbor to display information about\n"
13734 "Neighbor to display information about\n"
13735 "Neighbor on bgp configured interface\n"
13736 "Display routes learned from neighbor\n"
13737 "JavaScript Object Notation\n")
13738 {
13739 struct peer *peer;
13740 u_char uj = use_json(argc, argv);
13741
13742 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13743 if (! peer)
13744 return CMD_WARNING;
13745
13746 if (strncmp (argv[0], "m", 1) == 0)
13747 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13748 bgp_show_type_neighbor, uj);
13749
13750 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13751 bgp_show_type_neighbor, uj);
13752 }
13753
13754 #ifdef HAVE_IPV6
13755 DEFUN (show_bgp_instance_neighbor_routes,
13756 show_bgp_instance_neighbor_routes_cmd,
13757 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13758 SHOW_STR
13759 BGP_STR
13760 BGP_INSTANCE_HELP_STR
13761 "Detailed information on TCP and BGP neighbor connections\n"
13762 "Neighbor to display information about\n"
13763 "Neighbor to display information about\n"
13764 "Neighbor on bgp configured interface\n"
13765 "Display routes learned from neighbor\n"
13766 "JavaScript Object Notation\n")
13767 {
13768 struct peer *peer;
13769 u_char uj = use_json(argc, argv);
13770
13771 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13772 if (! peer)
13773 return CMD_WARNING;
13774
13775 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13776 bgp_show_type_neighbor, uj);
13777 }
13778
13779 ALIAS (show_bgp_instance_neighbor_routes,
13780 show_bgp_instance_ipv6_neighbor_routes_cmd,
13781 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13782 SHOW_STR
13783 BGP_STR
13784 BGP_INSTANCE_HELP_STR
13785 "Address family\n"
13786 "Detailed information on TCP and BGP neighbor connections\n"
13787 "Neighbor to display information about\n"
13788 "Neighbor to display information about\n"
13789 "Neighbor on bgp configured interface\n"
13790 "Display routes learned from neighbor\n"
13791 "JavaScript Object Notation\n")
13792
13793 DEFUN (show_bgp_instance_neighbor_damp,
13794 show_bgp_instance_neighbor_damp_cmd,
13795 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13796 SHOW_STR
13797 BGP_STR
13798 BGP_INSTANCE_HELP_STR
13799 "Detailed information on TCP and BGP neighbor connections\n"
13800 "Neighbor to display information about\n"
13801 "Neighbor to display information about\n"
13802 "Neighbor on bgp configured interface\n"
13803 "Display the dampened routes received from neighbor\n"
13804 "JavaScript Object Notation\n")
13805 {
13806 struct peer *peer;
13807 u_char uj = use_json(argc, argv);
13808
13809 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13810 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13811 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13812 else
13813 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13814
13815 if (! peer)
13816 return CMD_WARNING;
13817
13818 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13819 bgp_show_type_damp_neighbor, uj);
13820 }
13821
13822 ALIAS (show_bgp_instance_neighbor_damp,
13823 show_bgp_instance_ipv6_neighbor_damp_cmd,
13824 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13825 SHOW_STR
13826 BGP_STR
13827 BGP_INSTANCE_HELP_STR
13828 "Address family\n"
13829 "Detailed information on TCP and BGP neighbor connections\n"
13830 "Neighbor to display information about\n"
13831 "Neighbor to display information about\n"
13832 "Neighbor on bgp configured interface\n"
13833 "Display the dampened routes received from neighbor\n"
13834 "JavaScript Object Notation\n")
13835
13836 DEFUN (show_bgp_instance_neighbor_flap,
13837 show_bgp_instance_neighbor_flap_cmd,
13838 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13839 SHOW_STR
13840 BGP_STR
13841 BGP_INSTANCE_HELP_STR
13842 "Detailed information on TCP and BGP neighbor connections\n"
13843 "Neighbor to display information about\n"
13844 "Neighbor to display information about\n"
13845 "Neighbor on bgp configured interface\n"
13846 "Display flap statistics of the routes learned from neighbor\n"
13847 "JavaScript Object Notation\n")
13848 {
13849 struct peer *peer;
13850 u_char uj = use_json(argc, argv);
13851
13852 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13853 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13854 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13855 else
13856 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13857
13858 if (! peer)
13859 return CMD_WARNING;
13860
13861 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13862 bgp_show_type_flap_neighbor, uj);
13863 }
13864
13865 ALIAS (show_bgp_instance_neighbor_flap,
13866 show_bgp_instance_ipv6_neighbor_flap_cmd,
13867 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13868 SHOW_STR
13869 BGP_STR
13870 BGP_INSTANCE_HELP_STR
13871 "Address family\n"
13872 "Detailed information on TCP and BGP neighbor connections\n"
13873 "Neighbor to display information about\n"
13874 "Neighbor to display information about\n"
13875 "Neighbor on bgp configured interface\n"
13876 "Display flap statistics of the routes learned from neighbor\n"
13877 "JavaScript Object Notation\n")
13878
13879 DEFUN (show_bgp_neighbor_routes,
13880 show_bgp_neighbor_routes_cmd,
13881 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13882 SHOW_STR
13883 BGP_STR
13884 "Detailed information on TCP and BGP neighbor connections\n"
13885 "Neighbor to display information about\n"
13886 "Neighbor to display information about\n"
13887 "Neighbor on bgp configured interface\n"
13888 "Display routes learned from neighbor\n"
13889 "JavaScript Object Notation\n")
13890 {
13891 struct peer *peer;
13892 u_char uj = use_json(argc, argv);
13893
13894 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13895 if (! peer)
13896 return CMD_WARNING;
13897
13898 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13899 bgp_show_type_neighbor, uj);
13900 }
13901
13902
13903 ALIAS (show_bgp_neighbor_routes,
13904 show_bgp_ipv6_neighbor_routes_cmd,
13905 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13906 SHOW_STR
13907 BGP_STR
13908 "Address family\n"
13909 "Detailed information on TCP and BGP neighbor connections\n"
13910 "Neighbor to display information about\n"
13911 "Neighbor to display information about\n"
13912 "Neighbor on bgp configured interface\n"
13913 "Display routes learned from neighbor\n"
13914 "JavaScript Object Notation\n")
13915
13916 /* old command */
13917 ALIAS (show_bgp_neighbor_routes,
13918 ipv6_bgp_neighbor_routes_cmd,
13919 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13920 SHOW_STR
13921 IPV6_STR
13922 BGP_STR
13923 "Detailed information on TCP and BGP neighbor connections\n"
13924 "Neighbor to display information about\n"
13925 "Neighbor to display information about\n"
13926 "Neighbor on bgp configured interface\n"
13927 "Display routes learned from neighbor\n"
13928 "JavaScript Object Notation\n")
13929
13930 /* old command */
13931 DEFUN (ipv6_mbgp_neighbor_routes,
13932 ipv6_mbgp_neighbor_routes_cmd,
13933 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13934 SHOW_STR
13935 IPV6_STR
13936 MBGP_STR
13937 "Detailed information on TCP and BGP neighbor connections\n"
13938 "Neighbor to display information about\n"
13939 "Neighbor to display information about\n"
13940 "Neighbor on bgp configured interface\n"
13941 "Display routes learned from neighbor\n"
13942 "JavaScript Object Notation\n")
13943 {
13944 struct peer *peer;
13945 u_char uj = use_json(argc, argv);
13946
13947 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13948 if (! peer)
13949 return CMD_WARNING;
13950
13951 bgp_show_ipv6_bgp_deprecate_warning(vty);
13952 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13953 bgp_show_type_neighbor, uj);
13954 }
13955
13956 ALIAS (show_bgp_instance_neighbor_flap,
13957 show_bgp_neighbor_flap_cmd,
13958 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13959 SHOW_STR
13960 BGP_STR
13961 "Detailed information on TCP and BGP neighbor connections\n"
13962 "Neighbor to display information about\n"
13963 "Neighbor to display information about\n"
13964 "Neighbor on bgp configured interface\n"
13965 "Display flap statistics of the routes learned from neighbor\n"
13966 "JavaScript Object Notation\n")
13967
13968 ALIAS (show_bgp_instance_neighbor_flap,
13969 show_bgp_ipv6_neighbor_flap_cmd,
13970 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13971 SHOW_STR
13972 BGP_STR
13973 "Address family\n"
13974 "Detailed information on TCP and BGP neighbor connections\n"
13975 "Neighbor to display information about\n"
13976 "Neighbor to display information about\n"
13977 "Neighbor on bgp configured interface\n"
13978 "Display flap statistics of the routes learned from neighbor\n"
13979 "JavaScript Object Notation\n")
13980
13981 ALIAS (show_bgp_instance_neighbor_damp,
13982 show_bgp_neighbor_damp_cmd,
13983 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13984 SHOW_STR
13985 BGP_STR
13986 "Detailed information on TCP and BGP neighbor connections\n"
13987 "Neighbor to display information about\n"
13988 "Neighbor to display information about\n"
13989 "Neighbor on bgp configured interface\n"
13990 "Display the dampened routes received from neighbor\n"
13991 "JavaScript Object Notation\n")
13992
13993 ALIAS (show_bgp_instance_neighbor_damp,
13994 show_bgp_ipv6_neighbor_damp_cmd,
13995 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13996 SHOW_STR
13997 BGP_STR
13998 "Address family\n"
13999 "Detailed information on TCP and BGP neighbor connections\n"
14000 "Neighbor to display information about\n"
14001 "Neighbor to display information about\n"
14002 "Neighbor on bgp configured interface\n"
14003 "Display the dampened routes received from neighbor\n"
14004 "JavaScript Object Notation\n")
14005
14006 #endif /* HAVE_IPV6 */
14007
14008 struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
14009
14010 struct bgp_distance
14011 {
14012 /* Distance value for the IP source prefix. */
14013 u_char distance;
14014
14015 /* Name of the access-list to be matched. */
14016 char *access_list;
14017 };
14018
14019 static struct bgp_distance *
14020 bgp_distance_new (void)
14021 {
14022 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
14023 }
14024
14025 static void
14026 bgp_distance_free (struct bgp_distance *bdistance)
14027 {
14028 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14029 }
14030
14031 static int
14032 bgp_distance_set (struct vty *vty, const char *distance_str,
14033 const char *ip_str, const char *access_list_str)
14034 {
14035 int ret;
14036 afi_t afi;
14037 safi_t safi;
14038 struct prefix p;
14039 u_char distance;
14040 struct bgp_node *rn;
14041 struct bgp_distance *bdistance;
14042
14043 afi = bgp_node_afi (vty);
14044 safi = bgp_node_safi (vty);
14045
14046 ret = str2prefix (ip_str, &p);
14047 if (ret == 0)
14048 {
14049 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14050 return CMD_WARNING;
14051 }
14052
14053 distance = atoi (distance_str);
14054
14055 /* Get BGP distance node. */
14056 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
14057 if (rn->info)
14058 {
14059 bdistance = rn->info;
14060 bgp_unlock_node (rn);
14061 }
14062 else
14063 {
14064 bdistance = bgp_distance_new ();
14065 rn->info = bdistance;
14066 }
14067
14068 /* Set distance value. */
14069 bdistance->distance = distance;
14070
14071 /* Reset access-list configuration. */
14072 if (bdistance->access_list)
14073 {
14074 XFREE(MTYPE_AS_LIST, bdistance->access_list);
14075 bdistance->access_list = NULL;
14076 }
14077 if (access_list_str)
14078 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
14079
14080 return CMD_SUCCESS;
14081 }
14082
14083 static int
14084 bgp_distance_unset (struct vty *vty, const char *distance_str,
14085 const char *ip_str, const char *access_list_str)
14086 {
14087 int ret;
14088 afi_t afi;
14089 safi_t safi;
14090 struct prefix p;
14091 int distance;
14092 struct bgp_node *rn;
14093 struct bgp_distance *bdistance;
14094
14095 afi = bgp_node_afi (vty);
14096 safi = bgp_node_safi (vty);
14097
14098 ret = str2prefix (ip_str, &p);
14099 if (ret == 0)
14100 {
14101 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14102 return CMD_WARNING;
14103 }
14104
14105 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
14106 if (! rn)
14107 {
14108 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14109 return CMD_WARNING;
14110 }
14111
14112 bdistance = rn->info;
14113 distance = atoi(distance_str);
14114
14115 if (bdistance->distance != distance)
14116 {
14117 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
14118 return CMD_WARNING;
14119 }
14120
14121 if (bdistance->access_list)
14122 XFREE(MTYPE_AS_LIST, bdistance->access_list);
14123 bgp_distance_free (bdistance);
14124
14125 rn->info = NULL;
14126 bgp_unlock_node (rn);
14127 bgp_unlock_node (rn);
14128
14129 return CMD_SUCCESS;
14130 }
14131
14132 /* Apply BGP information to distance method. */
14133 u_char
14134 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
14135 safi_t safi, struct bgp *bgp)
14136 {
14137 struct bgp_node *rn;
14138 struct prefix q;
14139 struct peer *peer;
14140 struct bgp_distance *bdistance;
14141 struct access_list *alist;
14142 struct bgp_static *bgp_static;
14143
14144 if (! bgp)
14145 return 0;
14146
14147 peer = rinfo->peer;
14148
14149 /* Check source address. */
14150 sockunion2hostprefix (&peer->su, &q);
14151 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
14152 if (rn)
14153 {
14154 bdistance = rn->info;
14155 bgp_unlock_node (rn);
14156
14157 if (bdistance->access_list)
14158 {
14159 alist = access_list_lookup (afi, bdistance->access_list);
14160 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
14161 return bdistance->distance;
14162 }
14163 else
14164 return bdistance->distance;
14165 }
14166
14167 /* Backdoor check. */
14168 rn = bgp_node_lookup (bgp->route[afi][safi], p);
14169 if (rn)
14170 {
14171 bgp_static = rn->info;
14172 bgp_unlock_node (rn);
14173
14174 if (bgp_static->backdoor)
14175 {
14176 if (bgp->distance_local[afi][safi])
14177 return bgp->distance_local[afi][safi];
14178 else
14179 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14180 }
14181 }
14182
14183 if (peer->sort == BGP_PEER_EBGP)
14184 {
14185 if (bgp->distance_ebgp[afi][safi])
14186 return bgp->distance_ebgp[afi][safi];
14187 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14188 }
14189 else
14190 {
14191 if (bgp->distance_ibgp[afi][safi])
14192 return bgp->distance_ibgp[afi][safi];
14193 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14194 }
14195 }
14196
14197 DEFUN (bgp_distance,
14198 bgp_distance_cmd,
14199 "distance bgp <1-255> <1-255> <1-255>",
14200 "Define an administrative distance\n"
14201 "BGP distance\n"
14202 "Distance for routes external to the AS\n"
14203 "Distance for routes internal to the AS\n"
14204 "Distance for local routes\n")
14205 {
14206 struct bgp *bgp;
14207 afi_t afi;
14208 safi_t safi;
14209
14210 bgp = vty->index;
14211 afi = bgp_node_afi (vty);
14212 safi = bgp_node_safi (vty);
14213
14214 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
14215 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
14216 bgp->distance_local[afi][safi] = atoi (argv[2]);
14217 return CMD_SUCCESS;
14218 }
14219
14220 DEFUN (no_bgp_distance,
14221 no_bgp_distance_cmd,
14222 "no distance bgp <1-255> <1-255> <1-255>",
14223 NO_STR
14224 "Define an administrative distance\n"
14225 "BGP distance\n"
14226 "Distance for routes external to the AS\n"
14227 "Distance for routes internal to the AS\n"
14228 "Distance for local routes\n")
14229 {
14230 struct bgp *bgp;
14231 afi_t afi;
14232 safi_t safi;
14233
14234 bgp = vty->index;
14235 afi = bgp_node_afi (vty);
14236 safi = bgp_node_safi (vty);
14237
14238 bgp->distance_ebgp[afi][safi] = 0;
14239 bgp->distance_ibgp[afi][safi] = 0;
14240 bgp->distance_local[afi][safi] = 0;
14241 return CMD_SUCCESS;
14242 }
14243
14244 ALIAS (no_bgp_distance,
14245 no_bgp_distance2_cmd,
14246 "no distance bgp",
14247 NO_STR
14248 "Define an administrative distance\n"
14249 "BGP distance\n")
14250
14251 DEFUN (bgp_distance_source,
14252 bgp_distance_source_cmd,
14253 "distance <1-255> A.B.C.D/M",
14254 "Define an administrative distance\n"
14255 "Administrative distance\n"
14256 "IP source prefix\n")
14257 {
14258 bgp_distance_set (vty, argv[0], argv[1], NULL);
14259 return CMD_SUCCESS;
14260 }
14261
14262 DEFUN (no_bgp_distance_source,
14263 no_bgp_distance_source_cmd,
14264 "no distance <1-255> A.B.C.D/M",
14265 NO_STR
14266 "Define an administrative distance\n"
14267 "Administrative distance\n"
14268 "IP source prefix\n")
14269 {
14270 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14271 return CMD_SUCCESS;
14272 }
14273
14274 DEFUN (bgp_distance_source_access_list,
14275 bgp_distance_source_access_list_cmd,
14276 "distance <1-255> A.B.C.D/M WORD",
14277 "Define an administrative distance\n"
14278 "Administrative distance\n"
14279 "IP source prefix\n"
14280 "Access list name\n")
14281 {
14282 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14283 return CMD_SUCCESS;
14284 }
14285
14286 DEFUN (no_bgp_distance_source_access_list,
14287 no_bgp_distance_source_access_list_cmd,
14288 "no distance <1-255> A.B.C.D/M WORD",
14289 NO_STR
14290 "Define an administrative distance\n"
14291 "Administrative distance\n"
14292 "IP source prefix\n"
14293 "Access list name\n")
14294 {
14295 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14296 return CMD_SUCCESS;
14297 }
14298
14299 DEFUN (ipv6_bgp_distance_source,
14300 ipv6_bgp_distance_source_cmd,
14301 "distance <1-255> X:X::X:X/M",
14302 "Define an administrative distance\n"
14303 "Administrative distance\n"
14304 "IP source prefix\n")
14305 {
14306 bgp_distance_set (vty, argv[0], argv[1], NULL);
14307 return CMD_SUCCESS;
14308 }
14309
14310 DEFUN (no_ipv6_bgp_distance_source,
14311 no_ipv6_bgp_distance_source_cmd,
14312 "no distance <1-255> X:X::X:X/M",
14313 NO_STR
14314 "Define an administrative distance\n"
14315 "Administrative distance\n"
14316 "IP source prefix\n")
14317 {
14318 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14319 return CMD_SUCCESS;
14320 }
14321
14322 DEFUN (ipv6_bgp_distance_source_access_list,
14323 ipv6_bgp_distance_source_access_list_cmd,
14324 "distance <1-255> X:X::X:X/M WORD",
14325 "Define an administrative distance\n"
14326 "Administrative distance\n"
14327 "IP source prefix\n"
14328 "Access list name\n")
14329 {
14330 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14331 return CMD_SUCCESS;
14332 }
14333
14334 DEFUN (no_ipv6_bgp_distance_source_access_list,
14335 no_ipv6_bgp_distance_source_access_list_cmd,
14336 "no distance <1-255> X:X::X:X/M WORD",
14337 NO_STR
14338 "Define an administrative distance\n"
14339 "Administrative distance\n"
14340 "IP source prefix\n"
14341 "Access list name\n")
14342 {
14343 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14344 return CMD_SUCCESS;
14345 }
14346
14347 DEFUN (bgp_damp_set,
14348 bgp_damp_set_cmd,
14349 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14350 "BGP Specific commands\n"
14351 "Enable route-flap dampening\n"
14352 "Half-life time for the penalty\n"
14353 "Value to start reusing a route\n"
14354 "Value to start suppressing a route\n"
14355 "Maximum duration to suppress a stable route\n")
14356 {
14357 struct bgp *bgp;
14358 int half = DEFAULT_HALF_LIFE * 60;
14359 int reuse = DEFAULT_REUSE;
14360 int suppress = DEFAULT_SUPPRESS;
14361 int max = 4 * half;
14362
14363 if (argc == 4)
14364 {
14365 half = atoi (argv[0]) * 60;
14366 reuse = atoi (argv[1]);
14367 suppress = atoi (argv[2]);
14368 max = atoi (argv[3]) * 60;
14369 }
14370 else if (argc == 1)
14371 {
14372 half = atoi (argv[0]) * 60;
14373 max = 4 * half;
14374 }
14375
14376 bgp = vty->index;
14377
14378 if (suppress < reuse)
14379 {
14380 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14381 VTY_NEWLINE);
14382 return 0;
14383 }
14384
14385 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14386 half, reuse, suppress, max);
14387 }
14388
14389 ALIAS (bgp_damp_set,
14390 bgp_damp_set2_cmd,
14391 "bgp dampening <1-45>",
14392 "BGP Specific commands\n"
14393 "Enable route-flap dampening\n"
14394 "Half-life time for the penalty\n")
14395
14396 ALIAS (bgp_damp_set,
14397 bgp_damp_set3_cmd,
14398 "bgp dampening",
14399 "BGP Specific commands\n"
14400 "Enable route-flap dampening\n")
14401
14402 DEFUN (bgp_damp_unset,
14403 bgp_damp_unset_cmd,
14404 "no bgp dampening",
14405 NO_STR
14406 "BGP Specific commands\n"
14407 "Enable route-flap dampening\n")
14408 {
14409 struct bgp *bgp;
14410
14411 bgp = vty->index;
14412 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14413 }
14414
14415 ALIAS (bgp_damp_unset,
14416 bgp_damp_unset2_cmd,
14417 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14418 NO_STR
14419 "BGP Specific commands\n"
14420 "Enable route-flap dampening\n"
14421 "Half-life time for the penalty\n"
14422 "Value to start reusing a route\n"
14423 "Value to start suppressing a route\n"
14424 "Maximum duration to suppress a stable route\n")
14425
14426 ALIAS (bgp_damp_unset,
14427 bgp_damp_unset3_cmd,
14428 "no bgp dampening <1-45>",
14429 NO_STR
14430 "BGP Specific commands\n"
14431 "Enable route-flap dampening\n"
14432 "Half-life time for the penalty\n")
14433
14434 DEFUN (show_ip_bgp_dampened_paths,
14435 show_ip_bgp_dampened_paths_cmd,
14436 "show ip bgp dampened-paths",
14437 SHOW_STR
14438 IP_STR
14439 BGP_STR
14440 "Display paths suppressed due to dampening\n")
14441 {
14442 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14443 NULL, 0);
14444 }
14445
14446 ALIAS (show_ip_bgp_dampened_paths,
14447 show_ip_bgp_damp_dampened_paths_cmd,
14448 "show ip bgp dampening dampened-paths",
14449 SHOW_STR
14450 IP_STR
14451 BGP_STR
14452 "Display detailed information about dampening\n"
14453 "Display paths suppressed due to dampening\n")
14454
14455 DEFUN (show_ip_bgp_flap_statistics,
14456 show_ip_bgp_flap_statistics_cmd,
14457 "show ip bgp flap-statistics",
14458 SHOW_STR
14459 IP_STR
14460 BGP_STR
14461 "Display flap statistics of routes\n")
14462 {
14463 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14464 bgp_show_type_flap_statistics, NULL, 0);
14465 }
14466
14467 ALIAS (show_ip_bgp_flap_statistics,
14468 show_ip_bgp_damp_flap_statistics_cmd,
14469 "show ip bgp dampening flap-statistics",
14470 SHOW_STR
14471 IP_STR
14472 BGP_STR
14473 "Display detailed information about dampening\n"
14474 "Display flap statistics of routes\n")
14475
14476 /* Display specified route of BGP table. */
14477 static int
14478 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14479 const char *ip_str, afi_t afi, safi_t safi,
14480 struct prefix_rd *prd, int prefix_check)
14481 {
14482 int ret;
14483 struct prefix match;
14484 struct bgp_node *rn;
14485 struct bgp_node *rm;
14486 struct bgp_info *ri;
14487 struct bgp_info *ri_temp;
14488 struct bgp *bgp;
14489 struct bgp_table *table;
14490
14491 /* BGP structure lookup. */
14492 if (view_name)
14493 {
14494 bgp = bgp_lookup_by_name (view_name);
14495 if (bgp == NULL)
14496 {
14497 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14498 return CMD_WARNING;
14499 }
14500 }
14501 else
14502 {
14503 bgp = bgp_get_default ();
14504 if (bgp == NULL)
14505 {
14506 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14507 return CMD_WARNING;
14508 }
14509 }
14510
14511 /* Check IP address argument. */
14512 ret = str2prefix (ip_str, &match);
14513 if (! ret)
14514 {
14515 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14516 return CMD_WARNING;
14517 }
14518
14519 match.family = afi2family (afi);
14520
14521 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14522 {
14523 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14524 {
14525 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14526 continue;
14527
14528 if ((table = rn->info) != NULL)
14529 if ((rm = bgp_node_match (table, &match)) != NULL)
14530 {
14531 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14532 {
14533 ri = rm->info;
14534 while (ri)
14535 {
14536 if (ri->extra && ri->extra->damp_info)
14537 {
14538 ri_temp = ri->next;
14539 bgp_damp_info_free (ri->extra->damp_info, 1);
14540 ri = ri_temp;
14541 }
14542 else
14543 ri = ri->next;
14544 }
14545 }
14546
14547 bgp_unlock_node (rm);
14548 }
14549 }
14550 }
14551 else
14552 {
14553 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14554 {
14555 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14556 {
14557 ri = rn->info;
14558 while (ri)
14559 {
14560 if (ri->extra && ri->extra->damp_info)
14561 {
14562 ri_temp = ri->next;
14563 bgp_damp_info_free (ri->extra->damp_info, 1);
14564 ri = ri_temp;
14565 }
14566 else
14567 ri = ri->next;
14568 }
14569 }
14570
14571 bgp_unlock_node (rn);
14572 }
14573 }
14574
14575 return CMD_SUCCESS;
14576 }
14577
14578 DEFUN (clear_ip_bgp_dampening,
14579 clear_ip_bgp_dampening_cmd,
14580 "clear ip bgp dampening",
14581 CLEAR_STR
14582 IP_STR
14583 BGP_STR
14584 "Clear route flap dampening information\n")
14585 {
14586 bgp_damp_info_clean ();
14587 return CMD_SUCCESS;
14588 }
14589
14590 DEFUN (clear_ip_bgp_dampening_prefix,
14591 clear_ip_bgp_dampening_prefix_cmd,
14592 "clear ip bgp dampening A.B.C.D/M",
14593 CLEAR_STR
14594 IP_STR
14595 BGP_STR
14596 "Clear route flap dampening information\n"
14597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14598 {
14599 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14600 SAFI_UNICAST, NULL, 1);
14601 }
14602
14603 DEFUN (clear_ip_bgp_dampening_address,
14604 clear_ip_bgp_dampening_address_cmd,
14605 "clear ip bgp dampening A.B.C.D",
14606 CLEAR_STR
14607 IP_STR
14608 BGP_STR
14609 "Clear route flap dampening information\n"
14610 "Network to clear damping information\n")
14611 {
14612 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14613 SAFI_UNICAST, NULL, 0);
14614 }
14615
14616 DEFUN (clear_ip_bgp_dampening_address_mask,
14617 clear_ip_bgp_dampening_address_mask_cmd,
14618 "clear ip bgp dampening A.B.C.D A.B.C.D",
14619 CLEAR_STR
14620 IP_STR
14621 BGP_STR
14622 "Clear route flap dampening information\n"
14623 "Network to clear damping information\n"
14624 "Network mask\n")
14625 {
14626 int ret;
14627 char prefix_str[BUFSIZ];
14628
14629 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14630 if (! ret)
14631 {
14632 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14633 return CMD_WARNING;
14634 }
14635
14636 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14637 SAFI_UNICAST, NULL, 0);
14638 }
14639
14640 /* also used for encap safi */
14641 static int
14642 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14643 afi_t afi, safi_t safi, int *write)
14644 {
14645 struct bgp_node *prn;
14646 struct bgp_node *rn;
14647 struct bgp_table *table;
14648 struct prefix *p;
14649 struct prefix_rd *prd;
14650 struct bgp_static *bgp_static;
14651 u_int32_t label;
14652 char buf[SU_ADDRSTRLEN];
14653 char rdbuf[RD_ADDRSTRLEN];
14654
14655 /* Network configuration. */
14656 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14657 if ((table = prn->info) != NULL)
14658 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14659 if ((bgp_static = rn->info) != NULL)
14660 {
14661 p = &rn->p;
14662 prd = (struct prefix_rd *) &prn->p;
14663
14664 /* "address-family" display. */
14665 bgp_config_write_family_header (vty, afi, safi, write);
14666
14667 /* "network" configuration display. */
14668 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14669 label = decode_label (bgp_static->tag);
14670
14671 vty_out (vty, " network %s/%d rd %s tag %d",
14672 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14673 p->prefixlen,
14674 rdbuf, label);
14675 vty_out (vty, "%s", VTY_NEWLINE);
14676 }
14677 return 0;
14678 }
14679
14680 /* Configuration of static route announcement and aggregate
14681 information. */
14682 int
14683 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14684 afi_t afi, safi_t safi, int *write)
14685 {
14686 struct bgp_node *rn;
14687 struct prefix *p;
14688 struct bgp_static *bgp_static;
14689 struct bgp_aggregate *bgp_aggregate;
14690 char buf[SU_ADDRSTRLEN];
14691
14692 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14693 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14694
14695 /* Network configuration. */
14696 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14697 if ((bgp_static = rn->info) != NULL)
14698 {
14699 p = &rn->p;
14700
14701 /* "address-family" display. */
14702 bgp_config_write_family_header (vty, afi, safi, write);
14703
14704 /* "network" configuration display. */
14705 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14706 {
14707 u_int32_t destination;
14708 struct in_addr netmask;
14709
14710 destination = ntohl (p->u.prefix4.s_addr);
14711 masklen2ip (p->prefixlen, &netmask);
14712 vty_out (vty, " network %s",
14713 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14714
14715 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14716 || (IN_CLASSB (destination) && p->prefixlen == 16)
14717 || (IN_CLASSA (destination) && p->prefixlen == 8)
14718 || p->u.prefix4.s_addr == 0)
14719 {
14720 /* Natural mask is not display. */
14721 }
14722 else
14723 vty_out (vty, " mask %s", inet_ntoa (netmask));
14724 }
14725 else
14726 {
14727 vty_out (vty, " network %s/%d",
14728 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14729 p->prefixlen);
14730 }
14731
14732 if (bgp_static->rmap.name)
14733 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14734 else
14735 {
14736 if (bgp_static->backdoor)
14737 vty_out (vty, " backdoor");
14738 }
14739
14740 vty_out (vty, "%s", VTY_NEWLINE);
14741 }
14742
14743 /* Aggregate-address configuration. */
14744 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14745 if ((bgp_aggregate = rn->info) != NULL)
14746 {
14747 p = &rn->p;
14748
14749 /* "address-family" display. */
14750 bgp_config_write_family_header (vty, afi, safi, write);
14751
14752 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14753 {
14754 struct in_addr netmask;
14755
14756 masklen2ip (p->prefixlen, &netmask);
14757 vty_out (vty, " aggregate-address %s %s",
14758 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14759 inet_ntoa (netmask));
14760 }
14761 else
14762 {
14763 vty_out (vty, " aggregate-address %s/%d",
14764 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14765 p->prefixlen);
14766 }
14767
14768 if (bgp_aggregate->as_set)
14769 vty_out (vty, " as-set");
14770
14771 if (bgp_aggregate->summary_only)
14772 vty_out (vty, " summary-only");
14773
14774 vty_out (vty, "%s", VTY_NEWLINE);
14775 }
14776
14777 return 0;
14778 }
14779
14780 int
14781 bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14782 safi_t safi, int *write)
14783 {
14784 struct bgp_node *rn;
14785 struct bgp_distance *bdistance;
14786
14787 /* Distance configuration. */
14788 if (bgp->distance_ebgp[afi][safi]
14789 && bgp->distance_ibgp[afi][safi]
14790 && bgp->distance_local[afi][safi]
14791 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14792 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14793 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14794 {
14795 bgp_config_write_family_header (vty, afi, safi, write);
14796 vty_out (vty, " distance bgp %d %d %d%s",
14797 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14798 bgp->distance_local[afi][safi], VTY_NEWLINE);
14799 }
14800
14801 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14802 rn = bgp_route_next (rn))
14803 if ((bdistance = rn->info) != NULL)
14804 {
14805 char buf[PREFIX_STRLEN];
14806
14807 bgp_config_write_family_header (vty, afi, safi, write);
14808 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14809 prefix2str (&rn->p, buf, sizeof (buf)),
14810 bdistance->access_list ? bdistance->access_list : "",
14811 VTY_NEWLINE);
14812 }
14813
14814 return *write;
14815 }
14816
14817 /* Allocate routing table structure and install commands. */
14818 void
14819 bgp_route_init (void)
14820 {
14821 afi_t afi;
14822 safi_t safi;
14823
14824 /* Init BGP distance table. */
14825 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14826 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14827 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
14828
14829 /* IPv4 BGP commands. */
14830 install_element (BGP_NODE, &bgp_table_map_cmd);
14831 install_element (BGP_NODE, &bgp_network_cmd);
14832 install_element (BGP_NODE, &bgp_network_mask_cmd);
14833 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14834 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14835 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14836 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14837 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14838 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14839 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14840 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14841 install_element (BGP_NODE, &no_bgp_network_cmd);
14842 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14843 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14844 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14845 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14846 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14847 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14848 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14849 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14850
14851 install_element (BGP_NODE, &aggregate_address_cmd);
14852 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14853 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14854 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14855 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14856 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14857 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14858 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14859 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14860 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14861 install_element (BGP_NODE, &no_aggregate_address_cmd);
14862 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14863 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14864 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14865 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14866 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14867 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14868 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14869 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14870 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14871
14872 /* IPv4 unicast configuration. */
14873 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14874 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14875 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14876 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14877 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14878 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14879 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14880 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14881 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14882 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14883 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14884 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14885 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14886 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14887
14888 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14889 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14890 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14891 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14892 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14893 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14894 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14895 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14896 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14897 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14898 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14899 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14900 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14901 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14902 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14903 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14904 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14905 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14906 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14907 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14908
14909 /* IPv4 multicast configuration. */
14910 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14911 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14912 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14913 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14914 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14915 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14916 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14917 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14918 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14919 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14920 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14921 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14922 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14923 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14924 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14925 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14926 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14927 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14928 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14929 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14930 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14931 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14932 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14933 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14934 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14935 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14936 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14937 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14938 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14939 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14940 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14941 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14942 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14943 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14944
14945 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14946 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14947 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14948 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14949 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14950 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14951 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14952 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14953 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14954 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14955 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14956 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14957 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14958 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14959 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14960 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14961 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14962 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14963 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14964 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14965 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14966 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14967 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14968 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14969
14970 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14971 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14972 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14973 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14974 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14975 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14976 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14977 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14978 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14979 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14980 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14981 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14982 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14983 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14984 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14985 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14986 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14987 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14988 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14989 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14990 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14991 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14992 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14993 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14994 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14995 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14996 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14997 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14998 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14999 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
15000 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
15001 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
15002 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15003 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15004 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15005 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15006 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
15007 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
15008 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15009 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
15010 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15011 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
15012 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
15013 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15014 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
15015 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
15016 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
15017 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
15018 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
15019 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
15020 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
15021 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
15022 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
15023 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
15024 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
15025 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
15026 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
15027 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
15028 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
15029 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15030 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15031 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15032 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
15033 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
15034 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
15035 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
15036 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
15037 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
15038 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
15039 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
15040 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
15041 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
15042 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
15043 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15044 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
15045 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
15046 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
15047 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
15048 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15049 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
15050 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15051 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
15052 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
15053 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
15054 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
15055 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
15056
15057 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
15058 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
15059 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
15060
15061 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
15062 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
15063
15064 /* BGP dampening clear commands */
15065 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
15066 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
15067 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
15068 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
15069
15070 /* prefix count */
15071 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
15072 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
15073 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
15074 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
15075 #ifdef HAVE_IPV6
15076 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
15077 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
15078
15079 /* New config IPv6 BGP commands. */
15080 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
15081 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
15082 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
15083 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
15084 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
15085 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
15086
15087 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
15088 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
15089 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
15090 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
15091
15092 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
15093 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
15094
15095 /* Old config IPv6 BGP commands. */
15096 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
15097 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
15098
15099 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
15100 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
15101 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
15102 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
15103
15104 install_element (VIEW_NODE, &show_bgp_cmd);
15105 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
15106 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
15107 install_element (VIEW_NODE, &show_bgp_route_cmd);
15108 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
15109 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
15110 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
15111 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15112 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
15113 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
15114 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
15115 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
15116 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
15117 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15118 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
15119 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
15120 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
15121 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
15122 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
15123 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
15124 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
15125 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
15126 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
15127 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
15128 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
15129 install_element (VIEW_NODE, &show_bgp_community_cmd);
15130 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
15131 install_element (VIEW_NODE, &show_bgp_community2_cmd);
15132 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
15133 install_element (VIEW_NODE, &show_bgp_community3_cmd);
15134 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
15135 install_element (VIEW_NODE, &show_bgp_community4_cmd);
15136 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
15137 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
15138 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
15139 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
15140 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
15141 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
15142 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
15143 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
15144 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
15145 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
15146 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
15147 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
15148 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15149 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
15150 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15151 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
15152 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15153 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
15154 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15155 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
15156 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15157 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15158 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
15159 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
15160 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15161 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
15162 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
15163 install_element (VIEW_NODE, &show_bgp_instance_cmd);
15164 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
15165 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
15166 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
15167 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
15168 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
15169 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
15170 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
15171 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
15172 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
15173 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
15174 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
15175 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
15176 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
15177 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
15178 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
15179 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
15180 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
15181 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
15182 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
15183 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
15184 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
15185 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
15186 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
15187 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
15188 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
15189 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
15190 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15191 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15192 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
15193 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
15194 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
15195 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
15196
15197 /* Statistics */
15198 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15199 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15200 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15201 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15202
15203 /* old command */
15204 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15205 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15206 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15207 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15208 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15209 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15210 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15211 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15212 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15213 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15214 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15215 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15216 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15217 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15218 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15219 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15220 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15221 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15222 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15223 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15224 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15225 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15226 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15227 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15228 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15229 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15230 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15231 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15232 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15233 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15234 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15235 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15236 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15237 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15238 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15239 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15240
15241 /* old command */
15242 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15243 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15244
15245 /* old command */
15246 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15247 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15248
15249 /* old command */
15250 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15251 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15252 #endif /* HAVE_IPV6 */
15253
15254 install_element (BGP_NODE, &bgp_distance_cmd);
15255 install_element (BGP_NODE, &no_bgp_distance_cmd);
15256 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15257 install_element (BGP_NODE, &bgp_distance_source_cmd);
15258 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15259 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15260 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15261 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
15262 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
15263 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
15264 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
15265 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
15266 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
15267 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
15268 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
15269 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
15270 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
15271 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
15272 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
15273 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
15274 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
15275 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
15276 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
15277 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
15278 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
15279 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
15280 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15281 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15282 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15283 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15284 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15285 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15286 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15287 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15288 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15289
15290 install_element (BGP_NODE, &bgp_damp_set_cmd);
15291 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15292 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15293 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15294 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15295 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15296 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15297 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15298 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15299 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15300 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15301 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15302
15303 /* IPv4 Multicast Mode */
15304 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15305 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15306 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15307 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15308 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15309 }
15310
15311 void
15312 bgp_route_finish (void)
15313 {
15314 afi_t afi;
15315 safi_t safi;
15316
15317 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15318 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15319 {
15320 bgp_table_unlock (bgp_distance_table[afi][safi]);
15321 bgp_distance_table[afi][safi] = NULL;
15322 }
15323 }