1 /* BGP routing information
2    Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3    Copyright (C) 2016 Job Snijders <job@instituut.net>
4 
5 This file is part of GNU Zebra.
6 
7 GNU Zebra is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11 
12 GNU Zebra is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GNU Zebra; see the file COPYING.  If not, write to the Free
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21 
22 #include <zebra.h>
23 
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 
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_table.h"
41 #include "bgpd/bgp_route.h"
42 #include "bgpd/bgp_attr.h"
43 #include "bgpd/bgp_debug.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_regex.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_clist.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_nexthop.h"
55 #include "bgpd/bgp_damp.h"
56 #include "bgpd/bgp_advertise.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_mpath.h"
60 #include "bgpd/bgp_nht.h"
61 
62 /* Extern from bgp_dump.c */
63 extern const char *bgp_origin_str[];
64 extern const char *bgp_origin_long_str[];
65 
66 static struct bgp_node *
bgp_afi_node_get(struct bgp_table * table,afi_t afi,safi_t safi,struct prefix * p,struct prefix_rd * prd)67 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
68 		  struct prefix_rd *prd)
69 {
70   struct bgp_node *rn;
71   struct bgp_node *prn = NULL;
72 
73   assert (table);
74   if (!table)
75     return NULL;
76 
77   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
78     {
79       prn = bgp_node_get (table, (struct prefix *) prd);
80 
81       if (prn->info == NULL)
82 	prn->info = bgp_table_init (afi, safi);
83       else
84 	bgp_unlock_node (prn);
85       table = prn->info;
86     }
87 
88   rn = bgp_node_get (table, p);
89 
90   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
91     rn->prn = prn;
92 
93   return rn;
94 }
95 
96 /* Allocate bgp_info_extra */
97 static struct bgp_info_extra *
bgp_info_extra_new(void)98 bgp_info_extra_new (void)
99 {
100   struct bgp_info_extra *new;
101   new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
102   return new;
103 }
104 
105 static void
bgp_info_extra_free(struct bgp_info_extra ** extra)106 bgp_info_extra_free (struct bgp_info_extra **extra)
107 {
108   if (extra && *extra)
109     {
110       if ((*extra)->damp_info)
111         bgp_damp_info_free ((*extra)->damp_info, 0);
112 
113       (*extra)->damp_info = NULL;
114 
115       XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
116 
117       *extra = NULL;
118     }
119 }
120 
121 /* Get bgp_info extra information for the given bgp_info, lazy allocated
122  * if required.
123  */
124 struct bgp_info_extra *
bgp_info_extra_get(struct bgp_info * ri)125 bgp_info_extra_get (struct bgp_info *ri)
126 {
127   if (!ri->extra)
128     ri->extra = bgp_info_extra_new();
129   return ri->extra;
130 }
131 
132 /* Free bgp route information. */
133 static void
bgp_info_free(struct bgp_info * binfo)134 bgp_info_free (struct bgp_info *binfo)
135 {
136   if (binfo->attr)
137     bgp_attr_unintern (&binfo->attr);
138 
139   bgp_unlink_nexthop (binfo);
140   bgp_info_extra_free (&binfo->extra);
141   bgp_info_mpath_free (&binfo->mpath);
142 
143   peer_unlock (binfo->peer); /* bgp_info peer reference */
144 
145   XFREE (MTYPE_BGP_ROUTE, binfo);
146 }
147 
148 struct bgp_info *
bgp_info_lock(struct bgp_info * binfo)149 bgp_info_lock (struct bgp_info *binfo)
150 {
151   binfo->lock++;
152   return binfo;
153 }
154 
155 struct bgp_info *
bgp_info_unlock(struct bgp_info * binfo)156 bgp_info_unlock (struct bgp_info *binfo)
157 {
158   assert (binfo && binfo->lock > 0);
159   binfo->lock--;
160 
161   if (binfo->lock == 0)
162     {
163 #if 0
164       zlog_debug ("%s: unlocked and freeing", __func__);
165       zlog_backtrace (LOG_DEBUG);
166 #endif
167       bgp_info_free (binfo);
168       return NULL;
169     }
170 
171 #if 0
172   if (binfo->lock == 1)
173     {
174       zlog_debug ("%s: unlocked to 1", __func__);
175       zlog_backtrace (LOG_DEBUG);
176     }
177 #endif
178 
179   return binfo;
180 }
181 
182 void
bgp_info_add(struct bgp_node * rn,struct bgp_info * ri)183 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
184 {
185   struct bgp_info *top;
186 
187   top = rn->info;
188 
189   ri->next = rn->info;
190   ri->prev = NULL;
191   if (top)
192     top->prev = ri;
193   rn->info = ri;
194 
195   bgp_info_lock (ri);
196   bgp_lock_node (rn);
197   peer_lock (ri->peer); /* bgp_info peer reference */
198 }
199 
200 /* Do the actual removal of info from RIB, for use by bgp_process
201    completion callback *only* */
202 static void
bgp_info_reap(struct bgp_node * rn,struct bgp_info * ri)203 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
204 {
205   if (ri->next)
206     ri->next->prev = ri->prev;
207   if (ri->prev)
208     ri->prev->next = ri->next;
209   else
210     rn->info = ri->next;
211 
212   bgp_info_mpath_dequeue (ri);
213   bgp_info_unlock (ri);
214   bgp_unlock_node (rn);
215 }
216 
217 void
bgp_info_delete(struct bgp_node * rn,struct bgp_info * ri)218 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
219 {
220   bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221   /* set of previous already took care of pcount */
222   UNSET_FLAG (ri->flags, BGP_INFO_VALID);
223 }
224 
225 /* undo the effects of a previous call to bgp_info_delete; typically
226    called when a route is deleted and then quickly re-added before the
227    deletion has been processed */
228 static void
bgp_info_restore(struct bgp_node * rn,struct bgp_info * ri)229 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
230 {
231   bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232   /* unset of previous already took care of pcount */
233   SET_FLAG (ri->flags, BGP_INFO_VALID);
234 }
235 
236 /* Adjust pcount as required */
237 static void
bgp_pcount_adjust(struct bgp_node * rn,struct bgp_info * ri)238 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
239 {
240   struct bgp_table *table;
241 
242   assert (rn && bgp_node_table (rn));
243   assert (ri && ri->peer && ri->peer->bgp);
244 
245   table = bgp_node_table (rn);
246 
247   /* Ignore 'pcount' for RS-client tables */
248   if (table->type != BGP_TABLE_MAIN
249       || ri->peer == ri->peer->bgp->peer_self)
250     return;
251 
252   if (!BGP_INFO_COUNTABLE (ri)
253       && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
254     {
255 
256       UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
257 
258       /* slight hack, but more robust against errors. */
259       if (ri->peer->pcount[table->afi][table->safi])
260         ri->peer->pcount[table->afi][table->safi]--;
261       else
262         {
263           zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
264                      __func__, ri->peer->host);
265           zlog_backtrace (LOG_WARNING);
266           zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
267         }
268     }
269   else if (BGP_INFO_COUNTABLE (ri)
270            && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
271     {
272       SET_FLAG (ri->flags, BGP_INFO_COUNTED);
273       ri->peer->pcount[table->afi][table->safi]++;
274     }
275 }
276 
277 
278 /* Set/unset bgp_info flags, adjusting any other state as needed.
279  * This is here primarily to keep prefix-count in check.
280  */
281 void
bgp_info_set_flag(struct bgp_node * rn,struct bgp_info * ri,u_int32_t flag)282 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
283 {
284   SET_FLAG (ri->flags, flag);
285 
286   /* early bath if we know it's not a flag that changes countability state */
287   if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
288     return;
289 
290   bgp_pcount_adjust (rn, ri);
291 }
292 
293 void
bgp_info_unset_flag(struct bgp_node * rn,struct bgp_info * ri,u_int32_t flag)294 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
295 {
296   UNSET_FLAG (ri->flags, flag);
297 
298   /* early bath if we know it's not a flag that changes countability state */
299   if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
300     return;
301 
302   bgp_pcount_adjust (rn, ri);
303 }
304 
305 /* Get MED value.  If MED value is missing and "bgp bestpath
306    missing-as-worst" is specified, treat it as the worst value. */
307 static u_int32_t
bgp_med_value(struct attr * attr,struct bgp * bgp)308 bgp_med_value (struct attr *attr, struct bgp *bgp)
309 {
310   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
311     return attr->med;
312   else
313     {
314       if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
315 	return BGP_MED_MAX;
316       else
317 	return 0;
318     }
319 }
320 
321 /* Compare two bgp route entity.  Return -1 if new is preferred, 1 if exist
322  * is preferred, or 0 if they are the same (usually will only occur if
323  * multipath is enabled */
324 static int
bgp_info_cmp(struct bgp * bgp,struct bgp_info * new,struct bgp_info * exist,afi_t afi,safi_t safi)325 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
326               afi_t afi, safi_t safi)
327 {
328   struct attr *newattr, *existattr;
329   struct attr_extra *newattre, *existattre;
330   bgp_peer_sort_t new_sort;
331   bgp_peer_sort_t exist_sort;
332   u_int32_t new_pref;
333   u_int32_t exist_pref;
334   u_int32_t new_med;
335   u_int32_t exist_med;
336   u_int32_t new_weight;
337   u_int32_t exist_weight;
338   uint32_t newm, existm;
339   struct in_addr new_id;
340   struct in_addr exist_id;
341   int new_cluster;
342   int exist_cluster;
343   int internal_as_route;
344   int confed_as_route;
345   int ret;
346 
347   /* 0. Null check. */
348   if (new == NULL)
349     return 1;
350   if (exist == NULL)
351     return -1;
352 
353   newattr = new->attr;
354   existattr = exist->attr;
355   newattre = newattr->extra;
356   existattre = existattr->extra;
357 
358   /* 1. Weight check. */
359   new_weight = exist_weight = 0;
360 
361   if (newattre)
362     new_weight = newattre->weight;
363   if (existattre)
364     exist_weight = existattre->weight;
365 
366   if (new_weight > exist_weight)
367     return -1;
368   if (new_weight < exist_weight)
369     return 1;
370 
371   /* 2. Local preference check. */
372   new_pref = exist_pref = bgp->default_local_pref;
373 
374   if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375     new_pref = newattr->local_pref;
376   if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
377     exist_pref = existattr->local_pref;
378 
379   if (new_pref > exist_pref)
380     return -1;
381   if (new_pref < exist_pref)
382     return 1;
383 
384   /* 3. Local route check. We prefer:
385    *  - BGP_ROUTE_STATIC
386    *  - BGP_ROUTE_AGGREGATE
387    *  - BGP_ROUTE_REDISTRIBUTE
388    */
389   if (! (new->sub_type == BGP_ROUTE_NORMAL))
390      return -1;
391   if (! (exist->sub_type == BGP_ROUTE_NORMAL))
392      return 1;
393 
394   /* 4. AS path length check. */
395   if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
396     {
397       int exist_hops = aspath_count_hops (existattr->aspath);
398       int exist_confeds = aspath_count_confeds (existattr->aspath);
399 
400       if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
401 	{
402 	  int aspath_hops;
403 
404 	  aspath_hops = aspath_count_hops (newattr->aspath);
405           aspath_hops += aspath_count_confeds (newattr->aspath);
406 
407 	  if ( aspath_hops < (exist_hops + exist_confeds))
408 	    return -1;
409 	  if ( aspath_hops > (exist_hops + exist_confeds))
410 	    return 1;
411 	}
412       else
413 	{
414 	  int newhops = aspath_count_hops (newattr->aspath);
415 
416 	  if (newhops < exist_hops)
417 	    return -1;
418           if (newhops > exist_hops)
419 	    return 1;
420 	}
421     }
422 
423   /* 5. Origin check. */
424   if (newattr->origin < existattr->origin)
425     return -1;
426   if (newattr->origin > existattr->origin)
427     return 1;
428 
429   /* 6. MED check. */
430   internal_as_route = (aspath_count_hops (newattr->aspath) == 0
431 		      && aspath_count_hops (existattr->aspath) == 0);
432   confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
433 		    && aspath_count_confeds (existattr->aspath) > 0
434 		    && aspath_count_hops (newattr->aspath) == 0
435 		    && aspath_count_hops (existattr->aspath) == 0);
436 
437   if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
438       || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
439 	 && confed_as_route)
440       || aspath_cmp_left (newattr->aspath, existattr->aspath)
441       || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
442       || internal_as_route)
443     {
444       new_med = bgp_med_value (new->attr, bgp);
445       exist_med = bgp_med_value (exist->attr, bgp);
446 
447       if (new_med < exist_med)
448 	return -1;
449       if (new_med > exist_med)
450 	return 1;
451     }
452 
453   /* 7. Peer type check. */
454   new_sort = new->peer->sort;
455   exist_sort = exist->peer->sort;
456 
457   if (new_sort == BGP_PEER_EBGP
458       && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
459     return -1;
460   if (exist_sort == BGP_PEER_EBGP
461       && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
462     return 1;
463 
464   /* 8. IGP metric check. */
465   newm = existm = 0;
466 
467   if (new->extra)
468     newm = new->extra->igpmetric;
469   if (exist->extra)
470     existm = exist->extra->igpmetric;
471 
472   if (newm < existm)
473     return -1;
474   if (newm > existm)
475     return 1;
476 
477   /* 9. Maximum path check. */
478   if (bgp_mpath_is_configured (bgp, afi, safi))
479     {
480       if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
481         {
482           /*
483            * For the two paths, all comparison steps till IGP metric
484            * have succeeded - including AS_PATH hop count. Since 'bgp
485            * bestpath as-path multipath-relax' knob is on, we don't need
486            * an exact match of AS_PATH. Thus, mark the paths are equal.
487            * That will trigger both these paths to get into the multipath
488            * array.
489            */
490           return 0;
491         }
492       else if (new->peer->sort == BGP_PEER_IBGP)
493         {
494           if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
495             return 0;
496         }
497       else if (new->peer->as == exist->peer->as)
498         return 0;
499     }
500 
501   /* 10. If both paths are external, prefer the path that was received
502      first (the oldest one).  This step minimizes route-flap, since a
503      newer path won't displace an older one, even if it was the
504      preferred route based on the additional decision criteria below.  */
505   if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
506       && new_sort == BGP_PEER_EBGP
507       && exist_sort == BGP_PEER_EBGP)
508     {
509       if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
510 	return -1;
511       if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
512 	return 1;
513     }
514 
515   /* 11. Router-ID comparision. */
516   /* If one of the paths is "stale", the corresponding peer router-id will
517    * be 0 and would always win over the other path. If originator id is
518    * used for the comparision, it will decide which path is better.
519    */
520   if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
521     new_id.s_addr = newattre->originator_id.s_addr;
522   else
523     new_id.s_addr = new->peer->remote_id.s_addr;
524   if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
525     exist_id.s_addr = existattre->originator_id.s_addr;
526   else
527     exist_id.s_addr = exist->peer->remote_id.s_addr;
528 
529   if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
530     return -1;
531   if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
532     return 1;
533 
534   /* 12. Cluster length comparision. */
535   new_cluster = exist_cluster = 0;
536 
537   if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538     new_cluster = newattre->cluster->length;
539   if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
540     exist_cluster = existattre->cluster->length;
541 
542   if (new_cluster < exist_cluster)
543     return -1;
544   if (new_cluster > exist_cluster)
545     return 1;
546 
547   /* 13. Neighbor address comparision. */
548   /* Do this only if neither path is "stale" as stale paths do not have
549    * valid peer information (as the connection may or may not be up).
550    */
551   if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
552     return -1;
553   if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
554     return 1;
555   /* locally configured routes to advertise do not have su_remote */
556   if (new->peer->su_remote == NULL)
557     return 1;
558   if (exist->peer->su_remote == NULL)
559     return -1;
560 
561   ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
562 
563   if (ret == 1)
564     return 1;
565   if (ret == -1)
566     return -1;
567 
568   return -1;
569 }
570 
571 static enum filter_type
bgp_input_filter(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)572 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
573 		  afi_t afi, safi_t safi)
574 {
575   struct bgp_filter *filter;
576 
577   filter = &peer->filter[afi][safi];
578 
579 #define FILTER_EXIST_WARN(F,f,filter) \
580   if (BGP_DEBUG (update, UPDATE_IN) \
581       && !(F ## _IN (filter))) \
582     plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
583                peer->host, #f, F ## _IN_NAME(filter));
584 
585   if (DISTRIBUTE_IN_NAME (filter)) {
586     FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
587 
588     if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
589       return FILTER_DENY;
590   }
591 
592   if (PREFIX_LIST_IN_NAME (filter)) {
593     FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
594 
595     if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
596       return FILTER_DENY;
597   }
598 
599   if (FILTER_LIST_IN_NAME (filter)) {
600     FILTER_EXIST_WARN(FILTER_LIST, as, filter);
601 
602     if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
603       return FILTER_DENY;
604   }
605 
606   return FILTER_PERMIT;
607 #undef FILTER_EXIST_WARN
608 }
609 
610 static enum filter_type
bgp_output_filter(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)611 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
612 		   afi_t afi, safi_t safi)
613 {
614   struct bgp_filter *filter;
615 
616   filter = &peer->filter[afi][safi];
617 
618 #define FILTER_EXIST_WARN(F,f,filter) \
619   if (BGP_DEBUG (update, UPDATE_OUT) \
620       && !(F ## _OUT (filter))) \
621     plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
622                peer->host, #f, F ## _OUT_NAME(filter));
623 
624   if (DISTRIBUTE_OUT_NAME (filter)) {
625     FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
626 
627     if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
628       return FILTER_DENY;
629   }
630 
631   if (PREFIX_LIST_OUT_NAME (filter)) {
632     FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
633 
634     if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
635       return FILTER_DENY;
636   }
637 
638   if (FILTER_LIST_OUT_NAME (filter)) {
639     FILTER_EXIST_WARN(FILTER_LIST, as, filter);
640 
641     if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
642       return FILTER_DENY;
643   }
644 
645   return FILTER_PERMIT;
646 #undef FILTER_EXIST_WARN
647 }
648 
649 /* If community attribute includes no_export then return 1. */
650 static int
bgp_community_filter(struct peer * peer,struct attr * attr)651 bgp_community_filter (struct peer *peer, struct attr *attr)
652 {
653   if (attr->community)
654     {
655       /* NO_ADVERTISE check. */
656       if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
657 	return 1;
658 
659       /* NO_EXPORT check. */
660       if (peer->sort == BGP_PEER_EBGP &&
661 	  community_include (attr->community, COMMUNITY_NO_EXPORT))
662 	return 1;
663 
664       /* NO_EXPORT_SUBCONFED check. */
665       if (peer->sort == BGP_PEER_EBGP
666 	  || peer->sort == BGP_PEER_CONFED)
667 	if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
668 	  return 1;
669     }
670   return 0;
671 }
672 
673 /* Route reflection loop check.  */
674 static int
bgp_cluster_filter(struct peer * peer,struct attr * attr)675 bgp_cluster_filter (struct peer *peer, struct attr *attr)
676 {
677   struct in_addr cluster_id;
678 
679   if (attr->extra && attr->extra->cluster)
680     {
681       if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
682 	cluster_id = peer->bgp->cluster_id;
683       else
684 	cluster_id = peer->bgp->router_id;
685 
686       if (cluster_loop_check (attr->extra->cluster, cluster_id))
687 	return 1;
688     }
689   return 0;
690 }
691 
692 static int
bgp_input_modifier(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)693 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
694 		    afi_t afi, safi_t safi)
695 {
696   struct bgp_filter *filter;
697   struct bgp_info info;
698   route_map_result_t ret;
699 
700   filter = &peer->filter[afi][safi];
701 
702   /* Apply default weight value. */
703   if (peer->weight)
704     (bgp_attr_extra_get (attr))->weight = peer->weight;
705 
706   /* Route map apply. */
707   if (ROUTE_MAP_IN_NAME (filter))
708     {
709       /* Duplicate current value to new strucutre for modification. */
710       info.peer = peer;
711       info.attr = attr;
712 
713       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
714 
715       /* Apply BGP route map to the attribute. */
716       ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
717 
718       peer->rmap_type = 0;
719 
720       if (ret == RMAP_DENYMATCH)
721 	/* caller has multiple error paths with bgp_attr_flush() */
722 	return RMAP_DENY;
723     }
724   return RMAP_PERMIT;
725 }
726 
727 static int
bgp_export_modifier(struct peer * rsclient,struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)728 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
729         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
730 {
731   struct bgp_filter *filter;
732   struct bgp_info info;
733   route_map_result_t ret;
734 
735   filter = &peer->filter[afi][safi];
736 
737   /* Route map apply. */
738   if (ROUTE_MAP_EXPORT_NAME (filter))
739     {
740       /* Duplicate current value to new strucutre for modification. */
741       info.peer = rsclient;
742       info.attr = attr;
743 
744       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
745 
746       /* Apply BGP route map to the attribute. */
747       ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
748 
749       rsclient->rmap_type = 0;
750 
751       if (ret == RMAP_DENYMATCH)
752         {
753           /* Free newly generated AS path and community by route-map. */
754           bgp_attr_flush (attr);
755           return RMAP_DENY;
756         }
757     }
758   return RMAP_PERMIT;
759 }
760 
761 static int
bgp_import_modifier(struct peer * rsclient,struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)762 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
763         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
764 {
765   struct bgp_filter *filter;
766   struct bgp_info info;
767   route_map_result_t ret;
768 
769   filter = &rsclient->filter[afi][safi];
770 
771   /* Apply default weight value. */
772   if (peer->weight)
773     (bgp_attr_extra_get (attr))->weight = peer->weight;
774 
775   /* Route map apply. */
776   if (ROUTE_MAP_IMPORT_NAME (filter))
777     {
778       /* Duplicate current value to new strucutre for modification. */
779       info.peer = peer;
780       info.attr = attr;
781 
782       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
783 
784       /* Apply BGP route map to the attribute. */
785       ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
786 
787       peer->rmap_type = 0;
788 
789       if (ret == RMAP_DENYMATCH)
790         {
791           /* Free newly generated AS path and community by route-map. */
792           bgp_attr_flush (attr);
793           return RMAP_DENY;
794         }
795     }
796   return RMAP_PERMIT;
797 }
798 
799 static int
bgp_announce_check(struct bgp_info * ri,struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)800 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
801 		    struct attr *attr, afi_t afi, safi_t safi)
802 {
803   int ret;
804   char buf[SU_ADDRSTRLEN];
805   struct bgp_filter *filter;
806   struct peer *from;
807   struct bgp *bgp;
808   int transparent;
809   int reflect;
810   struct attr *riattr;
811 
812   from = ri->peer;
813   filter = &peer->filter[afi][safi];
814   bgp = peer->bgp;
815   riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
816 
817   if (DISABLE_BGP_ANNOUNCE)
818     return 0;
819 
820   /* Do not send announces to RS-clients from the 'normal' bgp_table. */
821   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
822     return 0;
823 
824   /* Do not send back route to sender. */
825   if (from == peer)
826     return 0;
827 
828   /* Aggregate-address suppress check. */
829   if (ri->extra && ri->extra->suppress)
830     if (! UNSUPPRESS_MAP_NAME (filter))
831       return 0;
832 
833   /* Default route check.  */
834   if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
835     {
836       if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
837 	return 0;
838       else if (p->family == AF_INET6 && p->prefixlen == 0)
839 	return 0;
840     }
841 
842   /* Transparency check. */
843   if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
844       && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
845     transparent = 1;
846   else
847     transparent = 0;
848 
849   /* If community is not disabled check the no-export and local. */
850   if (! transparent && bgp_community_filter (peer, riattr))
851     return 0;
852 
853   /* If the attribute has originator-id and it is same as remote
854      peer's id. */
855   if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
856     {
857       if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
858 	{
859 	  if (BGP_DEBUG (filter, FILTER))
860 	    zlog (peer->log, LOG_DEBUG,
861 		  "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
862 		  peer->host,
863 		  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
864 		  p->prefixlen);
865 	  return 0;
866 	}
867     }
868 
869   /* ORF prefix-list filter check */
870   if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
871       && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
872 	  || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
873     if (peer->orf_plist[afi][safi])
874       {
875 	if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
876           return 0;
877       }
878 
879   /* Output filter check. */
880   if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
881     {
882       if (BGP_DEBUG (filter, FILTER))
883 	zlog (peer->log, LOG_DEBUG,
884 	      "%s [Update:SEND] %s/%d is filtered",
885 	      peer->host,
886 	      inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
887 	      p->prefixlen);
888       return 0;
889     }
890 
891 #ifdef BGP_SEND_ASPATH_CHECK
892   /* AS path loop check. */
893   if (aspath_loop_check (riattr->aspath, peer->as))
894     {
895       if (BGP_DEBUG (filter, FILTER))
896         zlog (peer->log, LOG_DEBUG,
897 	      "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
898 	      peer->host, peer->as);
899       return 0;
900     }
901 
902   /* If we're a CONFED we need to loop check the CONFED ID too */
903   if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
904     {
905       if (aspath_loop_check(riattr->aspath, bgp->confed_id))
906 	{
907 	  if (BGP_DEBUG (filter, FILTER))
908 	    zlog (peer->log, LOG_DEBUG,
909 		  "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
910 		  peer->host,
911 		  bgp->confed_id);
912 	  return 0;
913 	}
914     }
915 #endif /* BGP_SEND_ASPATH_CHECK */
916 
917   /* Route-Reflect check. */
918   if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
919     reflect = 1;
920   else
921     reflect = 0;
922 
923   /* IBGP reflection check. */
924   if (reflect)
925     {
926       /* A route from a Client peer. */
927       if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
928 	{
929 	  /* Reflect to all the Non-Client peers and also to the
930              Client peers other than the originator.  Originator check
931              is already done.  So there is noting to do. */
932 	  /* no bgp client-to-client reflection check. */
933 	  if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
934 	    if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
935 	      return 0;
936 	}
937       else
938 	{
939 	  /* A route from a Non-client peer. Reflect to all other
940 	     clients. */
941 	  if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 	    return 0;
943 	}
944     }
945 
946   /* For modify attribute, copy it to temporary structure. */
947   bgp_attr_dup (attr, riattr);
948 
949   /* If local-preference is not set. */
950   if ((peer->sort == BGP_PEER_IBGP
951        || peer->sort == BGP_PEER_CONFED)
952       && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
953     {
954       attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
955       attr->local_pref = bgp->default_local_pref;
956     }
957 
958   /* If originator-id is not set and the route is to be reflected,
959      set the originator id */
960   if (peer && from && peer->sort == BGP_PEER_IBGP &&
961       from->sort == BGP_PEER_IBGP &&
962       (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
963     {
964       attr->extra = bgp_attr_extra_get(attr);
965       IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
966       SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
967     }
968 
969   /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
970   if (peer->sort == BGP_PEER_EBGP
971       && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
972     {
973       if (ri->peer != bgp->peer_self && ! transparent
974 	  && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
975 	attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
976     }
977 
978 
979 #define NEXTHOP_IS_V4 (\
980     (safi != SAFI_ENCAP && p->family == AF_INET) || \
981     (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
982 
983 #define NEXTHOP_IS_V6 (\
984     (safi != SAFI_ENCAP && p->family == AF_INET6) || \
985     (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
986 
987   /* next-hop-set */
988   if (transparent
989       || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
990       || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
991 	  && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
992 	      || (NEXTHOP_IS_V6 &&
993                   ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
994 	      )))
995     {
996       /* NEXT-HOP Unchanged. */
997     }
998   else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
999 	   || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
1000 	   || (NEXTHOP_IS_V6 &&
1001                IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1002 	   || (peer->sort == BGP_PEER_EBGP
1003                && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
1004     {
1005       /* Set IPv4 nexthop. */
1006       if (NEXTHOP_IS_V4)
1007 	{
1008 	  if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
1009 	    memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1010 	            IPV4_MAX_BYTELEN);
1011 	  else
1012 	    memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1013 	}
1014       /* Set IPv6 nexthop. */
1015       if (NEXTHOP_IS_V6)
1016 	{
1017 	  /* IPv6 global nexthop must be included. */
1018 	  memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
1019 		  IPV6_MAX_BYTELEN);
1020 	  attr->extra->mp_nexthop_len = 16;
1021 	}
1022     }
1023 
1024   if (p->family == AF_INET6 && safi != SAFI_ENCAP)
1025     {
1026       /* Left nexthop_local unchanged if so configured. */
1027       if ( CHECK_FLAG (peer->af_flags[afi][safi],
1028            PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1029         {
1030           if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1031             attr->extra->mp_nexthop_len=32;
1032           else
1033             attr->extra->mp_nexthop_len=16;
1034         }
1035 
1036       /* Default nexthop_local treatment for non-RS-Clients */
1037       else
1038         {
1039       /* Link-local address should not be transit to different peer. */
1040       attr->extra->mp_nexthop_len = 16;
1041 
1042       /* Set link-local address for shared network peer. */
1043       if (peer->shared_network
1044 	  && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1045 	{
1046 	  memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
1047 		  IPV6_MAX_BYTELEN);
1048 	  attr->extra->mp_nexthop_len = 32;
1049 	}
1050 
1051       /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1052 	 address.*/
1053       if (reflect)
1054 	attr->extra->mp_nexthop_len = 16;
1055 
1056       /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1057       if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
1058 	attr->extra->mp_nexthop_len = 16;
1059     }
1060 
1061     }
1062 
1063   /* If this is EBGP peer and remove-private-AS is set.  */
1064   if (peer->sort == BGP_PEER_EBGP
1065       && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1066       && aspath_private_as_check (attr->aspath))
1067     attr->aspath = aspath_empty_get ();
1068 
1069   /* Route map & unsuppress-map apply. */
1070   if (ROUTE_MAP_OUT_NAME (filter)
1071       || (ri->extra && ri->extra->suppress) )
1072     {
1073       struct bgp_info info;
1074       struct attr dummy_attr;
1075       struct attr_extra dummy_extra;
1076 
1077       dummy_attr.extra = &dummy_extra;
1078 
1079       info.peer = peer;
1080       info.attr = attr;
1081 
1082       /* The route reflector is not allowed to modify the attributes
1083 	 of the reflected IBGP routes, unless configured to allow it */
1084       if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1085 	  !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1086 	{
1087 	  bgp_attr_dup (&dummy_attr, attr);
1088 	  info.attr = &dummy_attr;
1089 	}
1090 
1091       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1092 
1093       if (ri->extra && ri->extra->suppress)
1094 	ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1095       else
1096 	ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1097 
1098       peer->rmap_type = 0;
1099 
1100       if (ret == RMAP_DENYMATCH)
1101 	{
1102 	  bgp_attr_flush (attr);
1103 	  return 0;
1104 	}
1105     }
1106   return 1;
1107 }
1108 
1109 static int
bgp_announce_check_rsclient(struct bgp_info * ri,struct peer * rsclient,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi)1110 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1111         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1112 {
1113   int ret;
1114   char buf[SU_ADDRSTRLEN];
1115   struct bgp_filter *filter;
1116   struct bgp_info info;
1117   struct peer *from;
1118   struct attr *riattr;
1119 
1120   from = ri->peer;
1121   filter = &rsclient->filter[afi][safi];
1122   riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1123 
1124   if (DISABLE_BGP_ANNOUNCE)
1125     return 0;
1126 
1127   /* Do not send back route to sender. */
1128   if (from == rsclient)
1129     return 0;
1130 
1131   /* Aggregate-address suppress check. */
1132   if (ri->extra && ri->extra->suppress)
1133     if (! UNSUPPRESS_MAP_NAME (filter))
1134       return 0;
1135 
1136   /* Default route check.  */
1137   if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1138           PEER_STATUS_DEFAULT_ORIGINATE))
1139     {
1140       if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1141         return 0;
1142       else if (p->family == AF_INET6 && p->prefixlen == 0)
1143         return 0;
1144     }
1145 
1146   /* If the attribute has originator-id and it is same as remote
1147      peer's id. */
1148   if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1149     {
1150       if (IPV4_ADDR_SAME (&rsclient->remote_id,
1151                           &riattr->extra->originator_id))
1152         {
1153          if (BGP_DEBUG (filter, FILTER))
1154            zlog (rsclient->log, LOG_DEBUG,
1155                  "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1156                  rsclient->host,
1157                  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158                  p->prefixlen);
1159          return 0;
1160        }
1161     }
1162 
1163   /* ORF prefix-list filter check */
1164   if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1165       && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1166          || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1167     if (rsclient->orf_plist[afi][safi])
1168       {
1169        if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1170           return 0;
1171       }
1172 
1173   /* Output filter check. */
1174   if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1175     {
1176       if (BGP_DEBUG (filter, FILTER))
1177        zlog (rsclient->log, LOG_DEBUG,
1178              "%s [Update:SEND] %s/%d is filtered",
1179              rsclient->host,
1180              inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1181              p->prefixlen);
1182       return 0;
1183     }
1184 
1185 #ifdef BGP_SEND_ASPATH_CHECK
1186   /* AS path loop check. */
1187   if (aspath_loop_check (riattr->aspath, rsclient->as))
1188     {
1189       if (BGP_DEBUG (filter, FILTER))
1190         zlog (rsclient->log, LOG_DEBUG,
1191              "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1192              rsclient->host, rsclient->as);
1193       return 0;
1194     }
1195 #endif /* BGP_SEND_ASPATH_CHECK */
1196 
1197   /* For modify attribute, copy it to temporary structure. */
1198   bgp_attr_dup (attr, riattr);
1199 
1200   /* next-hop-set */
1201   if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1202           || (p->family == AF_INET6 &&
1203               IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1204      )
1205   {
1206     /* Set IPv4 nexthop. */
1207     if (p->family == AF_INET)
1208       {
1209         if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
1210           memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1211                   IPV4_MAX_BYTELEN);
1212         else
1213           memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1214       }
1215     /* Set IPv6 nexthop. */
1216     if (p->family == AF_INET6)
1217       {
1218         /* IPv6 global nexthop must be included. */
1219         memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1220                 IPV6_MAX_BYTELEN);
1221         attr->extra->mp_nexthop_len = 16;
1222       }
1223   }
1224 
1225   if (p->family == AF_INET6)
1226     {
1227       struct attr_extra *attre = attr->extra;
1228 
1229       /* Left nexthop_local unchanged if so configured. */
1230       if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1231            PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1232         {
1233           if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1234             attre->mp_nexthop_len=32;
1235           else
1236             attre->mp_nexthop_len=16;
1237         }
1238 
1239       /* Default nexthop_local treatment for RS-Clients */
1240       else
1241         {
1242           /* Announcer and RS-Client are both in the same network */
1243           if (rsclient->shared_network && from->shared_network &&
1244               (rsclient->ifindex == from->ifindex))
1245             {
1246               if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1247                 attre->mp_nexthop_len=32;
1248               else
1249                 attre->mp_nexthop_len=16;
1250             }
1251 
1252           /* Set link-local address for shared network peer. */
1253           else if (rsclient->shared_network
1254               && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1255             {
1256               memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1257                       IPV6_MAX_BYTELEN);
1258               attre->mp_nexthop_len = 32;
1259             }
1260 
1261           else
1262             attre->mp_nexthop_len = 16;
1263         }
1264 
1265     }
1266 
1267   /* If this is EBGP peer and remove-private-AS is set.  */
1268   if (rsclient->sort == BGP_PEER_EBGP
1269       && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1270       && aspath_private_as_check (attr->aspath))
1271     attr->aspath = aspath_empty_get ();
1272 
1273   /* Route map & unsuppress-map apply. */
1274   if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1275     {
1276       info.peer = rsclient;
1277       info.attr = attr;
1278 
1279       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1280 
1281       if (ri->extra && ri->extra->suppress)
1282         ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1283       else
1284         ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1285 
1286       rsclient->rmap_type = 0;
1287 
1288       if (ret == RMAP_DENYMATCH)
1289        {
1290          bgp_attr_flush (attr);
1291          return 0;
1292        }
1293     }
1294 
1295   return 1;
1296 }
1297 
1298 struct bgp_info_pair
1299 {
1300   struct bgp_info *old;
1301   struct bgp_info *new;
1302 };
1303 
1304 static void
bgp_best_selection(struct bgp * bgp,struct bgp_node * rn,struct bgp_info_pair * result,afi_t afi,safi_t safi)1305 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1306 		    struct bgp_info_pair *result,
1307 		    afi_t afi, safi_t safi)
1308 {
1309   struct bgp_info *new_select;
1310   struct bgp_info *old_select;
1311   struct bgp_info *ri;
1312   struct bgp_info *ri1;
1313   struct bgp_info *ri2;
1314   struct bgp_info *nextri = NULL;
1315   int cmpret, do_mpath;
1316   struct list mp_list;
1317 
1318   result->old = result->new = NULL;
1319 
1320   if (rn->info == NULL)
1321     {
1322       char buf[PREFIX_STRLEN];
1323       zlog_warn ("%s: Called for route_node %s with no routing entries!",
1324                  __func__,
1325                  prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1326       return;
1327     }
1328 
1329   bgp_mp_list_init (&mp_list);
1330   do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
1331 
1332   /* bgp deterministic-med */
1333   new_select = NULL;
1334   if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1335     for (ri1 = rn->info; ri1; ri1 = ri1->next)
1336       {
1337 	if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1338 	  continue;
1339 	if (BGP_INFO_HOLDDOWN (ri1))
1340 	  continue;
1341         if (ri1->peer && ri1->peer != bgp->peer_self)
1342           if (ri1->peer->status != Established)
1343             continue;
1344 
1345 	new_select = ri1;
1346 	if (do_mpath)
1347 	  bgp_mp_list_add (&mp_list, ri1);
1348 	old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1349 	if (ri1->next)
1350 	  for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1351 	    {
1352 	      if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1353 		continue;
1354 	      if (BGP_INFO_HOLDDOWN (ri2))
1355 		continue;
1356               if (ri2->peer &&
1357                   ri2->peer != bgp->peer_self &&
1358                   !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1359                 if (ri2->peer->status != Established)
1360                   continue;
1361 
1362 	      if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1363 		  || aspath_cmp_left_confed (ri1->attr->aspath,
1364 					     ri2->attr->aspath))
1365 		{
1366 		  if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1367 		    old_select = ri2;
1368 		  if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1369 		       == -1)
1370 		    {
1371 		      bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1372 		      new_select = ri2;
1373 		    }
1374 
1375 		  if (do_mpath)
1376 		    {
1377                       if (cmpret != 0)
1378                         bgp_mp_list_clear (&mp_list);
1379 
1380                       if (cmpret == 0 || cmpret == -1)
1381                         bgp_mp_list_add (&mp_list, ri2);
1382                     }
1383 
1384 		  bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1385 		}
1386 	    }
1387 	bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1388 	bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1389 
1390 	bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
1391 	bgp_mp_list_clear (&mp_list);
1392       }
1393 
1394   /* Check old selected route and new selected route. */
1395   old_select = NULL;
1396   new_select = NULL;
1397   for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1398     {
1399       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1400 	old_select = ri;
1401 
1402       if (BGP_INFO_HOLDDOWN (ri))
1403         {
1404           /* reap REMOVED routes, if needs be
1405            * selected route must stay for a while longer though
1406            */
1407           if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1408               && (ri != old_select))
1409               bgp_info_reap (rn, ri);
1410 
1411           continue;
1412         }
1413 
1414       if (ri->peer &&
1415           ri->peer != bgp->peer_self &&
1416           !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1417         if (ri->peer->status != Established)
1418           continue;
1419 
1420       if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1421           && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1422 	{
1423 	  bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1424 	  continue;
1425         }
1426       bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1427       bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1428 
1429       if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
1430 	{
1431 	  if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1432 	    bgp_mp_dmed_deselect (new_select);
1433 
1434 	  new_select = ri;
1435 	}
1436       else if (cmpret == 1 && do_mpath
1437                && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1438 	bgp_mp_dmed_deselect (ri);
1439 
1440       if (do_mpath)
1441         {
1442           if (cmpret != 0)
1443             bgp_mp_list_clear (&mp_list);
1444 
1445           if (cmpret == 0 || cmpret == -1)
1446             bgp_mp_list_add (&mp_list, ri);
1447         }
1448     }
1449 
1450   if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1451     bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
1452 
1453   bgp_info_mpath_aggregate_update (new_select, old_select);
1454   bgp_mp_list_clear (&mp_list);
1455 
1456   result->old = old_select;
1457   result->new = new_select;
1458 
1459   return;
1460 }
1461 
1462 static int
bgp_process_announce_selected(struct peer * peer,struct bgp_info * selected,struct bgp_node * rn,afi_t afi,safi_t safi)1463 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1464                                struct bgp_node *rn, afi_t afi, safi_t safi)
1465 {
1466   struct prefix *p;
1467   struct attr attr;
1468   struct attr_extra extra;
1469 
1470   memset (&attr, 0, sizeof(struct attr));
1471   memset (&extra, 0, sizeof(struct attr_extra));
1472 
1473   p = &rn->p;
1474 
1475   /* Announce route to Established peer. */
1476   if (peer->status != Established)
1477     return 0;
1478 
1479   /* Address family configuration check. */
1480   if (! peer->afc_nego[afi][safi])
1481     return 0;
1482 
1483   /* First update is deferred until ORF or ROUTE-REFRESH is received */
1484   if (CHECK_FLAG (peer->af_sflags[afi][safi],
1485       PEER_STATUS_ORF_WAIT_REFRESH))
1486     return 0;
1487 
1488   /* It's initialized in bgp_announce_[check|check_rsclient]() */
1489   attr.extra = &extra;
1490 
1491   switch (bgp_node_table (rn)->type)
1492     {
1493       case BGP_TABLE_MAIN:
1494       /* Announcement to peer->conf.  If the route is filtered,
1495          withdraw it. */
1496         if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1497           bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1498         else
1499           bgp_adj_out_unset (rn, peer, p, afi, safi);
1500         break;
1501       case BGP_TABLE_RSCLIENT:
1502         /* Announcement to peer->conf.  If the route is filtered,
1503            withdraw it. */
1504         if (selected &&
1505             bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1506           bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1507         else
1508 	  bgp_adj_out_unset (rn, peer, p, afi, safi);
1509         break;
1510     }
1511 
1512   bgp_attr_flush (&attr);
1513   return 0;
1514 }
1515 
1516 struct bgp_process_queue
1517 {
1518   struct bgp *bgp;
1519   struct bgp_node *rn;
1520   afi_t afi;
1521   safi_t safi;
1522 };
1523 
1524 static wq_item_status
bgp_process_rsclient(struct work_queue * wq,void * data)1525 bgp_process_rsclient (struct work_queue *wq, void *data)
1526 {
1527   struct bgp_process_queue *pq = data;
1528   struct bgp *bgp = pq->bgp;
1529   struct bgp_node *rn = pq->rn;
1530   afi_t afi = pq->afi;
1531   safi_t safi = pq->safi;
1532   struct bgp_info *new_select;
1533   struct bgp_info *old_select;
1534   struct bgp_info_pair old_and_new;
1535   struct listnode *node, *nnode;
1536   struct peer *rsclient = bgp_node_table (rn)->owner;
1537 
1538   /* Best path selection. */
1539   bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
1540   new_select = old_and_new.new;
1541   old_select = old_and_new.old;
1542 
1543   if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1544     {
1545       if (rsclient->group)
1546         for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1547           {
1548             /* Nothing to do. */
1549             if (old_select && old_select == new_select)
1550               if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1551                 continue;
1552 
1553             if (old_select)
1554               bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1555             if (new_select)
1556               {
1557                 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1558                 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1559 		UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1560              }
1561 
1562             bgp_process_announce_selected (rsclient, new_select, rn,
1563                                            afi, safi);
1564           }
1565     }
1566   else
1567     {
1568       if (old_select)
1569 	bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1570       if (new_select)
1571 	{
1572 	  bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1573 	  bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1574 	  UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1575 	}
1576       bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1577     }
1578 
1579   if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1580     bgp_info_reap (rn, old_select);
1581 
1582   UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1583   return WQ_SUCCESS;
1584 }
1585 
1586 static wq_item_status
bgp_process_main(struct work_queue * wq,void * data)1587 bgp_process_main (struct work_queue *wq, void *data)
1588 {
1589   struct bgp_process_queue *pq = data;
1590   struct bgp *bgp = pq->bgp;
1591   struct bgp_node *rn = pq->rn;
1592   afi_t afi = pq->afi;
1593   safi_t safi = pq->safi;
1594   struct prefix *p = &rn->p;
1595   struct bgp_info *new_select;
1596   struct bgp_info *old_select;
1597   struct bgp_info_pair old_and_new;
1598   struct listnode *node, *nnode;
1599   struct peer *peer;
1600 
1601   /* Best path selection. */
1602   bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
1603   old_select = old_and_new.old;
1604   new_select = old_and_new.new;
1605 
1606   /* Nothing to do. */
1607   if (old_select && old_select == new_select
1608       && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
1609     {
1610       if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1611         {
1612           if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1613 	      CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1614             bgp_zebra_announce (p, old_select, bgp, safi);
1615 
1616 	  UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1617           UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1618           return WQ_SUCCESS;
1619         }
1620     }
1621 
1622   /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1623   UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1624 
1625   if (old_select)
1626     bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1627   if (new_select)
1628     {
1629       bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1630       bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1631       UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1632     }
1633 
1634 
1635   /* Check each BGP peer. */
1636   for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1637     {
1638       bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1639     }
1640 
1641   /* FIB update. */
1642   if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1643       ! bgp_option_check (BGP_OPT_NO_FIB)))
1644     {
1645       if (new_select
1646 	  && new_select->type == ZEBRA_ROUTE_BGP
1647 	  && new_select->sub_type == BGP_ROUTE_NORMAL)
1648 	bgp_zebra_announce (p, new_select, bgp, safi);
1649       else
1650 	{
1651 	  /* Withdraw the route from the kernel. */
1652 	  if (old_select
1653 	      && old_select->type == ZEBRA_ROUTE_BGP
1654 	      && old_select->sub_type == BGP_ROUTE_NORMAL)
1655 	    bgp_zebra_withdraw (p, old_select, safi);
1656 	}
1657     }
1658 
1659   /* Reap old select bgp_info, if it has been removed */
1660   if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1661     bgp_info_reap (rn, old_select);
1662 
1663   UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1664   return WQ_SUCCESS;
1665 }
1666 
1667 static void
bgp_processq_del(struct work_queue * wq,void * data)1668 bgp_processq_del (struct work_queue *wq, void *data)
1669 {
1670   struct bgp_process_queue *pq = data;
1671   struct bgp_table *table = bgp_node_table (pq->rn);
1672 
1673   bgp_unlock (pq->bgp);
1674   bgp_unlock_node (pq->rn);
1675   bgp_table_unlock (table);
1676   XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1677 }
1678 
1679 static void
bgp_process_queue_init(void)1680 bgp_process_queue_init (void)
1681 {
1682   bm->process_main_queue
1683     = work_queue_new (bm->master, "process_main_queue");
1684   bm->process_rsclient_queue
1685     = work_queue_new (bm->master, "process_rsclient_queue");
1686 
1687   if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1688     {
1689       zlog_err ("%s: Failed to allocate work queue", __func__);
1690       exit (1);
1691     }
1692 
1693   bm->process_main_queue->spec.workfunc = &bgp_process_main;
1694   bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1695   bm->process_main_queue->spec.max_retries = 0;
1696   bm->process_main_queue->spec.hold = 50;
1697 
1698   bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1699   bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1700   bm->process_rsclient_queue->spec.max_retries = 0;
1701   bm->process_rsclient_queue->spec.hold = 50;
1702 }
1703 
1704 void
bgp_process(struct bgp * bgp,struct bgp_node * rn,afi_t afi,safi_t safi)1705 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1706 {
1707   struct bgp_process_queue *pqnode;
1708 
1709   /* already scheduled for processing? */
1710   if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1711     return;
1712 
1713   if (rn->info == NULL)
1714     {
1715       /* XXX: Perhaps remove before next release, after we've flushed out
1716        * any obvious cases
1717        */
1718       assert (rn->info != NULL);
1719       char buf[PREFIX_STRLEN];
1720       zlog_warn ("%s: Called for route_node %s with no routing entries!",
1721                  __func__,
1722                  prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1723       return;
1724     }
1725 
1726   if ( (bm->process_main_queue == NULL) ||
1727        (bm->process_rsclient_queue == NULL) )
1728     bgp_process_queue_init ();
1729 
1730   pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1731                     sizeof (struct bgp_process_queue));
1732   if (!pqnode)
1733     return;
1734 
1735   /* all unlocked in bgp_processq_del */
1736   bgp_table_lock (bgp_node_table (rn));
1737   pqnode->rn = bgp_lock_node (rn);
1738   pqnode->bgp = bgp;
1739   bgp_lock (bgp);
1740   pqnode->afi = afi;
1741   pqnode->safi = safi;
1742 
1743   switch (bgp_node_table (rn)->type)
1744     {
1745       case BGP_TABLE_MAIN:
1746         work_queue_add (bm->process_main_queue, pqnode);
1747         break;
1748       case BGP_TABLE_RSCLIENT:
1749         work_queue_add (bm->process_rsclient_queue, pqnode);
1750         break;
1751     }
1752 
1753   SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1754   return;
1755 }
1756 
1757 static int
bgp_maximum_prefix_restart_timer(struct thread * thread)1758 bgp_maximum_prefix_restart_timer (struct thread *thread)
1759 {
1760   struct peer *peer;
1761 
1762   peer = THREAD_ARG (thread);
1763   peer->t_pmax_restart = NULL;
1764 
1765   if (BGP_DEBUG (events, EVENTS))
1766     zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1767 		peer->host);
1768 
1769   peer_clear (peer);
1770 
1771   return 0;
1772 }
1773 
1774 int
bgp_maximum_prefix_overflow(struct peer * peer,afi_t afi,safi_t safi,int always)1775 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1776                              safi_t safi, int always)
1777 {
1778   if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1779     return 0;
1780 
1781   if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1782     {
1783       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1784          && ! always)
1785        return 0;
1786 
1787       zlog (peer->log, LOG_INFO,
1788 	    "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1789 	    "limit %ld", afi_safi_print (afi, safi), peer->host,
1790 	    peer->pcount[afi][safi], peer->pmax[afi][safi]);
1791       SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1792 
1793       if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1794        return 0;
1795 
1796       {
1797        u_int8_t ndata[7];
1798 
1799        if (safi == SAFI_MPLS_VPN)
1800          safi = SAFI_MPLS_LABELED_VPN;
1801 
1802        ndata[0] = (afi >>  8);
1803        ndata[1] = afi;
1804        ndata[2] = safi;
1805        ndata[3] = (peer->pmax[afi][safi] >> 24);
1806        ndata[4] = (peer->pmax[afi][safi] >> 16);
1807        ndata[5] = (peer->pmax[afi][safi] >> 8);
1808        ndata[6] = (peer->pmax[afi][safi]);
1809 
1810        SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1811        bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1812                                   BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1813       }
1814 
1815       /* restart timer start */
1816       if (peer->pmax_restart[afi][safi])
1817 	{
1818 	  peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1819 
1820 	  if (BGP_DEBUG (events, EVENTS))
1821 	    zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1822 			peer->host, peer->v_pmax_restart);
1823 
1824 	  BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1825 			peer->v_pmax_restart);
1826 	}
1827 
1828       return 1;
1829     }
1830   else
1831     UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1832 
1833   if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1834     {
1835       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1836          && ! always)
1837        return 0;
1838 
1839       zlog (peer->log, LOG_INFO,
1840 	    "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1841 	    afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1842 	    peer->pmax[afi][safi]);
1843       SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1844     }
1845   else
1846     UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1847   return 0;
1848 }
1849 
1850 /* Unconditionally remove the route from the RIB, without taking
1851  * damping into consideration (eg, because the session went down)
1852  */
1853 static void
bgp_rib_remove(struct bgp_node * rn,struct bgp_info * ri,struct peer * peer,afi_t afi,safi_t safi)1854 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1855 		afi_t afi, safi_t safi)
1856 {
1857   bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1858 
1859   if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1860     bgp_info_delete (rn, ri); /* keep historical info */
1861 
1862   bgp_process (peer->bgp, rn, afi, safi);
1863 }
1864 
1865 static void
bgp_rib_withdraw(struct bgp_node * rn,struct bgp_info * ri,struct peer * peer,afi_t afi,safi_t safi,struct prefix_rd * prd)1866 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1867 		  afi_t afi, safi_t safi, struct prefix_rd *prd)
1868 {
1869   int status = BGP_DAMP_NONE;
1870 
1871   /* apply dampening, if result is suppressed, we'll be retaining
1872    * the bgp_info in the RIB for historical reference.
1873    */
1874   if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1875       && peer->sort == BGP_PEER_EBGP)
1876     if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1877          == BGP_DAMP_SUPPRESSED)
1878       {
1879         bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1880         return;
1881       }
1882 
1883   bgp_rib_remove (rn, ri, peer, afi, safi);
1884 }
1885 
1886 static struct bgp_info *
info_make(int type,int sub_type,struct peer * peer,struct attr * attr,struct bgp_node * rn)1887 info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1888 	   struct bgp_node *rn)
1889 {
1890   struct bgp_info *new;
1891 
1892   /* Make new BGP info. */
1893   new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1894   new->type = type;
1895   new->sub_type = sub_type;
1896   new->peer = peer;
1897   new->attr = attr;
1898   new->uptime = bgp_clock ();
1899   new->net = rn;
1900   return new;
1901 }
1902 
1903 static void
bgp_update_rsclient(struct peer * rsclient,afi_t afi,safi_t safi,struct attr * attr,struct peer * peer,struct prefix * p,int type,int sub_type,struct prefix_rd * prd,u_char * tag)1904 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1905       struct attr *attr, struct peer *peer, struct prefix *p, int type,
1906       int sub_type, struct prefix_rd *prd, u_char *tag)
1907 {
1908   struct bgp_node *rn;
1909   struct bgp *bgp;
1910   struct attr new_attr;
1911   struct attr_extra new_extra;
1912   struct attr *attr_new;
1913   struct attr *attr_new2;
1914   struct bgp_info *ri;
1915   struct bgp_info *new;
1916   const char *reason;
1917   char buf[SU_ADDRSTRLEN];
1918 
1919   /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1920   if (peer == rsclient)
1921     return;
1922 
1923   bgp = peer->bgp;
1924   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1925 
1926   /* Check previously received route. */
1927   for (ri = rn->info; ri; ri = ri->next)
1928     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1929       break;
1930 
1931   /* AS path loop check. */
1932   if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
1933     {
1934       reason = "as-path contains our own AS;";
1935       goto filtered;
1936     }
1937 
1938   /* Route reflector originator ID check.  */
1939   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1940       && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
1941     {
1942       reason = "originator is us;";
1943       goto filtered;
1944     }
1945 
1946   new_attr.extra = &new_extra;
1947   bgp_attr_dup (&new_attr, attr);
1948 
1949   /* Apply export policy. */
1950   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1951         bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1952     {
1953       reason = "export-policy;";
1954       goto filtered;
1955     }
1956 
1957   attr_new2 = bgp_attr_intern (&new_attr);
1958 
1959   /* Apply import policy. */
1960   if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1961     {
1962       bgp_attr_unintern (&attr_new2);
1963 
1964       reason = "import-policy;";
1965       goto filtered;
1966     }
1967 
1968   attr_new = bgp_attr_intern (&new_attr);
1969   bgp_attr_unintern (&attr_new2);
1970 
1971   /* IPv4 unicast next hop check.  */
1972   if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
1973     {
1974      /* Next hop must not be 0.0.0.0 nor Class D/E address. */
1975       if (new_attr.nexthop.s_addr == 0
1976          || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
1977        {
1978          bgp_attr_unintern (&attr_new);
1979 
1980          reason = "martian next-hop;";
1981          goto filtered;
1982        }
1983     }
1984 
1985   /* If the update is implicit withdraw. */
1986   if (ri)
1987     {
1988       ri->uptime = bgp_clock ();
1989 
1990       /* Same attribute comes in. */
1991       if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1992           && attrhash_cmp (ri->attr, attr_new))
1993         {
1994 
1995 
1996           if (BGP_DEBUG (update, UPDATE_IN))
1997             zlog (peer->log, LOG_DEBUG,
1998                     "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1999                     peer->host,
2000                     inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2001                     p->prefixlen, rsclient->host);
2002 
2003           bgp_unlock_node (rn);
2004           bgp_attr_unintern (&attr_new);
2005           bgp_attr_flush(&new_attr);
2006           return;
2007         }
2008 
2009       /* Withdraw/Announce before we fully processed the withdraw */
2010       if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2011         bgp_info_restore (rn, ri);
2012 
2013       /* Received Logging. */
2014       if (BGP_DEBUG (update, UPDATE_IN))
2015         zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
2016                 peer->host,
2017                 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2018                 p->prefixlen, rsclient->host);
2019 
2020       /* The attribute is changed. */
2021       bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2022 
2023       /* Update to new attribute.  */
2024       bgp_attr_unintern (&ri->attr);
2025       ri->attr = attr_new;
2026 
2027       /* Update MPLS tag.  */
2028       if (safi == SAFI_MPLS_VPN)
2029         memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2030 
2031       bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2032 
2033       /* Process change. */
2034       bgp_process (bgp, rn, afi, safi);
2035       bgp_unlock_node (rn);
2036 
2037       return;
2038     }
2039 
2040   /* Received Logging. */
2041   if (BGP_DEBUG (update, UPDATE_IN))
2042     {
2043       zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
2044               peer->host,
2045               inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2046               p->prefixlen, rsclient->host);
2047     }
2048 
2049   new = info_make(type, sub_type, peer, attr_new, rn);
2050 
2051   /* Update MPLS tag. */
2052   if (safi == SAFI_MPLS_VPN)
2053     memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2054 
2055   bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2056 
2057   /* Register new BGP information. */
2058   bgp_info_add (rn, new);
2059 
2060   /* route_node_get lock */
2061   bgp_unlock_node (rn);
2062 
2063   /* Process change. */
2064   bgp_process (bgp, rn, afi, safi);
2065 
2066   return;
2067 
2068  filtered:
2069 
2070   /* This BGP update is filtered.  Log the reason then update BGP entry.  */
2071   if (BGP_DEBUG (update, UPDATE_IN))
2072         zlog (peer->log, LOG_DEBUG,
2073         "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2074         peer->host,
2075         inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2076         p->prefixlen, rsclient->host, reason);
2077 
2078   if (ri)
2079     bgp_rib_remove (rn, ri, peer, afi, safi);
2080 
2081   bgp_unlock_node (rn);
2082 
2083   return;
2084 }
2085 
2086 static void
bgp_withdraw_rsclient(struct peer * rsclient,afi_t afi,safi_t safi,struct peer * peer,struct prefix * p,int type,int sub_type,struct prefix_rd * prd,u_char * tag)2087 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2088       struct peer *peer, struct prefix *p, int type, int sub_type,
2089       struct prefix_rd *prd, u_char *tag)
2090 {
2091   struct bgp_node *rn;
2092   struct bgp_info *ri;
2093   char buf[SU_ADDRSTRLEN];
2094 
2095   if (rsclient == peer)
2096     return;
2097 
2098   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2099 
2100   /* Lookup withdrawn route. */
2101   for (ri = rn->info; ri; ri = ri->next)
2102     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2103       break;
2104 
2105   /* Withdraw specified route from routing table. */
2106   if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2107     bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2108   else if (BGP_DEBUG (update, UPDATE_IN))
2109     zlog (peer->log, LOG_DEBUG,
2110           "%s Can't find the route %s/%d", peer->host,
2111           inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2112           p->prefixlen);
2113 
2114   /* Unlock bgp_node_get() lock. */
2115   bgp_unlock_node (rn);
2116 }
2117 
2118 static int
bgp_update_main(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi,int type,int sub_type,struct prefix_rd * prd,u_char * tag,int soft_reconfig)2119 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
2120 	    afi_t afi, safi_t safi, int type, int sub_type,
2121 	    struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2122 {
2123   int ret;
2124   int aspath_loop_count = 0;
2125   struct bgp_node *rn;
2126   struct bgp *bgp;
2127   struct attr new_attr;
2128   struct attr_extra new_extra;
2129   struct attr *attr_new;
2130   struct bgp_info *ri;
2131   struct bgp_info *new;
2132   const char *reason;
2133   char buf[SU_ADDRSTRLEN];
2134   int connected = 0;
2135 
2136   memset (&new_attr, 0, sizeof(struct attr));
2137   memset (&new_extra, 0, sizeof(struct attr_extra));
2138 
2139   bgp = peer->bgp;
2140   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2141 
2142   /* When peer's soft reconfiguration enabled.  Record input packet in
2143      Adj-RIBs-In.  */
2144   if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2145       && peer != bgp->peer_self)
2146     bgp_adj_in_set (rn, peer, attr);
2147 
2148   /* Check previously received route. */
2149   for (ri = rn->info; ri; ri = ri->next)
2150     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2151       break;
2152 
2153   /* AS path local-as loop check. */
2154   if (peer->change_local_as)
2155     {
2156       if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2157 	aspath_loop_count = 1;
2158 
2159       if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2160 	{
2161 	  reason = "as-path contains our own AS;";
2162 	  goto filtered;
2163 	}
2164     }
2165 
2166   /* AS path loop check. */
2167   if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2168       || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2169 	  && aspath_loop_check(attr->aspath, bgp->confed_id)
2170 	  > peer->allowas_in[afi][safi]))
2171     {
2172       reason = "as-path contains our own AS;";
2173       goto filtered;
2174     }
2175 
2176   /* Route reflector originator ID check.  */
2177   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2178       && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2179     {
2180       reason = "originator is us;";
2181       goto filtered;
2182     }
2183 
2184   /* Route reflector cluster ID check.  */
2185   if (bgp_cluster_filter (peer, attr))
2186     {
2187       reason = "reflected from the same cluster;";
2188       goto  filtered;
2189     }
2190 
2191   /* Apply incoming filter.  */
2192   if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2193     {
2194       reason = "filter;";
2195       goto filtered;
2196     }
2197 
2198   new_attr.extra = &new_extra;
2199   bgp_attr_dup (&new_attr, attr);
2200 
2201   /* Apply incoming route-map.
2202    * NB: new_attr may now contain newly allocated values from route-map "set"
2203    * commands, so we need bgp_attr_flush in the error paths, until we intern
2204    * the attr (which takes over the memory references) */
2205   if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2206     {
2207       reason = "route-map;";
2208       bgp_attr_flush (&new_attr);
2209       goto filtered;
2210     }
2211 
2212   /* IPv4 unicast next hop check.  */
2213   if (afi == AFI_IP && safi == SAFI_UNICAST)
2214     {
2215       /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
2216 	 must not be my own address.  */
2217       if (new_attr.nexthop.s_addr == 0
2218 	  || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2219 	  || bgp_nexthop_self (&new_attr))
2220 	{
2221 	  reason = "martian next-hop;";
2222 	  bgp_attr_flush (&new_attr);
2223 	  goto filtered;
2224 	}
2225     }
2226 
2227   attr_new = bgp_attr_intern (&new_attr);
2228 
2229   /* If the update is implicit withdraw. */
2230   if (ri)
2231     {
2232       ri->uptime = bgp_clock ();
2233 
2234       /* Same attribute comes in. */
2235       if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2236           && attrhash_cmp (ri->attr, attr_new))
2237 	{
2238 	  if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2239 	      && peer->sort == BGP_PEER_EBGP
2240 	      && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2241 	    {
2242 	      if (BGP_DEBUG (update, UPDATE_IN))
2243 		  zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2244 		  peer->host,
2245 		  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2246 		  p->prefixlen);
2247 
2248 	      if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2249 	        {
2250                   bgp_aggregate_increment (bgp, p, ri, afi, safi);
2251                   bgp_process (bgp, rn, afi, safi);
2252                 }
2253 	    }
2254           else /* Duplicate - odd */
2255 	    {
2256 	      if (BGP_DEBUG (update, UPDATE_IN))
2257 		zlog (peer->log, LOG_DEBUG,
2258 		"%s rcvd %s/%d...duplicate ignored",
2259 		peer->host,
2260 		inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2261 		p->prefixlen);
2262 
2263 	      /* graceful restart STALE flag unset. */
2264 	      if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2265 		{
2266 		  bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2267 		  bgp_process (bgp, rn, afi, safi);
2268 		}
2269 	    }
2270 
2271 	  bgp_unlock_node (rn);
2272 	  bgp_attr_unintern (&attr_new);
2273           bgp_attr_flush (&new_attr);
2274 
2275 	  return 0;
2276 	}
2277 
2278       /* Withdraw/Announce before we fully processed the withdraw */
2279       if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2280         {
2281           if (BGP_DEBUG (update, UPDATE_IN))
2282             zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2283             peer->host,
2284             inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2285             p->prefixlen);
2286           bgp_info_restore (rn, ri);
2287         }
2288 
2289       /* Received Logging. */
2290       if (BGP_DEBUG (update, UPDATE_IN))
2291 	zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2292 	      peer->host,
2293 	      inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2294 	      p->prefixlen);
2295 
2296       /* graceful restart STALE flag unset. */
2297       if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2298 	bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2299 
2300       /* The attribute is changed. */
2301       bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2302 
2303       /* implicit withdraw, decrement aggregate and pcount here.
2304        * only if update is accepted, they'll increment below.
2305        */
2306       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2307 
2308       /* Update bgp route dampening information.  */
2309       if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2310 	  && peer->sort == BGP_PEER_EBGP)
2311 	{
2312 	  /* This is implicit withdraw so we should update dampening
2313 	     information.  */
2314 	  if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2315 	    bgp_damp_withdraw (ri, rn, afi, safi, 1);
2316 	}
2317 
2318       /* Update to new attribute.  */
2319       bgp_attr_unintern (&ri->attr);
2320       ri->attr = attr_new;
2321 
2322       /* Update MPLS tag.  */
2323       if (safi == SAFI_MPLS_VPN)
2324         memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2325 
2326       bgp_attr_flush (&new_attr);
2327 
2328       /* Update bgp route dampening information.  */
2329       if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2330 	  && peer->sort == BGP_PEER_EBGP)
2331 	{
2332 	  /* Now we do normal update dampening.  */
2333 	  ret = bgp_damp_update (ri, rn, afi, safi);
2334 	  if (ret == BGP_DAMP_SUPPRESSED)
2335 	    {
2336 	      bgp_unlock_node (rn);
2337 	      return 0;
2338 	    }
2339 	}
2340 
2341       /* Nexthop reachability check. */
2342       if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2343 	{
2344 	  if (peer->sort == BGP_PEER_EBGP && peer_ttl (peer) == 1 &&
2345 	      ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2346 	    connected = 1;
2347 	  else
2348 	    connected = 0;
2349 
2350 	  if (bgp_ensure_nexthop (ri, NULL, connected))
2351 	    bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2352 	  else
2353 	    {
2354 	      if (BGP_DEBUG(nht, NHT))
2355 		{
2356 		  char buf1[INET6_ADDRSTRLEN];
2357 		  inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2358 		  zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2359 		}
2360 	      bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2361 	    }
2362 	}
2363       else
2364 	bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2365 
2366       bgp_attr_flush (&new_attr);
2367 
2368       /* Process change. */
2369       bgp_aggregate_increment (bgp, p, ri, afi, safi);
2370 
2371       bgp_process (bgp, rn, afi, safi);
2372       bgp_unlock_node (rn);
2373 
2374       return 0;
2375     }
2376 
2377   /* Received Logging. */
2378   if (BGP_DEBUG (update, UPDATE_IN))
2379     {
2380       zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2381 	    peer->host,
2382 	    inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2383 	    p->prefixlen);
2384     }
2385 
2386   /* Make new BGP info. */
2387   new = info_make(type, sub_type, peer, attr_new, rn);
2388 
2389   /* Update MPLS tag. */
2390   if (safi == SAFI_MPLS_VPN)
2391     memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2392 
2393   /* Nexthop reachability check. */
2394   if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2395     {
2396       if (peer->sort == BGP_PEER_EBGP && peer_ttl (peer) == 1 &&
2397 	  ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2398 	connected = 1;
2399       else
2400 	connected = 0;
2401 
2402       if (bgp_ensure_nexthop (new, NULL, connected))
2403 	bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2404       else
2405 	{
2406 	  if (BGP_DEBUG(nht, NHT))
2407 	    {
2408 	      char buf1[INET6_ADDRSTRLEN];
2409 	      inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2410 	      zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2411 	    }
2412 	  bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2413 	}
2414     }
2415   else
2416     bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2417 
2418   /* Increment prefix */
2419   bgp_aggregate_increment (bgp, p, new, afi, safi);
2420 
2421   /* Register new BGP information. */
2422   bgp_info_add (rn, new);
2423 
2424   /* route_node_get lock */
2425   bgp_unlock_node (rn);
2426 
2427   bgp_attr_flush (&new_attr);
2428 
2429   /* If maximum prefix count is configured and current prefix
2430      count exeed it. */
2431   if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2432     return -1;
2433 
2434   /* Process change. */
2435   bgp_process (bgp, rn, afi, safi);
2436 
2437   return 0;
2438 
2439   /* This BGP update is filtered.  Log the reason then update BGP
2440      entry.  */
2441  filtered:
2442   if (BGP_DEBUG (update, UPDATE_IN))
2443     zlog (peer->log, LOG_DEBUG,
2444 	  "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2445 	  peer->host,
2446 	  inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2447 	  p->prefixlen, reason);
2448 
2449   if (ri)
2450     bgp_rib_remove (rn, ri, peer, afi, safi);
2451 
2452   bgp_unlock_node (rn);
2453   bgp_attr_flush (&new_attr);
2454 
2455   return 0;
2456 }
2457 
2458 int
bgp_update(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi,int type,int sub_type,struct prefix_rd * prd,u_char * tag,int soft_reconfig)2459 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2460             afi_t afi, safi_t safi, int type, int sub_type,
2461             struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2462 {
2463   struct peer *rsclient;
2464   struct listnode *node, *nnode;
2465   struct bgp *bgp;
2466   int ret;
2467 
2468   ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2469           soft_reconfig);
2470 
2471   bgp = peer->bgp;
2472 
2473   /* Process the update for each RS-client. */
2474   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2475     {
2476       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2477         bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2478                 sub_type, prd, tag);
2479     }
2480 
2481   return ret;
2482 }
2483 
2484 int
bgp_withdraw(struct peer * peer,struct prefix * p,struct attr * attr,afi_t afi,safi_t safi,int type,int sub_type,struct prefix_rd * prd,u_char * tag)2485 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2486 	     afi_t afi, safi_t safi, int type, int sub_type,
2487 	     struct prefix_rd *prd, u_char *tag)
2488 {
2489   struct bgp *bgp;
2490   char buf[SU_ADDRSTRLEN];
2491   struct bgp_node *rn;
2492   struct bgp_info *ri;
2493   struct peer *rsclient;
2494   struct listnode *node, *nnode;
2495 
2496   bgp = peer->bgp;
2497 
2498   /* Lookup node. */
2499   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2500 
2501   /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2502    * routes that are filtered.  This tanks out Quagga RS pretty badly due to
2503    * the iteration over all RS clients.
2504    * Since we need to remove the entry from adj_in anyway, do that first and
2505    * if there was no entry, we don't need to do anything more. */
2506   if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2507       && peer != bgp->peer_self)
2508     if (!bgp_adj_in_unset (rn, peer))
2509       {
2510         if (BGP_DEBUG (update, UPDATE_IN))
2511           zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2512                 "not in adj-in", peer->host,
2513                 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2514                 p->prefixlen);
2515         bgp_unlock_node (rn);
2516         return 0;
2517       }
2518 
2519   /* Process the withdraw for each RS-client. */
2520   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2521     {
2522       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2523         bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2524     }
2525 
2526   /* Logging. */
2527   if (BGP_DEBUG (update, UPDATE_IN))
2528     zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2529 	  peer->host,
2530 	  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2531 	  p->prefixlen);
2532 
2533   /* Lookup withdrawn route. */
2534   for (ri = rn->info; ri; ri = ri->next)
2535     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2536       break;
2537 
2538   /* Withdraw specified route from routing table. */
2539   if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2540     bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2541   else if (BGP_DEBUG (update, UPDATE_IN))
2542     zlog (peer->log, LOG_DEBUG,
2543 	  "%s Can't find the route %s/%d", peer->host,
2544 	  inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2545 	  p->prefixlen);
2546 
2547   /* Unlock bgp_node_get() lock. */
2548   bgp_unlock_node (rn);
2549 
2550   return 0;
2551 }
2552 
2553 void
bgp_default_originate(struct peer * peer,afi_t afi,safi_t safi,int withdraw)2554 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2555 {
2556   struct bgp *bgp;
2557   struct attr attr;
2558   struct aspath *aspath;
2559   struct prefix p;
2560   struct peer *from;
2561   struct bgp_node *rn;
2562   struct bgp_info *ri;
2563   int ret = RMAP_DENYMATCH;
2564 
2565   if (!(afi == AFI_IP || afi == AFI_IP6))
2566     return;
2567 
2568   bgp = peer->bgp;
2569   from = bgp->peer_self;
2570 
2571   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2572   aspath = attr.aspath;
2573   attr.local_pref = bgp->default_local_pref;
2574   memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2575 
2576   if (afi == AFI_IP)
2577     str2prefix ("0.0.0.0/0", &p);
2578   else if (afi == AFI_IP6)
2579     {
2580       struct attr_extra *ae = attr.extra;
2581 
2582       str2prefix ("::/0", &p);
2583 
2584       /* IPv6 global nexthop must be included. */
2585       memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2586 	      IPV6_MAX_BYTELEN);
2587 	      ae->mp_nexthop_len = 16;
2588 
2589       /* If the peer is on shared nextwork and we have link-local
2590 	 nexthop set it. */
2591       if (peer->shared_network
2592 	  && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2593 	{
2594 	  memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2595 		  IPV6_MAX_BYTELEN);
2596 	  ae->mp_nexthop_len = 32;
2597 	}
2598     }
2599 
2600   if (peer->default_rmap[afi][safi].name)
2601     {
2602       SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2603       for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2604         {
2605           for (ri = rn->info; ri; ri = ri->next)
2606             {
2607               struct attr dummy_attr;
2608               struct attr_extra dummy_extra;
2609               struct bgp_info info;
2610 
2611               /* Provide dummy so the route-map can't modify the attributes */
2612               dummy_attr.extra = &dummy_extra;
2613               bgp_attr_dup(&dummy_attr, ri->attr);
2614               info.peer = ri->peer;
2615               info.attr = &dummy_attr;
2616 
2617               ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2618                                     RMAP_BGP, &info);
2619 
2620               /* The route map might have set attributes. If we don't flush them
2621                * here, they will be leaked. */
2622               bgp_attr_flush(&dummy_attr);
2623               if (ret != RMAP_DENYMATCH)
2624                 break;
2625             }
2626           if (ret != RMAP_DENYMATCH)
2627             break;
2628         }
2629       bgp->peer_self->rmap_type = 0;
2630 
2631       if (ret == RMAP_DENYMATCH)
2632         withdraw = 1;
2633     }
2634 
2635   if (withdraw)
2636     {
2637       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2638 	bgp_default_withdraw_send (peer, afi, safi);
2639       UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2640     }
2641   else
2642     {
2643       if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2644         {
2645           SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2646           bgp_default_update_send (peer, &attr, afi, safi, from);
2647         }
2648     }
2649 
2650   bgp_attr_extra_free (&attr);
2651   aspath_unintern (&aspath);
2652 }
2653 
2654 static void
bgp_announce_table(struct peer * peer,afi_t afi,safi_t safi,struct bgp_table * table,int rsclient)2655 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2656                    struct bgp_table *table, int rsclient)
2657 {
2658   struct bgp_node *rn;
2659   struct bgp_info *ri;
2660   struct attr attr;
2661   struct attr_extra extra;
2662 
2663   memset(&extra, 0, sizeof(extra));
2664 
2665   if (! table)
2666     table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2667 
2668   if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
2669       && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2670     bgp_default_originate (peer, afi, safi, 0);
2671 
2672   /* It's initialized in bgp_announce_[check|check_rsclient]() */
2673   attr.extra = &extra;
2674 
2675   for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2676     for (ri = rn->info; ri; ri = ri->next)
2677       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2678 	{
2679          if ( (rsclient) ?
2680               (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2681               : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2682 	    bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2683 	  else
2684 	    bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2685 	}
2686 
2687   bgp_attr_flush_encap(&attr);
2688 }
2689 
2690 void
bgp_announce_route(struct peer * peer,afi_t afi,safi_t safi)2691 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2692 {
2693   struct bgp_node *rn;
2694   struct bgp_table *table;
2695 
2696   if (peer->status != Established)
2697     return;
2698 
2699   if (! peer->afc_nego[afi][safi])
2700     return;
2701 
2702   /* First update is deferred until ORF or ROUTE-REFRESH is received */
2703   if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2704     return;
2705 
2706   if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
2707     bgp_announce_table (peer, afi, safi, NULL, 0);
2708   else
2709     for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2710 	 rn = bgp_route_next(rn))
2711       if ((table = (rn->info)) != NULL)
2712        bgp_announce_table (peer, afi, safi, table, 0);
2713 
2714   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2715     bgp_announce_table (peer, afi, safi, NULL, 1);
2716 }
2717 
2718 void
bgp_announce_route_all(struct peer * peer)2719 bgp_announce_route_all (struct peer *peer)
2720 {
2721   afi_t afi;
2722   safi_t safi;
2723 
2724   for (afi = AFI_IP; afi < AFI_MAX; afi++)
2725     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2726       bgp_announce_route (peer, afi, safi);
2727 }
2728 
2729 static void
bgp_soft_reconfig_table_rsclient(struct peer * rsclient,afi_t afi,safi_t safi,struct bgp_table * table,struct prefix_rd * prd)2730 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2731         safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
2732 {
2733   struct bgp_node *rn;
2734   struct bgp_adj_in *ain;
2735 
2736   if (! table)
2737     table = rsclient->bgp->rib[afi][safi];
2738 
2739   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2740     for (ain = rn->adj_in; ain; ain = ain->next)
2741       {
2742         struct bgp_info *ri = rn->info;
2743         u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2744 
2745         bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2746                 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
2747       }
2748 }
2749 
2750 void
bgp_soft_reconfig_rsclient(struct peer * rsclient,afi_t afi,safi_t safi)2751 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2752 {
2753   struct bgp_table *table;
2754   struct bgp_node *rn;
2755 
2756   if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
2757     bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
2758 
2759   else
2760     for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2761             rn = bgp_route_next (rn))
2762       if ((table = rn->info) != NULL)
2763         {
2764           struct prefix_rd prd;
2765           prd.family = AF_UNSPEC;
2766           prd.prefixlen = 64;
2767           memcpy(&prd.val, rn->p.u.val, 8);
2768 
2769           bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2770         }
2771 }
2772 
2773 static void
bgp_soft_reconfig_table(struct peer * peer,afi_t afi,safi_t safi,struct bgp_table * table,struct prefix_rd * prd)2774 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2775 			 struct bgp_table *table, struct prefix_rd *prd)
2776 {
2777   int ret;
2778   struct bgp_node *rn;
2779   struct bgp_adj_in *ain;
2780 
2781   if (! table)
2782     table = peer->bgp->rib[afi][safi];
2783 
2784   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2785     for (ain = rn->adj_in; ain; ain = ain->next)
2786       {
2787 	if (ain->peer == peer)
2788 	  {
2789 	    struct bgp_info *ri = rn->info;
2790 	    u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2791 
2792 	    ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2793 			      ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2794 			      prd, tag, 1);
2795 
2796 	    if (ret < 0)
2797 	      {
2798 		bgp_unlock_node (rn);
2799 		return;
2800 	      }
2801 	    continue;
2802 	  }
2803       }
2804 }
2805 
2806 void
bgp_soft_reconfig_in(struct peer * peer,afi_t afi,safi_t safi)2807 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2808 {
2809   struct bgp_node *rn;
2810   struct bgp_table *table;
2811 
2812   if (peer->status != Established)
2813     return;
2814 
2815   if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
2816     bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2817   else
2818     for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2819 	 rn = bgp_route_next (rn))
2820       if ((table = rn->info) != NULL)
2821         {
2822           struct prefix_rd prd;
2823           prd.family = AF_UNSPEC;
2824           prd.prefixlen = 64;
2825           memcpy(&prd.val, rn->p.u.val, 8);
2826 
2827           bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2828         }
2829 }
2830 
2831 
2832 struct bgp_clear_node_queue
2833 {
2834   struct bgp_node *rn;
2835   enum bgp_clear_route_type purpose;
2836 };
2837 
2838 static wq_item_status
bgp_clear_route_node(struct work_queue * wq,void * data)2839 bgp_clear_route_node (struct work_queue *wq, void *data)
2840 {
2841   struct bgp_clear_node_queue *cnq = data;
2842   struct bgp_node *rn = cnq->rn;
2843   struct peer *peer = wq->spec.data;
2844   struct bgp_info *ri;
2845   afi_t afi = bgp_node_table (rn)->afi;
2846   safi_t safi = bgp_node_table (rn)->safi;
2847 
2848   assert (rn && peer);
2849 
2850   for (ri = rn->info; ri; ri = ri->next)
2851     if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2852       {
2853         /* graceful restart STALE flag set. */
2854         if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2855             && peer->nsf[afi][safi]
2856             && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2857             && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2858           bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2859         else
2860           bgp_rib_remove (rn, ri, peer, afi, safi);
2861         break;
2862       }
2863   return WQ_SUCCESS;
2864 }
2865 
2866 static void
bgp_clear_node_queue_del(struct work_queue * wq,void * data)2867 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2868 {
2869   struct bgp_clear_node_queue *cnq = data;
2870   struct bgp_node *rn = cnq->rn;
2871   struct bgp_table *table = bgp_node_table (rn);
2872 
2873   bgp_unlock_node (rn);
2874   bgp_table_unlock (table);
2875   XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2876 }
2877 
2878 static void
bgp_clear_node_complete(struct work_queue * wq)2879 bgp_clear_node_complete (struct work_queue *wq)
2880 {
2881   struct peer *peer = wq->spec.data;
2882 
2883   /* Tickle FSM to start moving again */
2884   BGP_EVENT_ADD (peer, Clearing_Completed);
2885 
2886   peer_unlock (peer); /* bgp_clear_route */
2887 }
2888 
2889 static void
bgp_clear_node_queue_init(struct peer * peer)2890 bgp_clear_node_queue_init (struct peer *peer)
2891 {
2892   char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2893 
2894   snprintf (wname, sizeof(wname), "clear %s", peer->host);
2895 #undef CLEAR_QUEUE_NAME_LEN
2896 
2897   if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2898     {
2899       zlog_err ("%s: Failed to allocate work queue", __func__);
2900       exit (1);
2901     }
2902   peer->clear_node_queue->spec.hold = 10;
2903   peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2904   peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2905   peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2906   peer->clear_node_queue->spec.max_retries = 0;
2907 
2908   /* we only 'lock' this peer reference when the queue is actually active */
2909   peer->clear_node_queue->spec.data = peer;
2910 }
2911 
2912 static void
bgp_clear_route_table(struct peer * peer,afi_t afi,safi_t safi,struct bgp_table * table,struct peer * rsclient,enum bgp_clear_route_type purpose)2913 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2914                        struct bgp_table *table, struct peer *rsclient,
2915                        enum bgp_clear_route_type purpose)
2916 {
2917   struct bgp_node *rn;
2918 
2919 
2920   if (! table)
2921     table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
2922 
2923   /* If still no table => afi/safi isn't configured at all or smth. */
2924   if (! table)
2925     return;
2926 
2927   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2928     {
2929       struct bgp_info *ri;
2930       struct bgp_adj_in *ain;
2931       struct bgp_adj_out *aout;
2932 
2933       /* XXX:TODO: This is suboptimal, every non-empty route_node is
2934        * queued for every clearing peer, regardless of whether it is
2935        * relevant to the peer at hand.
2936        *
2937        * Overview: There are 3 different indices which need to be
2938        * scrubbed, potentially, when a peer is removed:
2939        *
2940        * 1 peer's routes visible via the RIB (ie accepted routes)
2941        * 2 peer's routes visible by the (optional) peer's adj-in index
2942        * 3 other routes visible by the peer's adj-out index
2943        *
2944        * 3 there is no hurry in scrubbing, once the struct peer is
2945        * removed from bgp->peer, we could just GC such deleted peer's
2946        * adj-outs at our leisure.
2947        *
2948        * 1 and 2 must be 'scrubbed' in some way, at least made
2949        * invisible via RIB index before peer session is allowed to be
2950        * brought back up. So one needs to know when such a 'search' is
2951        * complete.
2952        *
2953        * Ideally:
2954        *
2955        * - there'd be a single global queue or a single RIB walker
2956        * - rather than tracking which route_nodes still need to be
2957        *   examined on a peer basis, we'd track which peers still
2958        *   aren't cleared
2959        *
2960        * Given that our per-peer prefix-counts now should be reliable,
2961        * this may actually be achievable. It doesn't seem to be a huge
2962        * problem at this time,
2963        */
2964       for (ain = rn->adj_in; ain; ain = ain->next)
2965         if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2966           {
2967             bgp_adj_in_remove (rn, ain);
2968             bgp_unlock_node (rn);
2969             break;
2970           }
2971       for (aout = rn->adj_out; aout; aout = aout->next)
2972         if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2973           {
2974             bgp_adj_out_remove (rn, aout, peer, afi, safi);
2975             bgp_unlock_node (rn);
2976             break;
2977           }
2978 
2979       for (ri = rn->info; ri; ri = ri->next)
2980         if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2981           {
2982             struct bgp_clear_node_queue *cnq;
2983 
2984             /* both unlocked in bgp_clear_node_queue_del */
2985             bgp_table_lock (bgp_node_table (rn));
2986             bgp_lock_node (rn);
2987             cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2988                            sizeof (struct bgp_clear_node_queue));
2989             cnq->rn = rn;
2990             cnq->purpose = purpose;
2991             work_queue_add (peer->clear_node_queue, cnq);
2992             break;
2993           }
2994     }
2995   return;
2996 }
2997 
2998 void
bgp_clear_route(struct peer * peer,afi_t afi,safi_t safi,enum bgp_clear_route_type purpose)2999 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3000                  enum bgp_clear_route_type purpose)
3001 {
3002   struct bgp_node *rn;
3003   struct bgp_table *table;
3004   struct peer *rsclient;
3005   struct listnode *node, *nnode;
3006 
3007   if (peer->clear_node_queue == NULL)
3008     bgp_clear_node_queue_init (peer);
3009 
3010   /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3011    * Idle until it receives a Clearing_Completed event. This protects
3012    * against peers which flap faster than we can we clear, which could
3013    * lead to:
3014    *
3015    * a) race with routes from the new session being installed before
3016    *    clear_route_node visits the node (to delete the route of that
3017    *    peer)
3018    * b) resource exhaustion, clear_route_node likely leads to an entry
3019    *    on the process_main queue. Fast-flapping could cause that queue
3020    *    to grow and grow.
3021    */
3022 
3023   /* lock peer in assumption that clear-node-queue will get nodes; if so,
3024    * the unlock will happen upon work-queue completion; other wise, the
3025    * unlock happens at the end of this function.
3026    */
3027   if (!peer->clear_node_queue->thread)
3028     peer_lock (peer); /* bgp_clear_node_complete */
3029   switch (purpose)
3030     {
3031     case BGP_CLEAR_ROUTE_NORMAL:
3032       if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3033         bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3034       else
3035         for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3036              rn = bgp_route_next (rn))
3037           if ((table = rn->info) != NULL)
3038             bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3039 
3040       for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3041         if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3042                        PEER_FLAG_RSERVER_CLIENT))
3043           bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3044       break;
3045 
3046     case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3047       /*
3048        * gpz 091009: TBD why don't we have special handling for
3049        * SAFI_MPLS_VPN here in the original quagga code?
3050        * (and, by extension, for SAFI_ENCAP)
3051        */
3052       bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3053       break;
3054 
3055     default:
3056       assert (0);
3057       break;
3058     }
3059 
3060   /* unlock if no nodes got added to the clear-node-queue. */
3061   if (!peer->clear_node_queue->thread)
3062     peer_unlock (peer);
3063 
3064 }
3065 
3066 void
bgp_clear_route_all(struct peer * peer)3067 bgp_clear_route_all (struct peer *peer)
3068 {
3069   afi_t afi;
3070   safi_t safi;
3071 
3072   for (afi = AFI_IP; afi < AFI_MAX; afi++)
3073     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3074       bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
3075 }
3076 
3077 /*
3078  * Finish freeing things when exiting
3079  */
3080 static void
bgp_drain_workqueue_immediate(struct work_queue * wq)3081 bgp_drain_workqueue_immediate (struct work_queue *wq)
3082 {
3083   if (!wq)
3084     return;
3085 
3086   if (!wq->thread)
3087     {
3088       /*
3089        * no thread implies no queued items
3090        */
3091       assert(!wq->items->count);
3092       return;
3093     }
3094 
3095    while (wq->items->count)
3096      {
3097        if (wq->thread)
3098          thread_cancel(wq->thread);
3099        work_queue_run(wq->thread);
3100      }
3101 }
3102 
3103 /*
3104  * Special function to process clear node queue when bgpd is exiting
3105  * and the thread scheduler is no longer running.
3106  */
3107 void
bgp_peer_clear_node_queue_drain_immediate(struct peer * peer)3108 bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3109 {
3110   if (!peer)
3111     return;
3112 
3113   bgp_drain_workqueue_immediate(peer->clear_node_queue);
3114 }
3115 
3116 /*
3117  * The work queues are not specific to a BGP instance, but the
3118  * items in them refer to BGP instances, so this should be called
3119  * before each BGP instance is deleted.
3120  */
3121 void
bgp_process_queues_drain_immediate(void)3122 bgp_process_queues_drain_immediate(void)
3123 {
3124   bgp_drain_workqueue_immediate(bm->process_main_queue);
3125   bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3126 }
3127 
3128 void
bgp_clear_adj_in(struct peer * peer,afi_t afi,safi_t safi)3129 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3130 {
3131   struct bgp_table *table;
3132   struct bgp_node *rn;
3133   struct bgp_adj_in *ain;
3134 
3135   table = peer->bgp->rib[afi][safi];
3136 
3137   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3138     for (ain = rn->adj_in; ain ; ain = ain->next)
3139       if (ain->peer == peer)
3140 	{
3141           bgp_adj_in_remove (rn, ain);
3142           bgp_unlock_node (rn);
3143           break;
3144 	}
3145 }
3146 
3147 void
bgp_clear_stale_route(struct peer * peer,afi_t afi,safi_t safi)3148 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3149 {
3150   struct bgp_node *rn;
3151   struct bgp_info *ri;
3152   struct bgp_table *table;
3153 
3154   table = peer->bgp->rib[afi][safi];
3155 
3156   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3157     {
3158       for (ri = rn->info; ri; ri = ri->next)
3159 	if (ri->peer == peer)
3160 	  {
3161 	    if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3162 	      bgp_rib_remove (rn, ri, peer, afi, safi);
3163 	    break;
3164 	  }
3165     }
3166 }
3167 
3168 static void
bgp_cleanup_table(struct bgp_table * table,safi_t safi)3169 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3170 {
3171   struct bgp_node *rn;
3172   struct bgp_info *ri;
3173   struct bgp_info *next;
3174 
3175   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3176     for (ri = rn->info; ri; ri = next)
3177       {
3178         next = ri->next;
3179         if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3180             && ri->type == ZEBRA_ROUTE_BGP
3181             && ri->sub_type == BGP_ROUTE_NORMAL)
3182           bgp_zebra_withdraw (&rn->p, ri, safi);
3183       }
3184 }
3185 
3186 /* Delete all kernel routes. */
3187 void
bgp_cleanup_routes(void)3188 bgp_cleanup_routes (void)
3189 {
3190   struct bgp *bgp;
3191   struct listnode *node, *nnode;
3192   afi_t afi;
3193 
3194   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3195     {
3196       for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3197 	{
3198 	  struct bgp_node *rn;
3199 
3200 	  bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3201 
3202 	  /*
3203 	   * VPN and ENCAP tables are two-level (RD is top level)
3204 	   */
3205 	  for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3206                rn = bgp_route_next (rn))
3207 	    {
3208 	      if (rn->info)
3209                 {
3210 		  bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3211 		  bgp_table_finish ((struct bgp_table **)&(rn->info));
3212 		  rn->info = NULL;
3213 		  bgp_unlock_node(rn);
3214                 }
3215 	    }
3216 
3217 	  for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3218                rn = bgp_route_next (rn))
3219 	    {
3220 	      if (rn->info)
3221 		{
3222 		  bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3223 		  bgp_table_finish ((struct bgp_table **)&(rn->info));
3224 		  rn->info = NULL;
3225 		  bgp_unlock_node(rn);
3226 		}
3227 	    }
3228 	}
3229     }
3230 }
3231 
3232 void
bgp_reset(void)3233 bgp_reset (void)
3234 {
3235   vty_reset ();
3236   bgp_zclient_reset ();
3237   access_list_reset ();
3238   prefix_list_reset ();
3239 }
3240 
3241 /* Parse NLRI stream.  Withdraw NLRI is recognized by NULL attr
3242    value. */
3243 int
bgp_nlri_parse_ip(struct peer * peer,struct attr * attr,struct bgp_nlri * packet)3244 bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3245                    struct bgp_nlri *packet)
3246 {
3247   u_char *pnt;
3248   u_char *lim;
3249   struct prefix p;
3250   int psize;
3251   int ret;
3252 
3253   /* Check peer status. */
3254   if (peer->status != Established)
3255     return 0;
3256 
3257   pnt = packet->nlri;
3258   lim = pnt + packet->length;
3259 
3260   /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3261      syntactic validity.  If the field is syntactically incorrect,
3262      then the Error Subcode is set to Invalid Network Field. */
3263   for (; pnt < lim; pnt += psize)
3264     {
3265       /* Clear prefix structure. */
3266       memset (&p, 0, sizeof (struct prefix));
3267 
3268       /* Fetch prefix length. */
3269       p.prefixlen = *pnt++;
3270       /* afi/safi validity already verified by caller, bgp_update_receive */
3271       p.family = afi2family (packet->afi);
3272 
3273       /* Prefix length check. */
3274       if (p.prefixlen > prefix_blen (&p) * 8)
3275         {
3276           plog_err (peer->log,
3277                     "%s [Error] Update packet error"
3278                     " (wrong prefix length %u for afi %u)",
3279                     peer->host, p.prefixlen, packet->afi);
3280           return -1;
3281         }
3282 
3283       /* Packet size overflow check. */
3284       psize = PSIZE (p.prefixlen);
3285 
3286       /* When packet overflow occur return immediately. */
3287       if (pnt + psize > lim)
3288         {
3289           plog_err (peer->log,
3290                     "%s [Error] Update packet error"
3291                     " (prefix length %u overflows packet)",
3292                     peer->host, p.prefixlen);
3293           return -1;
3294         }
3295 
3296       /* Defensive coding, double-check the psize fits in a struct prefix */
3297       if (psize > (ssize_t) sizeof(p.u))
3298         {
3299           plog_err (peer->log,
3300                     "%s [Error] Update packet error"
3301                     " (prefix length %u too large for prefix storage %zu!?!!",
3302                     peer->host, p.prefixlen, sizeof(p.u));
3303           return -1;
3304         }
3305 
3306       /* Fetch prefix from NLRI packet. */
3307       memcpy (&p.u.prefix, pnt, psize);
3308 
3309       /* Check address. */
3310       if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3311 	{
3312 	  if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3313 	    {
3314 	     /*
3315  	      * From RFC4271 Section 6.3:
3316 	      *
3317 	      * If a prefix in the NLRI field is semantically incorrect
3318 	      * (e.g., an unexpected multicast IP address), an error SHOULD
3319 	      * be logged locally, and the prefix SHOULD be ignored.
3320 	      */
3321 	      zlog (peer->log, LOG_ERR,
3322 		    "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3323 		    peer->host, inet_ntoa (p.u.prefix4));
3324 	      continue;
3325 	    }
3326 	}
3327 
3328       /* Check address. */
3329       if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3330 	{
3331 	  if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3332 	    {
3333 	      char buf[BUFSIZ];
3334 
3335 	      zlog (peer->log, LOG_ERR,
3336 		    "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3337 		    peer->host,
3338 		    inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3339 	      continue;
3340 	    }
3341 	  if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3342 	    {
3343 	      char buf[BUFSIZ];
3344 
3345 	      zlog (peer->log, LOG_ERR,
3346 		    "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3347 		    peer->host,
3348 		    inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3349 	      continue;
3350 	    }
3351         }
3352 
3353       /* Normal process. */
3354       if (attr)
3355 	ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3356 			  ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3357       else
3358 	ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3359 			    ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3360 
3361       /* Address family configuration mismatch or maximum-prefix count
3362          overflow. */
3363       if (ret < 0)
3364 	return -1;
3365     }
3366 
3367   /* Packet length consistency check. */
3368   if (pnt != lim)
3369     {
3370       plog_err (peer->log,
3371                 "%s [Error] Update packet error"
3372                 " (prefix length mismatch with total length)",
3373                 peer->host);
3374       return -1;
3375     }
3376 
3377   return 0;
3378 }
3379 
3380 static struct bgp_static *
bgp_static_new(void)3381 bgp_static_new (void)
3382 {
3383   return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3384 }
3385 
3386 static void
bgp_static_free(struct bgp_static * bgp_static)3387 bgp_static_free (struct bgp_static *bgp_static)
3388 {
3389   if (bgp_static->rmap.name)
3390     free (bgp_static->rmap.name);
3391   XFREE (MTYPE_BGP_STATIC, bgp_static);
3392 }
3393 
3394 static void
bgp_static_withdraw_rsclient(struct bgp * bgp,struct peer * rsclient,struct prefix * p,afi_t afi,safi_t safi)3395 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3396         struct prefix *p, afi_t afi, safi_t safi)
3397 {
3398   struct bgp_node *rn;
3399   struct bgp_info *ri;
3400 
3401   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3402 
3403   /* Check selected route and self inserted route. */
3404   for (ri = rn->info; ri; ri = ri->next)
3405     if (ri->peer == bgp->peer_self
3406        && ri->type == ZEBRA_ROUTE_BGP
3407        && ri->sub_type == BGP_ROUTE_STATIC)
3408       break;
3409 
3410   /* Withdraw static BGP route from routing table. */
3411   if (ri)
3412     {
3413       bgp_info_delete (rn, ri);
3414       bgp_process (bgp, rn, afi, safi);
3415     }
3416 
3417   /* Unlock bgp_node_lookup. */
3418   bgp_unlock_node (rn);
3419 }
3420 
3421 static void
bgp_static_update_rsclient(struct peer * rsclient,struct prefix * p,struct bgp_static * bgp_static,afi_t afi,safi_t safi)3422 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3423                             struct bgp_static *bgp_static,
3424                             afi_t afi, safi_t safi)
3425 {
3426   struct bgp_node *rn;
3427   struct bgp_info *ri;
3428   struct bgp_info *new;
3429   struct bgp_info info;
3430   struct attr *attr_new;
3431   struct attr attr;
3432   struct attr new_attr;
3433   struct attr_extra new_extra;
3434   struct bgp *bgp;
3435   int ret;
3436   char buf[SU_ADDRSTRLEN];
3437 
3438   bgp = rsclient->bgp;
3439 
3440   assert (bgp_static);
3441   if (!bgp_static)
3442     return;
3443 
3444   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3445 
3446   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3447 
3448   attr.nexthop = bgp_static->igpnexthop;
3449   attr.med = bgp_static->igpmetric;
3450   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3451 
3452   if (bgp_static->atomic)
3453     attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3454 
3455   /* Apply network route-map for export to this rsclient. */
3456   if (bgp_static->rmap.name)
3457     {
3458       struct attr attr_tmp = attr;
3459       info.peer = rsclient;
3460       info.attr = &attr_tmp;
3461 
3462       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3463       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3464 
3465       ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3466 
3467       rsclient->rmap_type = 0;
3468 
3469       if (ret == RMAP_DENYMATCH)
3470         {
3471           /* Free uninterned attribute. */
3472           bgp_attr_flush (&attr_tmp);
3473 
3474           /* Unintern original. */
3475           aspath_unintern (&attr.aspath);
3476           bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3477           bgp_attr_extra_free (&attr);
3478 
3479           return;
3480         }
3481       attr_new = bgp_attr_intern (&attr_tmp);
3482     }
3483   else
3484     attr_new = bgp_attr_intern (&attr);
3485 
3486   new_attr.extra = &new_extra;
3487   bgp_attr_dup(&new_attr, attr_new);
3488 
3489   SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3490 
3491   if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3492         == RMAP_DENY)
3493     {
3494       /* This BGP update is filtered.  Log the reason then update BGP entry.  */
3495       if (BGP_DEBUG (update, UPDATE_IN))
3496               zlog (rsclient->log, LOG_DEBUG,
3497               "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3498               inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3499               p->prefixlen, rsclient->host);
3500 
3501       bgp->peer_self->rmap_type = 0;
3502 
3503       bgp_attr_unintern (&attr_new);
3504       aspath_unintern (&attr.aspath);
3505       bgp_attr_extra_free (&attr);
3506 
3507       bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3508 
3509       return;
3510     }
3511 
3512   bgp->peer_self->rmap_type = 0;
3513 
3514   bgp_attr_unintern (&attr_new);
3515   attr_new = bgp_attr_intern (&new_attr);
3516 
3517   for (ri = rn->info; ri; ri = ri->next)
3518     if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3519             && ri->sub_type == BGP_ROUTE_STATIC)
3520       break;
3521 
3522   if (ri)
3523        {
3524       if (attrhash_cmp (ri->attr, attr_new) &&
3525 	  !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3526         {
3527           bgp_unlock_node (rn);
3528           bgp_attr_unintern (&attr_new);
3529           aspath_unintern (&attr.aspath);
3530           bgp_attr_extra_free (&attr);
3531           return;
3532        }
3533       else
3534         {
3535           /* The attribute is changed. */
3536           bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3537 
3538           /* Rewrite BGP route information. */
3539 	  if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3540 	    bgp_info_restore(rn, ri);
3541           bgp_attr_unintern (&ri->attr);
3542           ri->attr = attr_new;
3543           ri->uptime = bgp_clock ();
3544 
3545 	  /* Nexthop reachability check. */
3546 	  if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3547 	    {
3548 	      if (bgp_ensure_nexthop (ri, NULL, 0))
3549 		bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3550 	      else
3551 		{
3552 		  if (BGP_DEBUG(nht, NHT))
3553 		    {
3554 		      char buf1[INET6_ADDRSTRLEN];
3555 		      inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3556 				buf1, INET6_ADDRSTRLEN);
3557 		      zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3558 		    }
3559 		  bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3560 		}
3561 	    }
3562           /* Process change. */
3563           bgp_process (bgp, rn, afi, safi);
3564           bgp_unlock_node (rn);
3565           aspath_unintern (&attr.aspath);
3566           bgp_attr_extra_free (&attr);
3567           return;
3568         }
3569     }
3570 
3571   /* Make new BGP info. */
3572   new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3573 		  attr_new, rn);
3574   /* Nexthop reachability check. */
3575   if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3576     {
3577       if (bgp_ensure_nexthop (new, NULL, 0))
3578 	bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3579       else
3580 	{
3581 	  if (BGP_DEBUG(nht, NHT))
3582 	    {
3583 	      char buf1[INET6_ADDRSTRLEN];
3584 	      inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3585 			buf1, INET6_ADDRSTRLEN);
3586 	      zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3587 	    }
3588 	  bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3589 	}
3590     }
3591   else
3592     bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3593 
3594   /* Register new BGP information. */
3595   bgp_info_add (rn, new);
3596 
3597   /* route_node_get lock */
3598   bgp_unlock_node (rn);
3599 
3600   /* Process change. */
3601   bgp_process (bgp, rn, afi, safi);
3602 
3603   /* Unintern original. */
3604   aspath_unintern (&attr.aspath);
3605   bgp_attr_extra_free (&attr);
3606 }
3607 
3608 static void
bgp_static_update_main(struct bgp * bgp,struct prefix * p,struct bgp_static * bgp_static,afi_t afi,safi_t safi)3609 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3610 			struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3611 {
3612   struct bgp_node *rn;
3613   struct bgp_info *ri;
3614   struct bgp_info *new;
3615   struct bgp_info info;
3616   struct attr attr;
3617   struct attr *attr_new;
3618   int ret;
3619 
3620   assert (bgp_static);
3621   if (!bgp_static)
3622     return;
3623 
3624   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3625 
3626   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3627 
3628   attr.nexthop = bgp_static->igpnexthop;
3629   attr.med = bgp_static->igpmetric;
3630   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3631 
3632   if (bgp_static->atomic)
3633     attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3634 
3635   /* Apply route-map. */
3636   if (bgp_static->rmap.name)
3637     {
3638       struct attr attr_tmp = attr;
3639       info.peer = bgp->peer_self;
3640       info.attr = &attr_tmp;
3641 
3642       SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3643 
3644       ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3645 
3646       bgp->peer_self->rmap_type = 0;
3647 
3648       if (ret == RMAP_DENYMATCH)
3649 	{
3650 	  /* Free uninterned attribute. */
3651 	  bgp_attr_flush (&attr_tmp);
3652 
3653 	  /* Unintern original. */
3654 	  aspath_unintern (&attr.aspath);
3655 	  bgp_attr_extra_free (&attr);
3656 	  bgp_static_withdraw (bgp, p, afi, safi);
3657 	  return;
3658 	}
3659       attr_new = bgp_attr_intern (&attr_tmp);
3660     }
3661   else
3662     attr_new = bgp_attr_intern (&attr);
3663 
3664   for (ri = rn->info; ri; ri = ri->next)
3665     if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3666 	&& ri->sub_type == BGP_ROUTE_STATIC)
3667       break;
3668 
3669   if (ri)
3670     {
3671       if (attrhash_cmp (ri->attr, attr_new) &&
3672 	  !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3673 	{
3674 	  bgp_unlock_node (rn);
3675 	  bgp_attr_unintern (&attr_new);
3676 	  aspath_unintern (&attr.aspath);
3677 	  bgp_attr_extra_free (&attr);
3678 	  return;
3679 	}
3680       else
3681 	{
3682 	  /* The attribute is changed. */
3683 	  bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3684 
3685 	  /* Rewrite BGP route information. */
3686 	  if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3687 	    bgp_info_restore(rn, ri);
3688 	  else
3689 	    bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3690 	  bgp_attr_unintern (&ri->attr);
3691 	  ri->attr = attr_new;
3692 	  ri->uptime = bgp_clock ();
3693 
3694 	  /* Nexthop reachability check. */
3695 	  if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3696 	    {
3697 	      if (bgp_ensure_nexthop (ri, NULL, 0))
3698 		bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3699 	      else
3700 		{
3701 		  if (BGP_DEBUG(nht, NHT))
3702 		    {
3703 		      char buf1[INET6_ADDRSTRLEN];
3704 		      inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3705 				buf1, INET6_ADDRSTRLEN);
3706 		      zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3707 		    }
3708 		  bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3709 		}
3710 	    }
3711 	  /* Process change. */
3712 	  bgp_aggregate_increment (bgp, p, ri, afi, safi);
3713 	  bgp_process (bgp, rn, afi, safi);
3714 	  bgp_unlock_node (rn);
3715 	  aspath_unintern (&attr.aspath);
3716 	  bgp_attr_extra_free (&attr);
3717 	  return;
3718 	}
3719     }
3720 
3721   /* Make new BGP info. */
3722   new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3723 		  rn);
3724   /* Nexthop reachability check. */
3725   if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3726     {
3727       if (bgp_ensure_nexthop (new, NULL, 0))
3728 	bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3729       else
3730 	{
3731 	  if (BGP_DEBUG(nht, NHT))
3732 	    {
3733 	      char buf1[INET6_ADDRSTRLEN];
3734 	      inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
3735 			INET6_ADDRSTRLEN);
3736 	      zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3737 	    }
3738 	  bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3739 	}
3740     }
3741   else
3742     bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3743 
3744   /* Aggregate address increment. */
3745   bgp_aggregate_increment (bgp, p, new, afi, safi);
3746 
3747   /* Register new BGP information. */
3748   bgp_info_add (rn, new);
3749 
3750   /* route_node_get lock */
3751   bgp_unlock_node (rn);
3752 
3753   /* Process change. */
3754   bgp_process (bgp, rn, afi, safi);
3755 
3756   /* Unintern original. */
3757   aspath_unintern (&attr.aspath);
3758   bgp_attr_extra_free (&attr);
3759 }
3760 
3761 void
bgp_static_update(struct bgp * bgp,struct prefix * p,struct bgp_static * bgp_static,afi_t afi,safi_t safi)3762 bgp_static_update (struct bgp *bgp, struct prefix *p,
3763                   struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3764 {
3765   struct peer *rsclient;
3766   struct listnode *node, *nnode;
3767 
3768   bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3769 
3770   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3771     {
3772       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3773         bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3774     }
3775 }
3776 
3777 void
bgp_static_withdraw(struct bgp * bgp,struct prefix * p,afi_t afi,safi_t safi)3778 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3779 		     safi_t safi)
3780 {
3781   struct bgp_node *rn;
3782   struct bgp_info *ri;
3783 
3784   /* Make new BGP info. */
3785   rn = bgp_node_get (bgp->rib[afi][safi], p);
3786 
3787   /* Check selected route and self inserted route. */
3788   for (ri = rn->info; ri; ri = ri->next)
3789     if (ri->peer == bgp->peer_self
3790 	&& ri->type == ZEBRA_ROUTE_BGP
3791 	&& ri->sub_type == BGP_ROUTE_STATIC)
3792       break;
3793 
3794   /* Withdraw static BGP route from routing table. */
3795   if (ri)
3796     {
3797       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3798       bgp_unlink_nexthop(ri);
3799       bgp_info_delete (rn, ri);
3800       bgp_process (bgp, rn, afi, safi);
3801     }
3802 
3803   /* Unlock bgp_node_lookup. */
3804   bgp_unlock_node (rn);
3805 }
3806 
3807 void
bgp_check_local_routes_rsclient(struct peer * rsclient,afi_t afi,safi_t safi)3808 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3809 {
3810   struct bgp_static *bgp_static;
3811   struct bgp *bgp;
3812   struct bgp_node *rn;
3813   struct prefix *p;
3814 
3815   bgp = rsclient->bgp;
3816 
3817   for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3818     if ((bgp_static = rn->info) != NULL)
3819       {
3820         p = &rn->p;
3821 
3822         bgp_static_update_rsclient (rsclient, p, bgp_static,
3823                 afi, safi);
3824       }
3825 }
3826 
3827 /*
3828  * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3829  */
3830 static void
bgp_static_withdraw_safi(struct bgp * bgp,struct prefix * p,afi_t afi,safi_t safi,struct prefix_rd * prd,u_char * tag)3831 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3832                           safi_t safi, struct prefix_rd *prd, u_char *tag)
3833 {
3834   struct bgp_node *rn;
3835   struct bgp_info *ri;
3836 
3837   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3838 
3839   /* Check selected route and self inserted route. */
3840   for (ri = rn->info; ri; ri = ri->next)
3841     if (ri->peer == bgp->peer_self
3842 	&& ri->type == ZEBRA_ROUTE_BGP
3843 	&& ri->sub_type == BGP_ROUTE_STATIC)
3844       break;
3845 
3846   /* Withdraw static BGP route from routing table. */
3847   if (ri)
3848     {
3849       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3850       bgp_info_delete (rn, ri);
3851       bgp_process (bgp, rn, afi, safi);
3852     }
3853 
3854   /* Unlock bgp_node_lookup. */
3855   bgp_unlock_node (rn);
3856 }
3857 
3858 static void
bgp_static_update_safi(struct bgp * bgp,struct prefix * p,struct bgp_static * bgp_static,afi_t afi,safi_t safi)3859 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3860                         struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3861 {
3862   struct bgp_node *rn;
3863   struct bgp_info *new;
3864   struct attr *attr_new;
3865   struct attr attr = { 0 };
3866   struct bgp_info *ri;
3867 
3868   assert (bgp_static);
3869 
3870   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3871 
3872   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3873 
3874   attr.nexthop = bgp_static->igpnexthop;
3875   attr.med = bgp_static->igpmetric;
3876   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3877 
3878   /* Apply route-map. */
3879   if (bgp_static->rmap.name)
3880     {
3881       struct attr attr_tmp = attr;
3882       struct bgp_info info;
3883       int ret;
3884 
3885       info.peer = bgp->peer_self;
3886       info.attr = &attr_tmp;
3887 
3888       SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3889 
3890       ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3891 
3892       bgp->peer_self->rmap_type = 0;
3893 
3894       if (ret == RMAP_DENYMATCH)
3895         {
3896           /* Free uninterned attribute. */
3897           bgp_attr_flush (&attr_tmp);
3898 
3899           /* Unintern original. */
3900           aspath_unintern (&attr.aspath);
3901           bgp_attr_extra_free (&attr);
3902           bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3903                                     bgp_static->tag);
3904           return;
3905         }
3906 
3907       attr_new = bgp_attr_intern (&attr_tmp);
3908     }
3909   else
3910     {
3911       attr_new = bgp_attr_intern (&attr);
3912     }
3913 
3914   for (ri = rn->info; ri; ri = ri->next)
3915     if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3916         && ri->sub_type == BGP_ROUTE_STATIC)
3917       break;
3918 
3919   if (ri)
3920     {
3921       if (attrhash_cmp (ri->attr, attr_new) &&
3922           !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3923         {
3924           bgp_unlock_node (rn);
3925           bgp_attr_unintern (&attr_new);
3926           aspath_unintern (&attr.aspath);
3927           bgp_attr_extra_free (&attr);
3928           return;
3929         }
3930       else
3931         {
3932           /* The attribute is changed. */
3933           bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3934 
3935           /* Rewrite BGP route information. */
3936           if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3937             bgp_info_restore(rn, ri);
3938           else
3939             bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3940           bgp_attr_unintern (&ri->attr);
3941           ri->attr = attr_new;
3942           ri->uptime = bgp_clock ();
3943 
3944           /* Process change. */
3945           bgp_aggregate_increment (bgp, p, ri, afi, safi);
3946           bgp_process (bgp, rn, afi, safi);
3947           bgp_unlock_node (rn);
3948           aspath_unintern (&attr.aspath);
3949           bgp_attr_extra_free (&attr);
3950           return;
3951         }
3952     }
3953 
3954 
3955   /* Make new BGP info. */
3956   new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3957 		   attr_new, rn);
3958   SET_FLAG (new->flags, BGP_INFO_VALID);
3959   new->extra = bgp_info_extra_new();
3960   memcpy (new->extra->tag, bgp_static->tag, 3);
3961 
3962   /* Aggregate address increment. */
3963   bgp_aggregate_increment (bgp, p, new, afi, safi);
3964 
3965   /* Register new BGP information. */
3966   bgp_info_add (rn, new);
3967 
3968   /* route_node_get lock */
3969   bgp_unlock_node (rn);
3970 
3971   /* Process change. */
3972   bgp_process (bgp, rn, afi, safi);
3973 
3974   /* Unintern original. */
3975   aspath_unintern (&attr.aspath);
3976   bgp_attr_extra_free (&attr);
3977 }
3978 
3979 /* Configure static BGP network.  When user don't run zebra, static
3980    route should be installed as valid.  */
3981 static int
bgp_static_set(struct vty * vty,struct bgp * bgp,const char * ip_str,afi_t afi,safi_t safi,const char * rmap,int backdoor)3982 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3983                 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3984 {
3985   int ret;
3986   struct prefix p;
3987   struct bgp_static *bgp_static;
3988   struct bgp_node *rn;
3989   u_char need_update = 0;
3990 
3991   /* Convert IP prefix string to struct prefix. */
3992   ret = str2prefix (ip_str, &p);
3993   if (! ret)
3994     {
3995       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3996       return CMD_WARNING;
3997     }
3998   if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3999     {
4000       vty_out (vty, "%% Malformed prefix (link-local address)%s",
4001 	       VTY_NEWLINE);
4002       return CMD_WARNING;
4003     }
4004 
4005   apply_mask (&p);
4006 
4007   /* Set BGP static route configuration. */
4008   rn = bgp_node_get (bgp->route[afi][safi], &p);
4009 
4010   if (rn->info)
4011     {
4012       /* Configuration change. */
4013       bgp_static = rn->info;
4014 
4015       /* Check previous routes are installed into BGP.  */
4016       if (bgp_static->valid && bgp_static->backdoor != backdoor)
4017         need_update = 1;
4018 
4019       bgp_static->backdoor = backdoor;
4020 
4021       if (rmap)
4022 	{
4023 	  if (bgp_static->rmap.name)
4024 	    free (bgp_static->rmap.name);
4025 	  bgp_static->rmap.name = strdup (rmap);
4026 	  bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4027 	}
4028       else
4029 	{
4030 	  if (bgp_static->rmap.name)
4031 	    free (bgp_static->rmap.name);
4032 	  bgp_static->rmap.name = NULL;
4033 	  bgp_static->rmap.map = NULL;
4034 	  bgp_static->valid = 0;
4035 	}
4036       bgp_unlock_node (rn);
4037     }
4038   else
4039     {
4040       /* New configuration. */
4041       bgp_static = bgp_static_new ();
4042       bgp_static->backdoor = backdoor;
4043       bgp_static->valid = 0;
4044       bgp_static->igpmetric = 0;
4045       bgp_static->igpnexthop.s_addr = 0;
4046 
4047       if (rmap)
4048 	{
4049 	  if (bgp_static->rmap.name)
4050 	    free (bgp_static->rmap.name);
4051 	  bgp_static->rmap.name = strdup (rmap);
4052 	  bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4053 	}
4054       rn->info = bgp_static;
4055     }
4056 
4057   bgp_static->valid = 1;
4058   if (need_update)
4059     bgp_static_withdraw (bgp, &p, afi, safi);
4060 
4061   if (! bgp_static->backdoor)
4062     bgp_static_update (bgp, &p, bgp_static, afi, safi);
4063 
4064   return CMD_SUCCESS;
4065 }
4066 
4067 /* Configure static BGP network. */
4068 static int
bgp_static_unset(struct vty * vty,struct bgp * bgp,const char * ip_str,afi_t afi,safi_t safi)4069 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4070 		  afi_t afi, safi_t safi)
4071 {
4072   int ret;
4073   struct prefix p;
4074   struct bgp_static *bgp_static;
4075   struct bgp_node *rn;
4076 
4077   /* Convert IP prefix string to struct prefix. */
4078   ret = str2prefix (ip_str, &p);
4079   if (! ret)
4080     {
4081       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4082       return CMD_WARNING;
4083     }
4084   if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4085     {
4086       vty_out (vty, "%% Malformed prefix (link-local address)%s",
4087 	       VTY_NEWLINE);
4088       return CMD_WARNING;
4089     }
4090 
4091   apply_mask (&p);
4092 
4093   rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4094   if (! rn)
4095     {
4096       vty_out (vty, "%% Can't find specified static route configuration.%s",
4097 	       VTY_NEWLINE);
4098       return CMD_WARNING;
4099     }
4100 
4101   bgp_static = rn->info;
4102 
4103   /* Update BGP RIB. */
4104   if (! bgp_static->backdoor)
4105     bgp_static_withdraw (bgp, &p, afi, safi);
4106 
4107   /* Clear configuration. */
4108   bgp_static_free (bgp_static);
4109   rn->info = NULL;
4110   bgp_unlock_node (rn);
4111   bgp_unlock_node (rn);
4112 
4113   return CMD_SUCCESS;
4114 }
4115 
4116 /* Called from bgp_delete().  Delete all static routes from the BGP
4117    instance. */
4118 void
bgp_static_delete(struct bgp * bgp)4119 bgp_static_delete (struct bgp *bgp)
4120 {
4121   afi_t afi;
4122   safi_t safi;
4123   struct bgp_node *rn;
4124   struct bgp_node *rm;
4125   struct bgp_table *table;
4126   struct bgp_static *bgp_static;
4127 
4128   for (afi = AFI_IP; afi < AFI_MAX; afi++)
4129     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4130       for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4131 	if (rn->info != NULL)
4132 	  {
4133 	    if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4134 	      {
4135 		table = rn->info;
4136 
4137 		for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4138 		  {
4139 		    bgp_static = rn->info;
4140 		    bgp_static_withdraw_safi (bgp, &rm->p,
4141 					       AFI_IP, safi,
4142 					       (struct prefix_rd *)&rn->p,
4143 					       bgp_static->tag);
4144 		    bgp_static_free (bgp_static);
4145 		    rn->info = NULL;
4146 		    bgp_unlock_node (rn);
4147 		  }
4148 	      }
4149 	    else
4150 	      {
4151 		bgp_static = rn->info;
4152 		bgp_static_withdraw (bgp, &rn->p, afi, safi);
4153 		bgp_static_free (bgp_static);
4154 		rn->info = NULL;
4155 		bgp_unlock_node (rn);
4156 	      }
4157 	  }
4158 }
4159 
4160 /*
4161  * gpz 110624
4162  * Currently this is used to set static routes for VPN and ENCAP.
4163  * I think it can probably be factored with bgp_static_set.
4164  */
4165 int
bgp_static_set_safi(safi_t safi,struct vty * vty,const char * ip_str,const char * rd_str,const char * tag_str,const char * rmap_str)4166 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4167                      const char *rd_str, const char *tag_str,
4168                      const char *rmap_str)
4169 {
4170   int ret;
4171   struct prefix p;
4172   struct prefix_rd prd;
4173   struct bgp *bgp;
4174   struct bgp_node *prn;
4175   struct bgp_node *rn;
4176   struct bgp_table *table;
4177   struct bgp_static *bgp_static;
4178   u_char tag[3];
4179 
4180   bgp = vty->index;
4181 
4182   ret = str2prefix (ip_str, &p);
4183   if (! ret)
4184     {
4185       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4186       return CMD_WARNING;
4187     }
4188   apply_mask (&p);
4189 
4190   ret = str2prefix_rd (rd_str, &prd);
4191   if (! ret)
4192     {
4193       vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4194       return CMD_WARNING;
4195     }
4196 
4197   ret = str2tag (tag_str, tag);
4198   if (! ret)
4199     {
4200       vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4201       return CMD_WARNING;
4202     }
4203 
4204   prn = bgp_node_get (bgp->route[AFI_IP][safi],
4205 			(struct prefix *)&prd);
4206   if (prn->info == NULL)
4207     prn->info = bgp_table_init (AFI_IP, safi);
4208   else
4209     bgp_unlock_node (prn);
4210   table = prn->info;
4211 
4212   rn = bgp_node_get (table, &p);
4213 
4214   if (rn->info)
4215     {
4216       vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4217       bgp_unlock_node (rn);
4218     }
4219   else
4220     {
4221       /* New configuration. */
4222       bgp_static = bgp_static_new ();
4223       bgp_static->backdoor = 0;
4224       bgp_static->valid = 0;
4225       bgp_static->igpmetric = 0;
4226       bgp_static->igpnexthop.s_addr = 0;
4227       memcpy(bgp_static->tag, tag, 3);
4228       bgp_static->prd = prd;
4229 
4230       if (rmap_str)
4231 	{
4232 	  if (bgp_static->rmap.name)
4233 	    free (bgp_static->rmap.name);
4234 	  bgp_static->rmap.name = strdup (rmap_str);
4235 	  bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4236 	}
4237       rn->info = bgp_static;
4238 
4239       bgp_static->valid = 1;
4240       bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4241     }
4242 
4243   return CMD_SUCCESS;
4244 }
4245 
4246 /* Configure static BGP network. */
4247 int
bgp_static_unset_safi(safi_t safi,struct vty * vty,const char * ip_str,const char * rd_str,const char * tag_str)4248 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4249                       const char *rd_str, const char *tag_str)
4250 {
4251   int ret;
4252   struct bgp *bgp;
4253   struct prefix p;
4254   struct prefix_rd prd;
4255   struct bgp_node *prn;
4256   struct bgp_node *rn;
4257   struct bgp_table *table;
4258   struct bgp_static *bgp_static;
4259   u_char tag[3];
4260 
4261   bgp = vty->index;
4262 
4263   /* Convert IP prefix string to struct prefix. */
4264   ret = str2prefix (ip_str, &p);
4265   if (! ret)
4266     {
4267       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4268       return CMD_WARNING;
4269     }
4270   apply_mask (&p);
4271 
4272   ret = str2prefix_rd (rd_str, &prd);
4273   if (! ret)
4274     {
4275       vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4276       return CMD_WARNING;
4277     }
4278 
4279   ret = str2tag (tag_str, tag);
4280   if (! ret)
4281     {
4282       vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4283       return CMD_WARNING;
4284     }
4285 
4286   prn = bgp_node_get (bgp->route[AFI_IP][safi],
4287 			(struct prefix *)&prd);
4288   if (prn->info == NULL)
4289     prn->info = bgp_table_init (AFI_IP, safi);
4290   else
4291     bgp_unlock_node (prn);
4292   table = prn->info;
4293 
4294   rn = bgp_node_lookup (table, &p);
4295 
4296   if (rn)
4297     {
4298       bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4299 
4300       bgp_static = rn->info;
4301       bgp_static_free (bgp_static);
4302       rn->info = NULL;
4303       bgp_unlock_node (rn);
4304       bgp_unlock_node (rn);
4305     }
4306   else
4307     vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4308 
4309   return CMD_SUCCESS;
4310 }
4311 
4312 DEFUN (bgp_network,
4313        bgp_network_cmd,
4314        "network A.B.C.D/M",
4315        "Specify a network to announce via BGP\n"
4316        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4317 {
4318   return bgp_static_set (vty, vty->index, argv[0],
4319 			 AFI_IP, bgp_node_safi (vty), NULL, 0);
4320 }
4321 
4322 DEFUN (bgp_network_route_map,
4323        bgp_network_route_map_cmd,
4324        "network A.B.C.D/M route-map WORD",
4325        "Specify a network to announce via BGP\n"
4326        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4327        "Route-map to modify the attributes\n"
4328        "Name of the route map\n")
4329 {
4330   return bgp_static_set (vty, vty->index, argv[0],
4331 			 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4332 }
4333 
4334 DEFUN (bgp_network_backdoor,
4335        bgp_network_backdoor_cmd,
4336        "network A.B.C.D/M backdoor",
4337        "Specify a network to announce via BGP\n"
4338        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4339        "Specify a BGP backdoor route\n")
4340 {
4341   return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4342                          NULL, 1);
4343 }
4344 
4345 DEFUN (bgp_network_mask,
4346        bgp_network_mask_cmd,
4347        "network A.B.C.D mask A.B.C.D",
4348        "Specify a network to announce via BGP\n"
4349        "Network number\n"
4350        "Network mask\n"
4351        "Network mask\n")
4352 {
4353   int ret;
4354   char prefix_str[BUFSIZ];
4355 
4356   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4357   if (! ret)
4358     {
4359       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4360       return CMD_WARNING;
4361     }
4362 
4363   return bgp_static_set (vty, vty->index, prefix_str,
4364 			 AFI_IP, bgp_node_safi (vty), NULL, 0);
4365 }
4366 
4367 DEFUN (bgp_network_mask_route_map,
4368        bgp_network_mask_route_map_cmd,
4369        "network A.B.C.D mask A.B.C.D route-map WORD",
4370        "Specify a network to announce via BGP\n"
4371        "Network number\n"
4372        "Network mask\n"
4373        "Network mask\n"
4374        "Route-map to modify the attributes\n"
4375        "Name of the route map\n")
4376 {
4377   int ret;
4378   char prefix_str[BUFSIZ];
4379 
4380   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4381   if (! ret)
4382     {
4383       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4384       return CMD_WARNING;
4385     }
4386 
4387   return bgp_static_set (vty, vty->index, prefix_str,
4388 			 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4389 }
4390 
4391 DEFUN (bgp_network_mask_backdoor,
4392        bgp_network_mask_backdoor_cmd,
4393        "network A.B.C.D mask A.B.C.D backdoor",
4394        "Specify a network to announce via BGP\n"
4395        "Network number\n"
4396        "Network mask\n"
4397        "Network mask\n"
4398        "Specify a BGP backdoor route\n")
4399 {
4400   int ret;
4401   char prefix_str[BUFSIZ];
4402 
4403   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4404   if (! ret)
4405     {
4406       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4407       return CMD_WARNING;
4408     }
4409 
4410   return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4411                          NULL, 1);
4412 }
4413 
4414 DEFUN (bgp_network_mask_natural,
4415        bgp_network_mask_natural_cmd,
4416        "network A.B.C.D",
4417        "Specify a network to announce via BGP\n"
4418        "Network number\n")
4419 {
4420   int ret;
4421   char prefix_str[BUFSIZ];
4422 
4423   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4424   if (! ret)
4425     {
4426       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4427       return CMD_WARNING;
4428     }
4429 
4430   return bgp_static_set (vty, vty->index, prefix_str,
4431 			 AFI_IP, bgp_node_safi (vty), NULL, 0);
4432 }
4433 
4434 DEFUN (bgp_network_mask_natural_route_map,
4435        bgp_network_mask_natural_route_map_cmd,
4436        "network A.B.C.D route-map WORD",
4437        "Specify a network to announce via BGP\n"
4438        "Network number\n"
4439        "Route-map to modify the attributes\n"
4440        "Name of the route map\n")
4441 {
4442   int ret;
4443   char prefix_str[BUFSIZ];
4444 
4445   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4446   if (! ret)
4447     {
4448       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4449       return CMD_WARNING;
4450     }
4451 
4452   return bgp_static_set (vty, vty->index, prefix_str,
4453 			 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4454 }
4455 
4456 DEFUN (bgp_network_mask_natural_backdoor,
4457        bgp_network_mask_natural_backdoor_cmd,
4458        "network A.B.C.D backdoor",
4459        "Specify a network to announce via BGP\n"
4460        "Network number\n"
4461        "Specify a BGP backdoor route\n")
4462 {
4463   int ret;
4464   char prefix_str[BUFSIZ];
4465 
4466   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4467   if (! ret)
4468     {
4469       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4470       return CMD_WARNING;
4471     }
4472 
4473   return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4474                          NULL, 1);
4475 }
4476 
4477 DEFUN (no_bgp_network,
4478        no_bgp_network_cmd,
4479        "no network A.B.C.D/M",
4480        NO_STR
4481        "Specify a network to announce via BGP\n"
4482        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4483 {
4484   return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4485 			   bgp_node_safi (vty));
4486 }
4487 
4488 ALIAS (no_bgp_network,
4489        no_bgp_network_route_map_cmd,
4490        "no network A.B.C.D/M route-map WORD",
4491        NO_STR
4492        "Specify a network to announce via BGP\n"
4493        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4494        "Route-map to modify the attributes\n"
4495        "Name of the route map\n")
4496 
4497 ALIAS (no_bgp_network,
4498        no_bgp_network_backdoor_cmd,
4499        "no network A.B.C.D/M backdoor",
4500        NO_STR
4501        "Specify a network to announce via BGP\n"
4502        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4503        "Specify a BGP backdoor route\n")
4504 
4505 DEFUN (no_bgp_network_mask,
4506        no_bgp_network_mask_cmd,
4507        "no network A.B.C.D mask A.B.C.D",
4508        NO_STR
4509        "Specify a network to announce via BGP\n"
4510        "Network number\n"
4511        "Network mask\n"
4512        "Network mask\n")
4513 {
4514   int ret;
4515   char prefix_str[BUFSIZ];
4516 
4517   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4518   if (! ret)
4519     {
4520       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4521       return CMD_WARNING;
4522     }
4523 
4524   return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4525 			   bgp_node_safi (vty));
4526 }
4527 
4528 ALIAS (no_bgp_network_mask,
4529        no_bgp_network_mask_route_map_cmd,
4530        "no network A.B.C.D mask A.B.C.D route-map WORD",
4531        NO_STR
4532        "Specify a network to announce via BGP\n"
4533        "Network number\n"
4534        "Network mask\n"
4535        "Network mask\n"
4536        "Route-map to modify the attributes\n"
4537        "Name of the route map\n")
4538 
4539 ALIAS (no_bgp_network_mask,
4540        no_bgp_network_mask_backdoor_cmd,
4541        "no network A.B.C.D mask A.B.C.D backdoor",
4542        NO_STR
4543        "Specify a network to announce via BGP\n"
4544        "Network number\n"
4545        "Network mask\n"
4546        "Network mask\n"
4547        "Specify a BGP backdoor route\n")
4548 
4549 DEFUN (no_bgp_network_mask_natural,
4550        no_bgp_network_mask_natural_cmd,
4551        "no network A.B.C.D",
4552        NO_STR
4553        "Specify a network to announce via BGP\n"
4554        "Network number\n")
4555 {
4556   int ret;
4557   char prefix_str[BUFSIZ];
4558 
4559   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4560   if (! ret)
4561     {
4562       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4563       return CMD_WARNING;
4564     }
4565 
4566   return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4567 			   bgp_node_safi (vty));
4568 }
4569 
4570 ALIAS (no_bgp_network_mask_natural,
4571        no_bgp_network_mask_natural_route_map_cmd,
4572        "no network A.B.C.D route-map WORD",
4573        NO_STR
4574        "Specify a network to announce via BGP\n"
4575        "Network number\n"
4576        "Route-map to modify the attributes\n"
4577        "Name of the route map\n")
4578 
4579 ALIAS (no_bgp_network_mask_natural,
4580        no_bgp_network_mask_natural_backdoor_cmd,
4581        "no network A.B.C.D backdoor",
4582        NO_STR
4583        "Specify a network to announce via BGP\n"
4584        "Network number\n"
4585        "Specify a BGP backdoor route\n")
4586 
4587 DEFUN (ipv6_bgp_network,
4588        ipv6_bgp_network_cmd,
4589        "network X:X::X:X/M",
4590        "Specify a network to announce via BGP\n"
4591        "IPv6 prefix <network>/<length>\n")
4592 {
4593   return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4594                          NULL, 0);
4595 }
4596 
4597 DEFUN (ipv6_bgp_network_route_map,
4598        ipv6_bgp_network_route_map_cmd,
4599        "network X:X::X:X/M route-map WORD",
4600        "Specify a network to announce via BGP\n"
4601        "IPv6 prefix <network>/<length>\n"
4602        "Route-map to modify the attributes\n"
4603        "Name of the route map\n")
4604 {
4605   return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4606 			 bgp_node_safi (vty), argv[1], 0);
4607 }
4608 
4609 DEFUN (no_ipv6_bgp_network,
4610        no_ipv6_bgp_network_cmd,
4611        "no network X:X::X:X/M",
4612        NO_STR
4613        "Specify a network to announce via BGP\n"
4614        "IPv6 prefix <network>/<length>\n")
4615 {
4616   return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4617 }
4618 
4619 ALIAS (no_ipv6_bgp_network,
4620        no_ipv6_bgp_network_route_map_cmd,
4621        "no network X:X::X:X/M route-map WORD",
4622        NO_STR
4623        "Specify a network to announce via BGP\n"
4624        "IPv6 prefix <network>/<length>\n"
4625        "Route-map to modify the attributes\n"
4626        "Name of the route map\n")
4627 
4628 ALIAS (ipv6_bgp_network,
4629        old_ipv6_bgp_network_cmd,
4630        "ipv6 bgp network X:X::X:X/M",
4631        IPV6_STR
4632        BGP_STR
4633        "Specify a network to announce via BGP\n"
4634        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4635 
4636 ALIAS (no_ipv6_bgp_network,
4637        old_no_ipv6_bgp_network_cmd,
4638        "no ipv6 bgp network X:X::X:X/M",
4639        NO_STR
4640        IPV6_STR
4641        BGP_STR
4642        "Specify a network to announce via BGP\n"
4643        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4644 
4645 /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4646 ALIAS_DEPRECATED (bgp_network,
4647        bgp_network_ttl_cmd,
4648        "network A.B.C.D/M pathlimit <0-255>",
4649        "Specify a network to announce via BGP\n"
4650        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4651        "AS-Path hopcount limit attribute\n"
4652        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4653 ALIAS_DEPRECATED (bgp_network_backdoor,
4654        bgp_network_backdoor_ttl_cmd,
4655        "network A.B.C.D/M backdoor pathlimit <0-255>",
4656        "Specify a network to announce via BGP\n"
4657        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4658        "Specify a BGP backdoor route\n"
4659        "AS-Path hopcount limit attribute\n"
4660        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4661 ALIAS_DEPRECATED (bgp_network_mask,
4662        bgp_network_mask_ttl_cmd,
4663        "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4664        "Specify a network to announce via BGP\n"
4665        "Network number\n"
4666        "Network mask\n"
4667        "Network mask\n"
4668        "AS-Path hopcount limit attribute\n"
4669        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4670 ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4671        bgp_network_mask_backdoor_ttl_cmd,
4672        "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4673        "Specify a network to announce via BGP\n"
4674        "Network number\n"
4675        "Network mask\n"
4676        "Network mask\n"
4677        "Specify a BGP backdoor route\n"
4678        "AS-Path hopcount limit attribute\n"
4679        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4680 ALIAS_DEPRECATED (bgp_network_mask_natural,
4681        bgp_network_mask_natural_ttl_cmd,
4682        "network A.B.C.D pathlimit <0-255>",
4683        "Specify a network to announce via BGP\n"
4684        "Network number\n"
4685        "AS-Path hopcount limit attribute\n"
4686        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4687 ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4688        bgp_network_mask_natural_backdoor_ttl_cmd,
4689        "network A.B.C.D backdoor pathlimit <1-255>",
4690        "Specify a network to announce via BGP\n"
4691        "Network number\n"
4692        "Specify a BGP backdoor route\n"
4693        "AS-Path hopcount limit attribute\n"
4694        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4695 ALIAS_DEPRECATED (no_bgp_network,
4696        no_bgp_network_ttl_cmd,
4697        "no network A.B.C.D/M pathlimit <0-255>",
4698        NO_STR
4699        "Specify a network to announce via BGP\n"
4700        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4701        "AS-Path hopcount limit attribute\n"
4702        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4703 ALIAS_DEPRECATED (no_bgp_network,
4704        no_bgp_network_backdoor_ttl_cmd,
4705        "no network A.B.C.D/M backdoor pathlimit <0-255>",
4706        NO_STR
4707        "Specify a network to announce via BGP\n"
4708        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4709        "Specify a BGP backdoor route\n"
4710        "AS-Path hopcount limit attribute\n"
4711        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4712 ALIAS_DEPRECATED (no_bgp_network,
4713        no_bgp_network_mask_ttl_cmd,
4714        "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4715        NO_STR
4716        "Specify a network to announce via BGP\n"
4717        "Network number\n"
4718        "Network mask\n"
4719        "Network mask\n"
4720        "AS-Path hopcount limit attribute\n"
4721        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4722 ALIAS_DEPRECATED (no_bgp_network_mask,
4723        no_bgp_network_mask_backdoor_ttl_cmd,
4724        "no network A.B.C.D mask A.B.C.D  backdoor pathlimit <0-255>",
4725        NO_STR
4726        "Specify a network to announce via BGP\n"
4727        "Network number\n"
4728        "Network mask\n"
4729        "Network mask\n"
4730        "Specify a BGP backdoor route\n"
4731        "AS-Path hopcount limit attribute\n"
4732        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4733 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4734        no_bgp_network_mask_natural_ttl_cmd,
4735        "no network A.B.C.D pathlimit <0-255>",
4736        NO_STR
4737        "Specify a network to announce via BGP\n"
4738        "Network number\n"
4739        "AS-Path hopcount limit attribute\n"
4740        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4741 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4742        no_bgp_network_mask_natural_backdoor_ttl_cmd,
4743        "no network A.B.C.D backdoor pathlimit <0-255>",
4744        NO_STR
4745        "Specify a network to announce via BGP\n"
4746        "Network number\n"
4747        "Specify a BGP backdoor route\n"
4748        "AS-Path hopcount limit attribute\n"
4749        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4750 ALIAS_DEPRECATED (ipv6_bgp_network,
4751        ipv6_bgp_network_ttl_cmd,
4752        "network X:X::X:X/M pathlimit <0-255>",
4753        "Specify a network to announce via BGP\n"
4754        "IPv6 prefix <network>/<length>\n"
4755        "AS-Path hopcount limit attribute\n"
4756        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4757 ALIAS_DEPRECATED (no_ipv6_bgp_network,
4758        no_ipv6_bgp_network_ttl_cmd,
4759        "no network X:X::X:X/M pathlimit <0-255>",
4760        NO_STR
4761        "Specify a network to announce via BGP\n"
4762        "IPv6 prefix <network>/<length>\n"
4763        "AS-Path hopcount limit attribute\n"
4764        "AS-Pathlimit TTL, in number of AS-Path hops\n")
4765 
4766 /* Aggreagete address:
4767 
4768   advertise-map  Set condition to advertise attribute
4769   as-set         Generate AS set path information
4770   attribute-map  Set attributes of aggregate
4771   route-map      Set parameters of aggregate
4772   summary-only   Filter more specific routes from updates
4773   suppress-map   Conditionally filter more specific routes from updates
4774   <cr>
4775  */
4776 struct bgp_aggregate
4777 {
4778   /* Summary-only flag. */
4779   u_char summary_only;
4780 
4781   /* AS set generation. */
4782   u_char as_set;
4783 
4784   /* Route-map for aggregated route. */
4785   struct route_map *map;
4786 
4787   /* Suppress-count. */
4788   unsigned long count;
4789 
4790   /* SAFI configuration. */
4791   safi_t safi;
4792 };
4793 
4794 static struct bgp_aggregate *
bgp_aggregate_new(void)4795 bgp_aggregate_new (void)
4796 {
4797   return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4798 }
4799 
4800 static void
bgp_aggregate_free(struct bgp_aggregate * aggregate)4801 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4802 {
4803   XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4804 }
4805 
4806 /* Update an aggregate as routes are added/removed from the BGP table */
4807 static void
bgp_aggregate_route(struct bgp * bgp,struct prefix * p,struct bgp_info * rinew,afi_t afi,safi_t safi,struct bgp_info * del,struct bgp_aggregate * aggregate)4808 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4809 		     afi_t afi, safi_t safi, struct bgp_info *del,
4810 		     struct bgp_aggregate *aggregate)
4811 {
4812   struct bgp_table *table;
4813   struct bgp_node *top;
4814   struct bgp_node *rn;
4815   u_char origin;
4816   struct aspath *aspath = NULL;
4817   struct aspath *asmerge = NULL;
4818   struct community *community = NULL;
4819   struct community *commerge = NULL;
4820   struct bgp_info *ri;
4821   struct bgp_info *new;
4822   int first = 1;
4823   unsigned long match = 0;
4824   u_char atomic_aggregate = 0;
4825 
4826   /* ORIGIN attribute: If at least one route among routes that are
4827      aggregated has ORIGIN with the value INCOMPLETE, then the
4828      aggregated route must have the ORIGIN attribute with the value
4829      INCOMPLETE. Otherwise, if at least one route among routes that
4830      are aggregated has ORIGIN with the value EGP, then the aggregated
4831      route must have the origin attribute with the value EGP. In all
4832      other case the value of the ORIGIN attribute of the aggregated
4833      route is INTERNAL. */
4834   origin = BGP_ORIGIN_IGP;
4835 
4836   table = bgp->rib[afi][safi];
4837 
4838   top = bgp_node_get (table, p);
4839   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4840     if (rn->p.prefixlen > p->prefixlen)
4841       {
4842 	match = 0;
4843 
4844 	for (ri = rn->info; ri; ri = ri->next)
4845 	  {
4846 	    if (BGP_INFO_HOLDDOWN (ri))
4847 	      continue;
4848 
4849 	    if (del && ri == del)
4850 	      continue;
4851 
4852 	    if (! rinew && first)
4853               first = 0;
4854 
4855 #ifdef AGGREGATE_NEXTHOP_CHECK
4856 	    if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4857 		|| ri->attr->med != med)
4858 	      {
4859 		if (aspath)
4860 		  aspath_free (aspath);
4861 		if (community)
4862 		  community_free (community);
4863 		bgp_unlock_node (rn);
4864 		bgp_unlock_node (top);
4865 		return;
4866 	      }
4867 #endif /* AGGREGATE_NEXTHOP_CHECK */
4868 
4869             if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4870               atomic_aggregate = 1;
4871 
4872 	    if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4873 	      {
4874 		if (aggregate->summary_only)
4875 		  {
4876 		    (bgp_info_extra_get (ri))->suppress++;
4877 		    bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4878 		    match++;
4879 		  }
4880 
4881 		aggregate->count++;
4882 
4883 		if (origin < ri->attr->origin)
4884 		  origin = ri->attr->origin;
4885 
4886 		if (aggregate->as_set)
4887 		  {
4888 		    if (aspath)
4889 		      {
4890 			asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4891 			aspath_free (aspath);
4892 			aspath = asmerge;
4893 		      }
4894 		    else
4895 		      aspath = aspath_dup (ri->attr->aspath);
4896 
4897 		    if (ri->attr->community)
4898 		      {
4899 			if (community)
4900 			  {
4901 			    commerge = community_merge (community,
4902 							ri->attr->community);
4903 			    community = community_uniq_sort (commerge);
4904 			    community_free (commerge);
4905 			  }
4906 			else
4907 			  community = community_dup (ri->attr->community);
4908 		      }
4909 		  }
4910 	      }
4911 	  }
4912 	if (match)
4913 	  bgp_process (bgp, rn, afi, safi);
4914       }
4915   bgp_unlock_node (top);
4916 
4917   if (rinew)
4918     {
4919       aggregate->count++;
4920 
4921       if (aggregate->summary_only)
4922         (bgp_info_extra_get (rinew))->suppress++;
4923 
4924       if (origin < rinew->attr->origin)
4925         origin = rinew->attr->origin;
4926 
4927       if (aggregate->as_set)
4928 	{
4929 	  if (aspath)
4930 	    {
4931 	      asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4932 	      aspath_free (aspath);
4933 	      aspath = asmerge;
4934 	    }
4935 	  else
4936 	    aspath = aspath_dup (rinew->attr->aspath);
4937 
4938 	  if (rinew->attr->community)
4939 	    {
4940 	      if (community)
4941 		{
4942 		  commerge = community_merge (community,
4943 					      rinew->attr->community);
4944 		  community = community_uniq_sort (commerge);
4945 		  community_free (commerge);
4946 		}
4947 	      else
4948 		community = community_dup (rinew->attr->community);
4949 	    }
4950 	}
4951     }
4952 
4953   if (aggregate->count > 0)
4954     {
4955       rn = bgp_node_get (table, p);
4956       new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4957 		      bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4958 						aggregate->as_set,
4959                                                 atomic_aggregate), rn);
4960       SET_FLAG (new->flags, BGP_INFO_VALID);
4961 
4962       bgp_info_add (rn, new);
4963       bgp_unlock_node (rn);
4964       bgp_process (bgp, rn, afi, safi);
4965     }
4966   else
4967     {
4968       if (aspath)
4969 	aspath_free (aspath);
4970       if (community)
4971 	community_free (community);
4972     }
4973 }
4974 
4975 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4976 			   struct bgp_aggregate *);
4977 
4978 void
bgp_aggregate_increment(struct bgp * bgp,struct prefix * p,struct bgp_info * ri,afi_t afi,safi_t safi)4979 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4980 			 struct bgp_info *ri, afi_t afi, safi_t safi)
4981 {
4982   struct bgp_node *child;
4983   struct bgp_node *rn;
4984   struct bgp_aggregate *aggregate;
4985   struct bgp_table *table;
4986 
4987   /* MPLS-VPN aggregation is not yet supported. */
4988   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4989     return;
4990 
4991   table = bgp->aggregate[afi][safi];
4992 
4993   /* No aggregates configured. */
4994   if (bgp_table_top_nolock (table) == NULL)
4995     return;
4996 
4997   if (p->prefixlen == 0)
4998     return;
4999 
5000   if (BGP_INFO_HOLDDOWN (ri))
5001     return;
5002 
5003   child = bgp_node_get (table, p);
5004 
5005   /* Aggregate address configuration check. */
5006   for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5007     if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5008       {
5009 	bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5010 	bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5011       }
5012   bgp_unlock_node (child);
5013 }
5014 
5015 void
bgp_aggregate_decrement(struct bgp * bgp,struct prefix * p,struct bgp_info * del,afi_t afi,safi_t safi)5016 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5017 			 struct bgp_info *del, afi_t afi, safi_t safi)
5018 {
5019   struct bgp_node *child;
5020   struct bgp_node *rn;
5021   struct bgp_aggregate *aggregate;
5022   struct bgp_table *table;
5023 
5024   /* MPLS-VPN aggregation is not yet supported. */
5025   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5026     return;
5027 
5028   table = bgp->aggregate[afi][safi];
5029 
5030   /* No aggregates configured. */
5031   if (bgp_table_top_nolock (table) == NULL)
5032     return;
5033 
5034   if (p->prefixlen == 0)
5035     return;
5036 
5037   child = bgp_node_get (table, p);
5038 
5039   /* Aggregate address configuration check. */
5040   for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5041     if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5042       {
5043 	bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5044 	bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5045       }
5046   bgp_unlock_node (child);
5047 }
5048 
5049 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5050 static void
bgp_aggregate_add(struct bgp * bgp,struct prefix * p,afi_t afi,safi_t safi,struct bgp_aggregate * aggregate)5051 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5052 		   struct bgp_aggregate *aggregate)
5053 {
5054   struct bgp_table *table;
5055   struct bgp_node *top;
5056   struct bgp_node *rn;
5057   struct bgp_info *new;
5058   struct bgp_info *ri;
5059   unsigned long match;
5060   u_char origin = BGP_ORIGIN_IGP;
5061   struct aspath *aspath = NULL;
5062   struct aspath *asmerge = NULL;
5063   struct community *community = NULL;
5064   struct community *commerge = NULL;
5065   u_char atomic_aggregate = 0;
5066 
5067   table = bgp->rib[afi][safi];
5068 
5069   /* Sanity check. */
5070   if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5071     return;
5072   if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5073     return;
5074 
5075   /* If routes exists below this node, generate aggregate routes. */
5076   top = bgp_node_get (table, p);
5077   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5078     if (rn->p.prefixlen > p->prefixlen)
5079       {
5080 	match = 0;
5081 
5082 	for (ri = rn->info; ri; ri = ri->next)
5083 	  {
5084 	    if (BGP_INFO_HOLDDOWN (ri))
5085 	      continue;
5086 
5087             if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5088               atomic_aggregate = 1;
5089 
5090 	    if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5091 	      {
5092 		/* summary-only aggregate route suppress aggregated
5093 		   route announcement.  */
5094 		if (aggregate->summary_only)
5095 		  {
5096 		    (bgp_info_extra_get (ri))->suppress++;
5097 		    bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5098 		    match++;
5099 		  }
5100 
5101                 /* If at least one route among routes that are aggregated has
5102                  * ORIGIN with the value INCOMPLETE, then the aggregated route
5103                  * MUST have the ORIGIN attribute with the value INCOMPLETE.
5104                  * Otherwise, if at least one route among routes that are
5105                  * aggregated has ORIGIN with the value EGP, then the aggregated
5106                  * route MUST have the ORIGIN attribute with the value EGP.
5107                  */
5108                 if (origin < ri->attr->origin)
5109                     origin = ri->attr->origin;
5110 
5111 		/* as-set aggregate route generate origin, as path,
5112 		   community aggregation.  */
5113 		if (aggregate->as_set)
5114 		  {
5115 		    if (aspath)
5116 		      {
5117 			asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5118 			aspath_free (aspath);
5119 			aspath = asmerge;
5120 		      }
5121 		    else
5122 		      aspath = aspath_dup (ri->attr->aspath);
5123 
5124 		    if (ri->attr->community)
5125 		      {
5126 			if (community)
5127 			  {
5128 			    commerge = community_merge (community,
5129 							ri->attr->community);
5130 			    community = community_uniq_sort (commerge);
5131 			    community_free (commerge);
5132 			  }
5133 			else
5134 			  community = community_dup (ri->attr->community);
5135 		      }
5136 		  }
5137 		aggregate->count++;
5138 	      }
5139 	  }
5140 
5141 	/* If this node is suppressed, process the change. */
5142 	if (match)
5143 	  bgp_process (bgp, rn, afi, safi);
5144       }
5145   bgp_unlock_node (top);
5146 
5147   /* Add aggregate route to BGP table. */
5148   if (aggregate->count)
5149     {
5150       rn = bgp_node_get (table, p);
5151       new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5152 		      bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5153 						aggregate->as_set,
5154                                                 atomic_aggregate), rn);
5155       SET_FLAG (new->flags, BGP_INFO_VALID);
5156 
5157       bgp_info_add (rn, new);
5158       bgp_unlock_node (rn);
5159 
5160       /* Process change. */
5161       bgp_process (bgp, rn, afi, safi);
5162     }
5163   else
5164     {
5165       if (aspath)
5166 	aspath_free (aspath);
5167       if (community)
5168 	community_free (community);
5169     }
5170 }
5171 
5172 void
bgp_aggregate_delete(struct bgp * bgp,struct prefix * p,afi_t afi,safi_t safi,struct bgp_aggregate * aggregate)5173 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5174 		      safi_t safi, struct bgp_aggregate *aggregate)
5175 {
5176   struct bgp_table *table;
5177   struct bgp_node *top;
5178   struct bgp_node *rn;
5179   struct bgp_info *ri;
5180   unsigned long match;
5181 
5182   table = bgp->rib[afi][safi];
5183 
5184   if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5185     return;
5186   if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5187     return;
5188 
5189   /* If routes exists below this node, generate aggregate routes. */
5190   top = bgp_node_get (table, p);
5191   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5192     if (rn->p.prefixlen > p->prefixlen)
5193       {
5194 	match = 0;
5195 
5196 	for (ri = rn->info; ri; ri = ri->next)
5197 	  {
5198 	    if (BGP_INFO_HOLDDOWN (ri))
5199 	      continue;
5200 
5201 	    if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5202 	      {
5203 		if (aggregate->summary_only && ri->extra)
5204 		  {
5205 		    ri->extra->suppress--;
5206 
5207 		    if (ri->extra->suppress == 0)
5208 		      {
5209 			bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5210 			match++;
5211 		      }
5212 		  }
5213 		aggregate->count--;
5214 	      }
5215 	  }
5216 
5217 	/* If this node was suppressed, process the change. */
5218 	if (match)
5219 	  bgp_process (bgp, rn, afi, safi);
5220       }
5221   bgp_unlock_node (top);
5222 
5223   /* Delete aggregate route from BGP table. */
5224   rn = bgp_node_get (table, p);
5225 
5226   for (ri = rn->info; ri; ri = ri->next)
5227     if (ri->peer == bgp->peer_self
5228 	&& ri->type == ZEBRA_ROUTE_BGP
5229 	&& ri->sub_type == BGP_ROUTE_AGGREGATE)
5230       break;
5231 
5232   /* Withdraw static BGP route from routing table. */
5233   if (ri)
5234     {
5235       bgp_info_delete (rn, ri);
5236       bgp_process (bgp, rn, afi, safi);
5237     }
5238 
5239   /* Unlock bgp_node_lookup. */
5240   bgp_unlock_node (rn);
5241 }
5242 
5243 /* Aggregate route attribute. */
5244 #define AGGREGATE_SUMMARY_ONLY 1
5245 #define AGGREGATE_AS_SET       1
5246 
5247 static int
bgp_aggregate_unset(struct vty * vty,const char * prefix_str,afi_t afi,safi_t safi)5248 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5249                      afi_t afi, safi_t safi)
5250 {
5251   int ret;
5252   struct prefix p;
5253   struct bgp_node *rn;
5254   struct bgp *bgp;
5255   struct bgp_aggregate *aggregate;
5256 
5257   /* Convert string to prefix structure. */
5258   ret = str2prefix (prefix_str, &p);
5259   if (!ret)
5260     {
5261       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5262       return CMD_WARNING;
5263     }
5264   apply_mask (&p);
5265 
5266   /* Get BGP structure. */
5267   bgp = vty->index;
5268 
5269   /* Old configuration check. */
5270   rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5271   if (! rn)
5272     {
5273       vty_out (vty, "%% There is no aggregate-address configuration.%s",
5274                VTY_NEWLINE);
5275       return CMD_WARNING;
5276     }
5277 
5278   aggregate = rn->info;
5279   if (aggregate->safi & SAFI_UNICAST)
5280     bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5281   if (aggregate->safi & SAFI_MULTICAST)
5282     bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5283 
5284   /* Unlock aggregate address configuration. */
5285   rn->info = NULL;
5286   bgp_aggregate_free (aggregate);
5287   bgp_unlock_node (rn);
5288   bgp_unlock_node (rn);
5289 
5290   return CMD_SUCCESS;
5291 }
5292 
5293 static int
bgp_aggregate_set(struct vty * vty,const char * prefix_str,afi_t afi,safi_t safi,u_char summary_only,u_char as_set)5294 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5295                    afi_t afi, safi_t safi,
5296 		   u_char summary_only, u_char as_set)
5297 {
5298   int ret;
5299   struct prefix p;
5300   struct bgp_node *rn;
5301   struct bgp *bgp;
5302   struct bgp_aggregate *aggregate;
5303 
5304   /* Convert string to prefix structure. */
5305   ret = str2prefix (prefix_str, &p);
5306   if (!ret)
5307     {
5308       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5309       return CMD_WARNING;
5310     }
5311   apply_mask (&p);
5312 
5313   /* Get BGP structure. */
5314   bgp = vty->index;
5315 
5316   /* Old configuration check. */
5317   rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5318 
5319   if (rn->info)
5320     {
5321       vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5322       /* try to remove the old entry */
5323       ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5324       if (ret)
5325         {
5326           vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5327 	  bgp_unlock_node (rn);
5328 	  return CMD_WARNING;
5329         }
5330     }
5331 
5332   /* Make aggregate address structure. */
5333   aggregate = bgp_aggregate_new ();
5334   aggregate->summary_only = summary_only;
5335   aggregate->as_set = as_set;
5336   aggregate->safi = safi;
5337   rn->info = aggregate;
5338 
5339   /* Aggregate address insert into BGP routing table. */
5340   if (safi & SAFI_UNICAST)
5341     bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5342   if (safi & SAFI_MULTICAST)
5343     bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5344 
5345   return CMD_SUCCESS;
5346 }
5347 
5348 DEFUN (aggregate_address,
5349        aggregate_address_cmd,
5350        "aggregate-address A.B.C.D/M",
5351        "Configure BGP aggregate entries\n"
5352        "Aggregate prefix\n")
5353 {
5354   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5355 }
5356 
5357 DEFUN (aggregate_address_mask,
5358        aggregate_address_mask_cmd,
5359        "aggregate-address A.B.C.D A.B.C.D",
5360        "Configure BGP aggregate entries\n"
5361        "Aggregate address\n"
5362        "Aggregate mask\n")
5363 {
5364   int ret;
5365   char prefix_str[BUFSIZ];
5366 
5367   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5368 
5369   if (! ret)
5370     {
5371       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5372       return CMD_WARNING;
5373     }
5374 
5375   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5376 			    0, 0);
5377 }
5378 
5379 DEFUN (aggregate_address_summary_only,
5380        aggregate_address_summary_only_cmd,
5381        "aggregate-address A.B.C.D/M summary-only",
5382        "Configure BGP aggregate entries\n"
5383        "Aggregate prefix\n"
5384        "Filter more specific routes from updates\n")
5385 {
5386   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5387 			    AGGREGATE_SUMMARY_ONLY, 0);
5388 }
5389 
5390 DEFUN (aggregate_address_mask_summary_only,
5391        aggregate_address_mask_summary_only_cmd,
5392        "aggregate-address A.B.C.D A.B.C.D summary-only",
5393        "Configure BGP aggregate entries\n"
5394        "Aggregate address\n"
5395        "Aggregate mask\n"
5396        "Filter more specific routes from updates\n")
5397 {
5398   int ret;
5399   char prefix_str[BUFSIZ];
5400 
5401   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5402 
5403   if (! ret)
5404     {
5405       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5406       return CMD_WARNING;
5407     }
5408 
5409   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5410 			    AGGREGATE_SUMMARY_ONLY, 0);
5411 }
5412 
5413 DEFUN (aggregate_address_as_set,
5414        aggregate_address_as_set_cmd,
5415        "aggregate-address A.B.C.D/M as-set",
5416        "Configure BGP aggregate entries\n"
5417        "Aggregate prefix\n"
5418        "Generate AS set path information\n")
5419 {
5420   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5421 			    0, AGGREGATE_AS_SET);
5422 }
5423 
5424 DEFUN (aggregate_address_mask_as_set,
5425        aggregate_address_mask_as_set_cmd,
5426        "aggregate-address A.B.C.D A.B.C.D as-set",
5427        "Configure BGP aggregate entries\n"
5428        "Aggregate address\n"
5429        "Aggregate mask\n"
5430        "Generate AS set path information\n")
5431 {
5432   int ret;
5433   char prefix_str[BUFSIZ];
5434 
5435   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5436 
5437   if (! ret)
5438     {
5439       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5440       return CMD_WARNING;
5441     }
5442 
5443   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5444 			    0, AGGREGATE_AS_SET);
5445 }
5446 
5447 
5448 DEFUN (aggregate_address_as_set_summary,
5449        aggregate_address_as_set_summary_cmd,
5450        "aggregate-address A.B.C.D/M as-set summary-only",
5451        "Configure BGP aggregate entries\n"
5452        "Aggregate prefix\n"
5453        "Generate AS set path information\n"
5454        "Filter more specific routes from updates\n")
5455 {
5456   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5457 			    AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5458 }
5459 
5460 ALIAS (aggregate_address_as_set_summary,
5461        aggregate_address_summary_as_set_cmd,
5462        "aggregate-address A.B.C.D/M summary-only as-set",
5463        "Configure BGP aggregate entries\n"
5464        "Aggregate prefix\n"
5465        "Filter more specific routes from updates\n"
5466        "Generate AS set path information\n")
5467 
5468 DEFUN (aggregate_address_mask_as_set_summary,
5469        aggregate_address_mask_as_set_summary_cmd,
5470        "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5471        "Configure BGP aggregate entries\n"
5472        "Aggregate address\n"
5473        "Aggregate mask\n"
5474        "Generate AS set path information\n"
5475        "Filter more specific routes from updates\n")
5476 {
5477   int ret;
5478   char prefix_str[BUFSIZ];
5479 
5480   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5481 
5482   if (! ret)
5483     {
5484       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5485       return CMD_WARNING;
5486     }
5487 
5488   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5489 			    AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5490 }
5491 
5492 ALIAS (aggregate_address_mask_as_set_summary,
5493        aggregate_address_mask_summary_as_set_cmd,
5494        "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5495        "Configure BGP aggregate entries\n"
5496        "Aggregate address\n"
5497        "Aggregate mask\n"
5498        "Filter more specific routes from updates\n"
5499        "Generate AS set path information\n")
5500 
5501 DEFUN (no_aggregate_address,
5502        no_aggregate_address_cmd,
5503        "no aggregate-address A.B.C.D/M",
5504        NO_STR
5505        "Configure BGP aggregate entries\n"
5506        "Aggregate prefix\n")
5507 {
5508   return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5509 }
5510 
5511 ALIAS (no_aggregate_address,
5512        no_aggregate_address_summary_only_cmd,
5513        "no aggregate-address A.B.C.D/M summary-only",
5514        NO_STR
5515        "Configure BGP aggregate entries\n"
5516        "Aggregate prefix\n"
5517        "Filter more specific routes from updates\n")
5518 
5519 ALIAS (no_aggregate_address,
5520        no_aggregate_address_as_set_cmd,
5521        "no aggregate-address A.B.C.D/M as-set",
5522        NO_STR
5523        "Configure BGP aggregate entries\n"
5524        "Aggregate prefix\n"
5525        "Generate AS set path information\n")
5526 
5527 ALIAS (no_aggregate_address,
5528        no_aggregate_address_as_set_summary_cmd,
5529        "no aggregate-address A.B.C.D/M as-set summary-only",
5530        NO_STR
5531        "Configure BGP aggregate entries\n"
5532        "Aggregate prefix\n"
5533        "Generate AS set path information\n"
5534        "Filter more specific routes from updates\n")
5535 
5536 ALIAS (no_aggregate_address,
5537        no_aggregate_address_summary_as_set_cmd,
5538        "no aggregate-address A.B.C.D/M summary-only as-set",
5539        NO_STR
5540        "Configure BGP aggregate entries\n"
5541        "Aggregate prefix\n"
5542        "Filter more specific routes from updates\n"
5543        "Generate AS set path information\n")
5544 
5545 DEFUN (no_aggregate_address_mask,
5546        no_aggregate_address_mask_cmd,
5547        "no aggregate-address A.B.C.D A.B.C.D",
5548        NO_STR
5549        "Configure BGP aggregate entries\n"
5550        "Aggregate address\n"
5551        "Aggregate mask\n")
5552 {
5553   int ret;
5554   char prefix_str[BUFSIZ];
5555 
5556   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5557 
5558   if (! ret)
5559     {
5560       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5561       return CMD_WARNING;
5562     }
5563 
5564   return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5565 }
5566 
5567 ALIAS (no_aggregate_address_mask,
5568        no_aggregate_address_mask_summary_only_cmd,
5569        "no aggregate-address A.B.C.D A.B.C.D summary-only",
5570        NO_STR
5571        "Configure BGP aggregate entries\n"
5572        "Aggregate address\n"
5573        "Aggregate mask\n"
5574        "Filter more specific routes from updates\n")
5575 
5576 ALIAS (no_aggregate_address_mask,
5577        no_aggregate_address_mask_as_set_cmd,
5578        "no aggregate-address A.B.C.D A.B.C.D as-set",
5579        NO_STR
5580        "Configure BGP aggregate entries\n"
5581        "Aggregate address\n"
5582        "Aggregate mask\n"
5583        "Generate AS set path information\n")
5584 
5585 ALIAS (no_aggregate_address_mask,
5586        no_aggregate_address_mask_as_set_summary_cmd,
5587        "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5588        NO_STR
5589        "Configure BGP aggregate entries\n"
5590        "Aggregate address\n"
5591        "Aggregate mask\n"
5592        "Generate AS set path information\n"
5593        "Filter more specific routes from updates\n")
5594 
5595 ALIAS (no_aggregate_address_mask,
5596        no_aggregate_address_mask_summary_as_set_cmd,
5597        "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5598        NO_STR
5599        "Configure BGP aggregate entries\n"
5600        "Aggregate address\n"
5601        "Aggregate mask\n"
5602        "Filter more specific routes from updates\n"
5603        "Generate AS set path information\n")
5604 
5605 DEFUN (ipv6_aggregate_address,
5606        ipv6_aggregate_address_cmd,
5607        "aggregate-address X:X::X:X/M",
5608        "Configure BGP aggregate entries\n"
5609        "Aggregate prefix\n")
5610 {
5611   return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5612 }
5613 
5614 DEFUN (ipv6_aggregate_address_summary_only,
5615        ipv6_aggregate_address_summary_only_cmd,
5616        "aggregate-address X:X::X:X/M summary-only",
5617        "Configure BGP aggregate entries\n"
5618        "Aggregate prefix\n"
5619        "Filter more specific routes from updates\n")
5620 {
5621   return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5622 			    AGGREGATE_SUMMARY_ONLY, 0);
5623 }
5624 
5625 DEFUN (no_ipv6_aggregate_address,
5626        no_ipv6_aggregate_address_cmd,
5627        "no aggregate-address X:X::X:X/M",
5628        NO_STR
5629        "Configure BGP aggregate entries\n"
5630        "Aggregate prefix\n")
5631 {
5632   return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5633 }
5634 
5635 DEFUN (no_ipv6_aggregate_address_summary_only,
5636        no_ipv6_aggregate_address_summary_only_cmd,
5637        "no aggregate-address X:X::X:X/M summary-only",
5638        NO_STR
5639        "Configure BGP aggregate entries\n"
5640        "Aggregate prefix\n"
5641        "Filter more specific routes from updates\n")
5642 {
5643   return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5644 }
5645 
5646 ALIAS (ipv6_aggregate_address,
5647        old_ipv6_aggregate_address_cmd,
5648        "ipv6 bgp aggregate-address X:X::X:X/M",
5649        IPV6_STR
5650        BGP_STR
5651        "Configure BGP aggregate entries\n"
5652        "Aggregate prefix\n")
5653 
5654 ALIAS (ipv6_aggregate_address_summary_only,
5655        old_ipv6_aggregate_address_summary_only_cmd,
5656        "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5657        IPV6_STR
5658        BGP_STR
5659        "Configure BGP aggregate entries\n"
5660        "Aggregate prefix\n"
5661        "Filter more specific routes from updates\n")
5662 
5663 ALIAS (no_ipv6_aggregate_address,
5664        old_no_ipv6_aggregate_address_cmd,
5665        "no ipv6 bgp aggregate-address X:X::X:X/M",
5666        NO_STR
5667        IPV6_STR
5668        BGP_STR
5669        "Configure BGP aggregate entries\n"
5670        "Aggregate prefix\n")
5671 
5672 ALIAS (no_ipv6_aggregate_address_summary_only,
5673        old_no_ipv6_aggregate_address_summary_only_cmd,
5674        "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5675        NO_STR
5676        IPV6_STR
5677        BGP_STR
5678        "Configure BGP aggregate entries\n"
5679        "Aggregate prefix\n"
5680        "Filter more specific routes from updates\n")
5681 
5682 /* Redistribute route treatment. */
5683 void
bgp_redistribute_add(struct prefix * p,const struct in_addr * nexthop,const struct in6_addr * nexthop6,u_int32_t metric,u_char type,route_tag_t tag)5684 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5685 		      const struct in6_addr *nexthop6,
5686 		      u_int32_t metric, u_char type, route_tag_t tag)
5687 {
5688   struct bgp *bgp;
5689   struct listnode *node, *nnode;
5690   struct bgp_info *new;
5691   struct bgp_info *bi;
5692   struct bgp_info info;
5693   struct bgp_node *bn;
5694   struct attr attr;
5695   struct attr *new_attr;
5696   afi_t afi;
5697   int ret;
5698 
5699   /* Make default attribute. */
5700   bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5701   if (nexthop)
5702     attr.nexthop = *nexthop;
5703 
5704   if (nexthop6)
5705     {
5706       struct attr_extra *extra = bgp_attr_extra_get(&attr);
5707       extra->mp_nexthop_global = *nexthop6;
5708       extra->mp_nexthop_len = 16;
5709     }
5710 
5711   attr.med = metric;
5712   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5713   attr.extra->tag = tag;
5714 
5715   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5716     {
5717       afi = family2afi (p->family);
5718 
5719       if (bgp->redist[afi][type])
5720 	{
5721 	  struct attr attr_new;
5722 	  struct attr_extra extra_new;
5723 
5724 	  /* Copy attribute for modification. */
5725 	  attr_new.extra = &extra_new;
5726 	  bgp_attr_dup (&attr_new, &attr);
5727 
5728 	  if (bgp->redist_metric_flag[afi][type])
5729 	    attr_new.med = bgp->redist_metric[afi][type];
5730 
5731 	  /* Apply route-map. */
5732 	  if (bgp->rmap[afi][type].name)
5733 	    {
5734 	      info.peer = bgp->peer_self;
5735 	      info.attr = &attr_new;
5736 
5737               SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5738 
5739 	      ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5740 				     &info);
5741 
5742               bgp->peer_self->rmap_type = 0;
5743 
5744 	      if (ret == RMAP_DENYMATCH)
5745 		{
5746 		  /* Free uninterned attribute. */
5747 		  bgp_attr_flush (&attr_new);
5748 
5749 		  /* Unintern original. */
5750 		  aspath_unintern (&attr.aspath);
5751 		  bgp_attr_extra_free (&attr);
5752 		  bgp_redistribute_delete (p, type);
5753 		  return;
5754 		}
5755 	    }
5756 
5757           bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5758                                  afi, SAFI_UNICAST, p, NULL);
5759 
5760 	  new_attr = bgp_attr_intern (&attr_new);
5761 
5762  	  for (bi = bn->info; bi; bi = bi->next)
5763  	    if (bi->peer == bgp->peer_self
5764  		&& bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5765  	      break;
5766 
5767  	  if (bi)
5768  	    {
5769  	      if (attrhash_cmp (bi->attr, new_attr) &&
5770 		  !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5771  		{
5772  		  bgp_attr_unintern (&new_attr);
5773  		  aspath_unintern (&attr.aspath);
5774  		  bgp_attr_extra_free (&attr);
5775  		  bgp_unlock_node (bn);
5776  		  return;
5777  		}
5778  	      else
5779  		{
5780  		  /* The attribute is changed. */
5781  		  bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5782 
5783  		  /* Rewrite BGP route information. */
5784 		  if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5785 		    bgp_info_restore(bn, bi);
5786 		  else
5787 		    bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5788  		  bgp_attr_unintern (&bi->attr);
5789  		  bi->attr = new_attr;
5790  		  bi->uptime = bgp_clock ();
5791 
5792  		  /* Process change. */
5793  		  bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5794  		  bgp_process (bgp, bn, afi, SAFI_UNICAST);
5795  		  bgp_unlock_node (bn);
5796  		  aspath_unintern (&attr.aspath);
5797  		  bgp_attr_extra_free (&attr);
5798  		  return;
5799 		}
5800  	    }
5801 
5802 	  new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5803 			  new_attr, bn);
5804 	  SET_FLAG (new->flags, BGP_INFO_VALID);
5805 
5806 	  bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5807 	  bgp_info_add (bn, new);
5808 	  bgp_unlock_node (bn);
5809 	  bgp_process (bgp, bn, afi, SAFI_UNICAST);
5810 	}
5811     }
5812 
5813   /* Unintern original. */
5814   aspath_unintern (&attr.aspath);
5815   bgp_attr_extra_free (&attr);
5816 }
5817 
5818 void
bgp_redistribute_delete(struct prefix * p,u_char type)5819 bgp_redistribute_delete (struct prefix *p, u_char type)
5820 {
5821   struct bgp *bgp;
5822   struct listnode *node, *nnode;
5823   afi_t afi;
5824   struct bgp_node *rn;
5825   struct bgp_info *ri;
5826 
5827   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5828     {
5829       afi = family2afi (p->family);
5830 
5831       if (bgp->redist[afi][type])
5832 	{
5833          rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5834 
5835 	  for (ri = rn->info; ri; ri = ri->next)
5836 	    if (ri->peer == bgp->peer_self
5837 		&& ri->type == type)
5838 	      break;
5839 
5840 	  if (ri)
5841 	    {
5842 	      bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5843 	      bgp_info_delete (rn, ri);
5844 	      bgp_process (bgp, rn, afi, SAFI_UNICAST);
5845 	    }
5846 	  bgp_unlock_node (rn);
5847 	}
5848     }
5849 }
5850 
5851 /* Withdraw specified route type's route. */
5852 void
bgp_redistribute_withdraw(struct bgp * bgp,afi_t afi,int type)5853 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5854 {
5855   struct bgp_node *rn;
5856   struct bgp_info *ri;
5857   struct bgp_table *table;
5858 
5859   table = bgp->rib[afi][SAFI_UNICAST];
5860 
5861   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5862     {
5863       for (ri = rn->info; ri; ri = ri->next)
5864 	if (ri->peer == bgp->peer_self
5865 	    && ri->type == type)
5866 	  break;
5867 
5868       if (ri)
5869 	{
5870 	  bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5871 	  bgp_info_delete (rn, ri);
5872 	  bgp_process (bgp, rn, afi, SAFI_UNICAST);
5873 	}
5874     }
5875 }
5876 
5877 /* Static function to display route. */
5878 static void
route_vty_out_route(struct prefix * p,struct vty * vty)5879 route_vty_out_route (struct prefix *p, struct vty *vty)
5880 {
5881   int len;
5882   u_int32_t destination;
5883   char buf[BUFSIZ];
5884 
5885   if (p->family == AF_INET)
5886     {
5887       len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5888       destination = ntohl (p->u.prefix4.s_addr);
5889 
5890       if ((IN_CLASSC (destination) && p->prefixlen == 24)
5891 	  || (IN_CLASSB (destination) && p->prefixlen == 16)
5892 	  || (IN_CLASSA (destination) && p->prefixlen == 8)
5893 	  || p->u.prefix4.s_addr == 0)
5894 	{
5895 	  /* When mask is natural, mask is not displayed. */
5896 	}
5897       else
5898 	len += vty_out (vty, "/%d", p->prefixlen);
5899     }
5900   else
5901     len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5902 		   p->prefixlen);
5903 
5904   len = 17 - len;
5905   if (len < 1)
5906     vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5907   else
5908     vty_out (vty, "%*s", len, " ");
5909 }
5910 
5911 enum bgp_display_type
5912 {
5913   normal_list,
5914 };
5915 
5916 /* Print the short form route status for a bgp_info */
5917 static void
route_vty_short_status_out(struct vty * vty,struct bgp_info * binfo)5918 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5919 {
5920  /* Route status display. */
5921   if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5922     vty_out (vty, "R");
5923   else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5924     vty_out (vty, "S");
5925   else if (binfo->extra && binfo->extra->suppress)
5926     vty_out (vty, "s");
5927   else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5928            ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5929     vty_out (vty, "*");
5930   else
5931     vty_out (vty, " ");
5932 
5933   /* Selected */
5934   if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5935     vty_out (vty, "h");
5936   else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5937     vty_out (vty, "d");
5938   else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5939     vty_out (vty, ">");
5940   else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5941     vty_out (vty, "=");
5942   else
5943     vty_out (vty, " ");
5944 
5945   /* Internal route. */
5946     if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5947       vty_out (vty, "i");
5948     else
5949       vty_out (vty, " ");
5950 }
5951 
5952 /* called from terminal list command */
5953 void
route_vty_out(struct vty * vty,struct prefix * p,struct bgp_info * binfo,int display,safi_t safi)5954 route_vty_out(
5955     struct vty *vty,
5956     struct prefix *p,
5957     struct bgp_info *binfo,
5958     int display,
5959     safi_t safi)
5960 {
5961   struct attr *attr;
5962 
5963   /* short status lead text */
5964   route_vty_short_status_out (vty, binfo);
5965 
5966   /* print prefix and mask */
5967   if (!display)
5968     route_vty_out_route (p, vty);
5969   else
5970     vty_out (vty, "%*s", 17, " ");
5971 
5972   /* Print attribute */
5973   attr = binfo->attr;
5974   if (attr)
5975     {
5976 
5977       /*
5978        * NEXTHOP start
5979        */
5980 
5981       /*
5982        * For ENCAP routes, nexthop address family is not
5983        * neccessarily the same as the prefix address family.
5984        * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5985        */
5986       if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5987 	if (attr->extra) {
5988 	    char	buf[BUFSIZ];
5989 	    int		af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5990 
5991 	    switch (af) {
5992 		case AF_INET:
5993 		    vty_out (vty, "%s", inet_ntop(af,
5994 			&attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5995 		    break;
5996 		case AF_INET6:
5997 		    vty_out (vty, "%s", inet_ntop(af,
5998 			&attr->extra->mp_nexthop_global, buf, BUFSIZ));
5999 		    break;
6000 		default:
6001 		    vty_out(vty, "?");
6002 	    }
6003 	} else {
6004 	    vty_out(vty, "?");
6005 	}
6006       } else {
6007 
6008 	  if (p->family == AF_INET)
6009 	    {
6010 		vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6011 	    }
6012 	  else if (p->family == AF_INET6)
6013 	    {
6014 	      int len;
6015 	      char buf[BUFSIZ];
6016 
6017 	      len = vty_out (vty, "%s",
6018 			     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6019 			     buf, BUFSIZ));
6020 	      len = 16 - len;
6021 	      if (len < 1)
6022 		vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6023 	      else
6024 		vty_out (vty, "%*s", len, " ");
6025 	    }
6026          else
6027 	   {
6028 	     vty_out(vty, "?");
6029 	   }
6030       }
6031 
6032       /*
6033        * NEXTHOP end
6034        */
6035 
6036 
6037       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6038 	vty_out (vty, "%10u", attr->med);
6039       else
6040 	  vty_out (vty, "          ");
6041 
6042       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6043 	vty_out (vty, "%7u", attr->local_pref);
6044       else
6045 	  vty_out (vty, "       ");
6046 
6047       vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6048 
6049       /* Print aspath */
6050       if (attr->aspath)
6051         aspath_print_vty (vty, "%s", attr->aspath, " ");
6052 
6053       /* Print origin */
6054       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6055     }
6056   vty_out (vty, "%s", VTY_NEWLINE);
6057 }
6058 
6059 /* called from terminal list command */
6060 void
route_vty_out_tmp(struct vty * vty,struct prefix * p,struct attr * attr,safi_t safi)6061 route_vty_out_tmp (struct vty *vty, struct prefix *p,
6062 		   struct attr *attr, safi_t safi)
6063 {
6064   /* Route status display. */
6065   vty_out (vty, "*");
6066   vty_out (vty, ">");
6067   vty_out (vty, " ");
6068 
6069   /* print prefix and mask */
6070   route_vty_out_route (p, vty);
6071 
6072   /* Print attribute */
6073   if (attr)
6074     {
6075       if (p->family == AF_INET)
6076 	{
6077 	  if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6078 	    vty_out (vty, "%-16s",
6079                      inet_ntoa (attr->extra->mp_nexthop_global_in));
6080 	  else
6081 	    vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6082 	}
6083       else if (p->family == AF_INET6)
6084         {
6085           int len;
6086           char buf[BUFSIZ];
6087 
6088           assert (attr->extra);
6089 
6090           len = vty_out (vty, "%s",
6091                          inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6092                          buf, BUFSIZ));
6093           len = 16 - len;
6094           if (len < 1)
6095             vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6096           else
6097             vty_out (vty, "%*s", len, " ");
6098         }
6099 
6100       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6101 	vty_out (vty, "%10u ", attr->med);
6102       else
6103 	vty_out (vty, "          ");
6104 
6105       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6106 	vty_out (vty, "%7u ", attr->local_pref);
6107       else
6108 	vty_out (vty, "       ");
6109 
6110       vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6111 
6112       /* Print aspath */
6113       if (attr->aspath)
6114         aspath_print_vty (vty, "%s", attr->aspath, " ");
6115 
6116       /* Print origin */
6117       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6118     }
6119 
6120   vty_out (vty, "%s", VTY_NEWLINE);
6121 }
6122 
6123 void
route_vty_out_tag(struct vty * vty,struct prefix * p,struct bgp_info * binfo,int display,safi_t safi)6124 route_vty_out_tag (struct vty *vty, struct prefix *p,
6125 		   struct bgp_info *binfo, int display, safi_t safi)
6126 {
6127   struct attr *attr;
6128   u_int32_t label = 0;
6129 
6130   if (!binfo->extra)
6131     return;
6132 
6133   /* short status lead text */
6134   route_vty_short_status_out (vty, binfo);
6135 
6136   /* print prefix and mask */
6137   if (! display)
6138     route_vty_out_route (p, vty);
6139   else
6140     vty_out (vty, "%*s", 17, " ");
6141 
6142   /* Print attribute */
6143   attr = binfo->attr;
6144   if (attr)
6145     {
6146       if (p->family == AF_INET)
6147 	{
6148 	  if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6149 	    vty_out (vty, "%-16s",
6150                      inet_ntoa (attr->extra->mp_nexthop_global_in));
6151 	  else
6152 	    vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6153 	}
6154       else if (p->family == AF_INET6)
6155 	{
6156 	  assert (attr->extra);
6157 	  char buf[BUFSIZ];
6158 	  char buf1[BUFSIZ];
6159 	  if (attr->extra->mp_nexthop_len == 16)
6160 	    vty_out (vty, "%s",
6161 		     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6162                      buf, BUFSIZ));
6163 	  else if (attr->extra->mp_nexthop_len == 32)
6164 	    vty_out (vty, "%s(%s)",
6165 		     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6166 		                buf, BUFSIZ),
6167 		     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6168 		                buf1, BUFSIZ));
6169 
6170 	}
6171     }
6172 
6173   label = decode_label (binfo->extra->tag);
6174 
6175   vty_out (vty, "notag/%d", label);
6176 
6177   vty_out (vty, "%s", VTY_NEWLINE);
6178 }
6179 
6180 /* dampening route */
6181 static void
damp_route_vty_out(struct vty * vty,struct prefix * p,struct bgp_info * binfo,int display,safi_t safi)6182 damp_route_vty_out (struct vty *vty, struct prefix *p,
6183 		    struct bgp_info *binfo, int display, safi_t safi)
6184 {
6185   struct attr *attr;
6186   int len;
6187   char timebuf[BGP_UPTIME_LEN];
6188 
6189   /* short status lead text */
6190   route_vty_short_status_out (vty, binfo);
6191 
6192   /* print prefix and mask */
6193   if (! display)
6194     route_vty_out_route (p, vty);
6195   else
6196     vty_out (vty, "%*s", 17, " ");
6197 
6198   len = vty_out (vty, "%s", binfo->peer->host);
6199   len = 17 - len;
6200   if (len < 1)
6201     vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6202   else
6203     vty_out (vty, "%*s", len, " ");
6204 
6205   vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6206 
6207   /* Print attribute */
6208   attr = binfo->attr;
6209   if (attr)
6210     {
6211       /* Print aspath */
6212       if (attr->aspath)
6213 	aspath_print_vty (vty, "%s", attr->aspath, " ");
6214 
6215       /* Print origin */
6216       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6217     }
6218   vty_out (vty, "%s", VTY_NEWLINE);
6219 }
6220 
6221 /* flap route */
6222 static void
flap_route_vty_out(struct vty * vty,struct prefix * p,struct bgp_info * binfo,int display,safi_t safi)6223 flap_route_vty_out (struct vty *vty, struct prefix *p,
6224 		    struct bgp_info *binfo, int display, safi_t safi)
6225 {
6226   struct attr *attr;
6227   struct bgp_damp_info *bdi;
6228   char timebuf[BGP_UPTIME_LEN];
6229   int len;
6230 
6231   if (!binfo->extra)
6232     return;
6233 
6234   bdi = binfo->extra->damp_info;
6235 
6236   /* short status lead text */
6237   route_vty_short_status_out (vty, binfo);
6238 
6239   /* print prefix and mask */
6240   if (! display)
6241     route_vty_out_route (p, vty);
6242   else
6243     vty_out (vty, "%*s", 17, " ");
6244 
6245   len = vty_out (vty, "%s", binfo->peer->host);
6246   len = 16 - len;
6247   if (len < 1)
6248     vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6249   else
6250     vty_out (vty, "%*s", len, " ");
6251 
6252   len = vty_out (vty, "%d", bdi->flap);
6253   len = 5 - len;
6254   if (len < 1)
6255     vty_out (vty, " ");
6256   else
6257     vty_out (vty, "%*s ", len, " ");
6258 
6259   vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6260 	   timebuf, BGP_UPTIME_LEN));
6261 
6262   if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6263       && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6264     vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6265   else
6266     vty_out (vty, "%*s ", 8, " ");
6267 
6268   /* Print attribute */
6269   attr = binfo->attr;
6270   if (attr)
6271     {
6272       /* Print aspath */
6273       if (attr->aspath)
6274 	aspath_print_vty (vty, "%s", attr->aspath, " ");
6275 
6276       /* Print origin */
6277       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6278     }
6279   vty_out (vty, "%s", VTY_NEWLINE);
6280 }
6281 
6282 static void
route_vty_out_detail(struct vty * vty,struct bgp * bgp,struct prefix * p,struct bgp_info * binfo,afi_t afi,safi_t safi)6283 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6284 		      struct bgp_info *binfo, afi_t afi, safi_t safi)
6285 {
6286   char buf[INET6_ADDRSTRLEN];
6287   char buf1[BUFSIZ];
6288   struct attr *attr;
6289   int sockunion_vty_out (struct vty *, union sockunion *);
6290 #ifdef HAVE_CLOCK_MONOTONIC
6291   time_t tbuf;
6292 #endif
6293 
6294   attr = binfo->attr;
6295 
6296   if (attr)
6297     {
6298       /* Line1 display AS-path, Aggregator */
6299       if (attr->aspath)
6300 	{
6301 	  vty_out (vty, "  ");
6302 	  if (aspath_count_hops (attr->aspath) == 0)
6303 	    vty_out (vty, "Local");
6304 	  else
6305 	    aspath_print_vty (vty, "%s", attr->aspath, "");
6306 	}
6307 
6308       if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6309         vty_out (vty, ", (removed)");
6310       if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6311 	vty_out (vty, ", (stale)");
6312       if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6313 	vty_out (vty, ", (aggregated by %u %s)",
6314 	         attr->extra->aggregator_as,
6315 		 inet_ntoa (attr->extra->aggregator_addr));
6316       if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6317 	vty_out (vty, ", (Received from a RR-client)");
6318       if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6319 	vty_out (vty, ", (Received from a RS-client)");
6320       if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6321 	vty_out (vty, ", (history entry)");
6322       else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6323 	vty_out (vty, ", (suppressed due to dampening)");
6324       vty_out (vty, "%s", VTY_NEWLINE);
6325 
6326       /* Line2 display Next-hop, Neighbor, Router-id */
6327       if (p->family == AF_INET)
6328 	{
6329 	  vty_out (vty, "    %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
6330 		   inet_ntoa (attr->extra->mp_nexthop_global_in) :
6331 		   inet_ntoa (attr->nexthop));
6332 	}
6333       else
6334 	{
6335 	  assert (attr->extra);
6336 	  vty_out (vty, "    %s",
6337 		   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6338 			      buf, INET6_ADDRSTRLEN));
6339 	}
6340 
6341       if (binfo->peer == bgp->peer_self)
6342 	{
6343 	  vty_out (vty, " from %s ",
6344 		   p->family == AF_INET ? "0.0.0.0" : "::");
6345 	  vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6346 	}
6347       else
6348 	{
6349 	  if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6350 	    vty_out (vty, " (inaccessible)");
6351 	  else if (binfo->extra && binfo->extra->igpmetric)
6352 	    vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6353 	  if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6354 	    buf[0] = '?';
6355 	    buf[1] = 0;
6356 	  }
6357 	  vty_out (vty, " from %s", buf);
6358 	  if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6359 	    vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6360 	  else
6361 	    vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6362 	}
6363       vty_out (vty, "%s", VTY_NEWLINE);
6364 
6365       /* display nexthop local */
6366       if (attr->extra && attr->extra->mp_nexthop_len == 32)
6367 	{
6368 	  vty_out (vty, "    (%s)%s",
6369 		   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6370 			      buf, INET6_ADDRSTRLEN),
6371 		   VTY_NEWLINE);
6372 	}
6373 
6374       /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6375       vty_out (vty, "      Origin %s", bgp_origin_long_str[attr->origin]);
6376 
6377       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6378 	vty_out (vty, ", metric %u", attr->med);
6379 
6380       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6381 	vty_out (vty, ", localpref %u", attr->local_pref);
6382       else
6383 	vty_out (vty, ", localpref %u", bgp->default_local_pref);
6384 
6385       if (attr->extra && attr->extra->weight != 0)
6386 	vty_out (vty, ", weight %u", attr->extra->weight);
6387 
6388       if (attr->extra && attr->extra->tag != 0)
6389         vty_out (vty, ", tag %d", attr->extra->tag);
6390 
6391       if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6392 	vty_out (vty, ", invalid");
6393       else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6394 	vty_out (vty, ", valid");
6395 
6396       if (binfo->peer != bgp->peer_self)
6397 	{
6398 	  if (binfo->peer->as == binfo->peer->local_as)
6399 	    vty_out (vty, ", internal");
6400 	  else
6401 	    vty_out (vty, ", %s",
6402 		     (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6403 	}
6404       else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6405 	vty_out (vty, ", aggregated, local");
6406       else if (binfo->type != ZEBRA_ROUTE_BGP)
6407 	vty_out (vty, ", sourced");
6408       else
6409 	vty_out (vty, ", sourced, local");
6410 
6411       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6412 	vty_out (vty, ", atomic-aggregate");
6413 
6414       if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6415 	  (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6416 	   bgp_info_mpath_count (binfo)))
6417 	vty_out (vty, ", multipath");
6418 
6419       if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6420 	vty_out (vty, ", best");
6421 
6422       vty_out (vty, "%s", VTY_NEWLINE);
6423 
6424       /* Line 4 display Community */
6425       if (attr->community)
6426 	vty_out (vty, "      Community: %s%s", attr->community->str,
6427 		 VTY_NEWLINE);
6428 
6429       /* Line 5 display Extended-community */
6430       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6431 	vty_out (vty, "      Extended Community: %s%s",
6432 	         attr->extra->ecommunity->str, VTY_NEWLINE);
6433 
6434       /* Line 6 display Large community */
6435       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))
6436 	vty_out (vty, "      Large Community: %s%s",
6437 	         attr->extra->lcommunity->str, VTY_NEWLINE);
6438 
6439       /* Line 7 display Originator, Cluster-id */
6440       if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6441 	  (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6442 	{
6443 	  assert (attr->extra);
6444 	  if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6445 	    vty_out (vty, "      Originator: %s",
6446 	             inet_ntoa (attr->extra->originator_id));
6447 
6448 	  if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6449 	    {
6450 	      int i;
6451 	      vty_out (vty, ", Cluster list: ");
6452 	      for (i = 0; i < attr->extra->cluster->length / 4; i++)
6453 		vty_out (vty, "%s ",
6454 		         inet_ntoa (attr->extra->cluster->list[i]));
6455 	    }
6456 	  vty_out (vty, "%s", VTY_NEWLINE);
6457 	}
6458 
6459       if (binfo->extra && binfo->extra->damp_info)
6460 	bgp_damp_info_vty (vty, binfo);
6461 
6462       /* Line 8 display Uptime */
6463 #ifdef HAVE_CLOCK_MONOTONIC
6464       tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6465       vty_out (vty, "      Last update: %s", ctime(&tbuf));
6466 #else
6467       vty_out (vty, "      Last update: %s", ctime(&binfo->uptime));
6468 #endif /* HAVE_CLOCK_MONOTONIC */
6469     }
6470   vty_out (vty, "%s", VTY_NEWLINE);
6471 }
6472 
6473 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6474 			      "h history, * valid, > best, = multipath,%s"\
6475 		"              i internal, r RIB-failure, S Stale, R Removed%s"
6476 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
6477 #define BGP_SHOW_HEADER "   Network          Next Hop            Metric LocPrf Weight Path%s"
6478 #define BGP_SHOW_DAMP_HEADER "   Network          From             Reuse    Path%s"
6479 #define BGP_SHOW_FLAP_HEADER "   Network          From            Flaps Duration Reuse    Path%s"
6480 
6481 enum bgp_show_type
6482 {
6483   bgp_show_type_normal,
6484   bgp_show_type_regexp,
6485   bgp_show_type_prefix_list,
6486   bgp_show_type_filter_list,
6487   bgp_show_type_route_map,
6488   bgp_show_type_neighbor,
6489   bgp_show_type_cidr_only,
6490   bgp_show_type_prefix_longer,
6491   bgp_show_type_community_all,
6492   bgp_show_type_community,
6493   bgp_show_type_community_exact,
6494   bgp_show_type_community_list,
6495   bgp_show_type_community_list_exact,
6496   bgp_show_type_lcommunity_all,
6497   bgp_show_type_lcommunity,
6498   bgp_show_type_lcommunity_list,
6499   bgp_show_type_flap_statistics,
6500   bgp_show_type_flap_address,
6501   bgp_show_type_flap_prefix,
6502   bgp_show_type_flap_cidr_only,
6503   bgp_show_type_flap_regexp,
6504   bgp_show_type_flap_filter_list,
6505   bgp_show_type_flap_prefix_list,
6506   bgp_show_type_flap_prefix_longer,
6507   bgp_show_type_flap_route_map,
6508   bgp_show_type_flap_neighbor,
6509   bgp_show_type_dampend_paths,
6510   bgp_show_type_damp_neighbor
6511 };
6512 
6513 static int
bgp_show_table(struct vty * vty,struct bgp_table * table,struct in_addr * router_id,enum bgp_show_type type,void * output_arg)6514 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6515 	  enum bgp_show_type type, void *output_arg)
6516 {
6517   struct bgp_info *ri;
6518   struct bgp_node *rn;
6519   int header = 1;
6520   int display;
6521   unsigned long output_count;
6522   unsigned long total_count;
6523 
6524   /* This is first entry point, so reset total line. */
6525   output_count = 0;
6526   total_count  = 0;
6527 
6528   /* Start processing of routes. */
6529   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6530     if (rn->info != NULL)
6531       {
6532 	display = 0;
6533 
6534 	for (ri = rn->info; ri; ri = ri->next)
6535 	  {
6536             total_count++;
6537 	    if (type == bgp_show_type_flap_statistics
6538 		|| type == bgp_show_type_flap_address
6539 		|| type == bgp_show_type_flap_prefix
6540 		|| type == bgp_show_type_flap_cidr_only
6541 		|| type == bgp_show_type_flap_regexp
6542 		|| type == bgp_show_type_flap_filter_list
6543 		|| type == bgp_show_type_flap_prefix_list
6544 		|| type == bgp_show_type_flap_prefix_longer
6545 		|| type == bgp_show_type_flap_route_map
6546 		|| type == bgp_show_type_flap_neighbor
6547 		|| type == bgp_show_type_dampend_paths
6548 		|| type == bgp_show_type_damp_neighbor)
6549 	      {
6550 		if (!(ri->extra && ri->extra->damp_info))
6551 		  continue;
6552 	      }
6553 	    if (type == bgp_show_type_regexp
6554 		|| type == bgp_show_type_flap_regexp)
6555 	      {
6556 		regex_t *regex = output_arg;
6557 
6558 		if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6559 		  continue;
6560 	      }
6561 	    if (type == bgp_show_type_prefix_list
6562 		|| type == bgp_show_type_flap_prefix_list)
6563 	      {
6564 		struct prefix_list *plist = output_arg;
6565 
6566 		if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6567 		  continue;
6568 	      }
6569 	    if (type == bgp_show_type_filter_list
6570 		|| type == bgp_show_type_flap_filter_list)
6571 	      {
6572 		struct as_list *as_list = output_arg;
6573 
6574 		if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6575 		  continue;
6576 	      }
6577 	    if (type == bgp_show_type_route_map
6578 		|| type == bgp_show_type_flap_route_map)
6579 	      {
6580 		struct route_map *rmap = output_arg;
6581 		struct bgp_info binfo;
6582 		struct attr dummy_attr;
6583 		struct attr_extra dummy_extra;
6584 		int ret;
6585 
6586 		dummy_attr.extra = &dummy_extra;
6587 		bgp_attr_dup (&dummy_attr, ri->attr);
6588 
6589 		binfo.peer = ri->peer;
6590 		binfo.attr = &dummy_attr;
6591 
6592 		ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6593 		if (ret == RMAP_DENYMATCH)
6594 		  continue;
6595 	      }
6596 	    if (type == bgp_show_type_neighbor
6597 		|| type == bgp_show_type_flap_neighbor
6598 		|| type == bgp_show_type_damp_neighbor)
6599 	      {
6600 		union sockunion *su = output_arg;
6601 
6602 		if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6603 		  continue;
6604 	      }
6605 	    if (type == bgp_show_type_cidr_only
6606 		|| type == bgp_show_type_flap_cidr_only)
6607 	      {
6608 		u_int32_t destination;
6609 
6610 		destination = ntohl (rn->p.u.prefix4.s_addr);
6611 		if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6612 		  continue;
6613 		if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6614 		  continue;
6615 		if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6616 		  continue;
6617 	      }
6618 	    if (type == bgp_show_type_prefix_longer
6619 		|| type == bgp_show_type_flap_prefix_longer)
6620 	      {
6621 		struct prefix *p = output_arg;
6622 
6623 		if (! prefix_match (p, &rn->p))
6624 		  continue;
6625 	      }
6626 	    if (type == bgp_show_type_community_all)
6627 	      {
6628 		if (! ri->attr->community)
6629 		  continue;
6630 	      }
6631 	    if (type == bgp_show_type_community)
6632 	      {
6633 		struct community *com = output_arg;
6634 
6635 		if (! ri->attr->community ||
6636 		    ! community_match (ri->attr->community, com))
6637 		  continue;
6638 	      }
6639 	    if (type == bgp_show_type_community_exact)
6640 	      {
6641 		struct community *com = output_arg;
6642 
6643 		if (! ri->attr->community ||
6644 		    ! community_cmp (ri->attr->community, com))
6645 		  continue;
6646 	      }
6647 	    if (type == bgp_show_type_community_list)
6648 	      {
6649 		struct community_list *list = output_arg;
6650 
6651 		if (! community_list_match (ri->attr->community, list))
6652 		  continue;
6653 	      }
6654 	    if (type == bgp_show_type_community_list_exact)
6655 	      {
6656 		struct community_list *list = output_arg;
6657 
6658 		if (! community_list_exact_match (ri->attr->community, list))
6659 		  continue;
6660 	      }
6661 	    if (type == bgp_show_type_community_all)
6662 	      {
6663 		if (! ri->attr->community)
6664 		  continue;
6665 	      }
6666 	    if (type == bgp_show_type_lcommunity)
6667 	      {
6668 		struct lcommunity *lcom = output_arg;
6669 
6670 		if (! ri->attr->extra || ! ri->attr->extra->lcommunity ||
6671 		    ! lcommunity_match (ri->attr->extra->lcommunity, lcom))
6672 		  continue;
6673 	      }
6674 	    if (type == bgp_show_type_lcommunity_list)
6675 	      {
6676 		struct community_list *list = output_arg;
6677 
6678 		if (! ri->attr->extra ||
6679 		    ! lcommunity_list_match (ri->attr->extra->lcommunity, list))
6680 		  continue;
6681 	      }
6682 	    if (type == bgp_show_type_lcommunity_all)
6683 	      {
6684 		if (! ri->attr->extra || ! ri->attr->extra->lcommunity)
6685 		  continue;
6686 	      }
6687 	    if (type == bgp_show_type_flap_address
6688 		|| type == bgp_show_type_flap_prefix)
6689 	      {
6690 		struct prefix *p = output_arg;
6691 
6692 		if (! prefix_match (&rn->p, p))
6693 		  continue;
6694 
6695 		if (type == bgp_show_type_flap_prefix)
6696 		  if (p->prefixlen != rn->p.prefixlen)
6697 		    continue;
6698 	      }
6699 	    if (type == bgp_show_type_dampend_paths
6700 		|| type == bgp_show_type_damp_neighbor)
6701 	      {
6702 		if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6703 		    || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6704 		  continue;
6705 	      }
6706 
6707 	    if (header)
6708 	      {
6709 		vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6710 		vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6711 		vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6712 		if (type == bgp_show_type_dampend_paths
6713 		    || type == bgp_show_type_damp_neighbor)
6714 		  vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6715 		else if (type == bgp_show_type_flap_statistics
6716 			 || type == bgp_show_type_flap_address
6717 			 || type == bgp_show_type_flap_prefix
6718 			 || type == bgp_show_type_flap_cidr_only
6719 			 || type == bgp_show_type_flap_regexp
6720 			 || type == bgp_show_type_flap_filter_list
6721 			 || type == bgp_show_type_flap_prefix_list
6722 			 || type == bgp_show_type_flap_prefix_longer
6723 			 || type == bgp_show_type_flap_route_map
6724 			 || type == bgp_show_type_flap_neighbor)
6725 		  vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6726 		else
6727 		  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6728 		header = 0;
6729 	      }
6730 
6731 	    if (type == bgp_show_type_dampend_paths
6732 		|| type == bgp_show_type_damp_neighbor)
6733 	      damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6734 	    else if (type == bgp_show_type_flap_statistics
6735 		     || type == bgp_show_type_flap_address
6736 		     || type == bgp_show_type_flap_prefix
6737 		     || type == bgp_show_type_flap_cidr_only
6738 		     || type == bgp_show_type_flap_regexp
6739 		     || type == bgp_show_type_flap_filter_list
6740 		     || type == bgp_show_type_flap_prefix_list
6741 		     || type == bgp_show_type_flap_prefix_longer
6742 		     || type == bgp_show_type_flap_route_map
6743 		     || type == bgp_show_type_flap_neighbor)
6744 	      flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6745 	    else
6746 	      route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6747 	    display++;
6748 	  }
6749 	if (display)
6750 	  output_count++;
6751       }
6752 
6753   /* No route is displayed */
6754   if (output_count == 0)
6755     {
6756       if (type == bgp_show_type_normal)
6757         vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
6758     }
6759   else
6760     vty_out (vty, "%sDisplayed  %ld out of %ld total prefixes%s",
6761 	     VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
6762 
6763   return CMD_SUCCESS;
6764 }
6765 
6766 static int
bgp_show(struct vty * vty,struct bgp * bgp,afi_t afi,safi_t safi,enum bgp_show_type type,void * output_arg)6767 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6768          enum bgp_show_type type, void *output_arg)
6769 {
6770   struct bgp_table *table;
6771 
6772   if (bgp == NULL) {
6773     bgp = bgp_get_default ();
6774   }
6775 
6776   if (bgp == NULL)
6777     {
6778       vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6779       return CMD_WARNING;
6780     }
6781 
6782 
6783   table = bgp->rib[afi][safi];
6784 
6785   return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
6786 }
6787 
6788 /* Header of detailed BGP route information */
6789 static void
route_vty_out_detail_header(struct vty * vty,struct bgp * bgp,struct bgp_node * rn,struct prefix_rd * prd,afi_t afi,safi_t safi)6790 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6791 			     struct bgp_node *rn,
6792                              struct prefix_rd *prd, afi_t afi, safi_t safi)
6793 {
6794   struct bgp_info *ri;
6795   struct prefix *p;
6796   struct peer *peer;
6797   struct listnode *node, *nnode;
6798   char buf1[INET6_ADDRSTRLEN];
6799   char buf2[INET6_ADDRSTRLEN];
6800   int count = 0;
6801   int best = 0;
6802   int suppress = 0;
6803   int no_export = 0;
6804   int no_advertise = 0;
6805   int local_as = 0;
6806   int first = 0;
6807   int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
6808 
6809   p = &rn->p;
6810   vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6811 	   (printrd ?  prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6812 	   printrd ?  ":" : "",
6813 	   inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6814 	   p->prefixlen, VTY_NEWLINE);
6815 
6816   for (ri = rn->info; ri; ri = ri->next)
6817     {
6818       count++;
6819       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6820 	{
6821 	  best = count;
6822 	  if (ri->extra && ri->extra->suppress)
6823 	    suppress = 1;
6824 	  if (ri->attr->community != NULL)
6825 	    {
6826 	      if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6827 		no_advertise = 1;
6828 	      if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6829 		no_export = 1;
6830 	      if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6831 		local_as = 1;
6832 	    }
6833 	}
6834     }
6835 
6836   vty_out (vty, "Paths: (%d available", count);
6837   if (best)
6838     {
6839       vty_out (vty, ", best #%d", best);
6840       if (safi == SAFI_UNICAST)
6841 	vty_out (vty, ", table Default-IP-Routing-Table");
6842     }
6843   else
6844     vty_out (vty, ", no best path");
6845   if (no_advertise)
6846     vty_out (vty, ", not advertised to any peer");
6847   else if (no_export)
6848     vty_out (vty, ", not advertised to EBGP peer");
6849   else if (local_as)
6850     vty_out (vty, ", not advertised outside local AS");
6851   if (suppress)
6852     vty_out (vty, ", Advertisements suppressed by an aggregate.");
6853   vty_out (vty, ")%s", VTY_NEWLINE);
6854 
6855   /* advertised peer */
6856   for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6857     {
6858       if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6859 	{
6860 	  if (! first)
6861 	    vty_out (vty, "  Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6862 	  vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6863 	  first = 1;
6864 	}
6865     }
6866   if (! first)
6867     vty_out (vty, "  Not advertised to any peer");
6868   vty_out (vty, "%s", VTY_NEWLINE);
6869 }
6870 
6871 /* Display specified route of BGP table. */
6872 static int
bgp_show_route_in_table(struct vty * vty,struct bgp * bgp,struct bgp_table * rib,const char * ip_str,afi_t afi,safi_t safi,struct prefix_rd * prd,int prefix_check,enum bgp_path_type pathtype)6873 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6874                          struct bgp_table *rib, const char *ip_str,
6875                          afi_t afi, safi_t safi, struct prefix_rd *prd,
6876                          int prefix_check, enum bgp_path_type pathtype)
6877 {
6878   int ret;
6879   int header;
6880   int display = 0;
6881   struct prefix match;
6882   struct bgp_node *rn;
6883   struct bgp_node *rm;
6884   struct bgp_info *ri;
6885   struct bgp_table *table;
6886 
6887   memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
6888   /* Check IP address argument. */
6889   ret = str2prefix (ip_str, &match);
6890   if (! ret)
6891     {
6892       vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6893       return CMD_WARNING;
6894     }
6895 
6896   match.family = afi2family (afi);
6897 
6898   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6899     {
6900       for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6901         {
6902           if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6903             continue;
6904 
6905           if ((table = rn->info) != NULL)
6906             {
6907               header = 1;
6908 
6909               if ((rm = bgp_node_match (table, &match)) != NULL)
6910                 {
6911                   if (prefix_check && rm->p.prefixlen != match.prefixlen)
6912                     {
6913                       bgp_unlock_node (rm);
6914                       continue;
6915                     }
6916 
6917                   for (ri = rm->info; ri; ri = ri->next)
6918                     {
6919                       if (header)
6920                         {
6921                           route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6922                                                        AFI_IP, safi);
6923 
6924                           header = 0;
6925                         }
6926                       display++;
6927 
6928                       if (pathtype == BGP_PATH_ALL ||
6929                           (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6930                           (pathtype == BGP_PATH_MULTIPATH &&
6931                            (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6932                         route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
6933                     }
6934 
6935                   bgp_unlock_node (rm);
6936                 }
6937             }
6938         }
6939     }
6940   else
6941     {
6942       header = 1;
6943 
6944       if ((rn = bgp_node_match (rib, &match)) != NULL)
6945         {
6946           if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6947             {
6948               for (ri = rn->info; ri; ri = ri->next)
6949                 {
6950                   if (header)
6951                     {
6952                       route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6953                       header = 0;
6954                     }
6955                   display++;
6956 
6957                   if (pathtype == BGP_PATH_ALL ||
6958                       (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6959                       (pathtype == BGP_PATH_MULTIPATH &&
6960                        (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6961                     route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6962                 }
6963             }
6964 
6965           bgp_unlock_node (rn);
6966         }
6967     }
6968 
6969   if (! display)
6970     {
6971       vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6972       return CMD_WARNING;
6973     }
6974 
6975   return CMD_SUCCESS;
6976 }
6977 
6978 /* Display specified route of Main RIB */
6979 static int
bgp_show_route(struct vty * vty,const char * view_name,const char * ip_str,afi_t afi,safi_t safi,struct prefix_rd * prd,int prefix_check,enum bgp_path_type pathtype)6980 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
6981 		afi_t afi, safi_t safi, struct prefix_rd *prd,
6982 		int prefix_check, enum bgp_path_type pathtype)
6983 {
6984   struct bgp *bgp;
6985 
6986   /* BGP structure lookup. */
6987   if (view_name)
6988     {
6989       bgp = bgp_lookup_by_name (view_name);
6990       if (bgp == NULL)
6991 	{
6992 	  vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6993 	  return CMD_WARNING;
6994 	}
6995     }
6996   else
6997     {
6998       bgp = bgp_get_default ();
6999       if (bgp == NULL)
7000 	{
7001 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7002 	  return CMD_WARNING;
7003 	}
7004     }
7005 
7006   return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7007                                   afi, safi, prd, prefix_check, pathtype);
7008 }
7009 
7010 /* BGP route print out function. */
7011 DEFUN (show_ip_bgp,
7012        show_ip_bgp_cmd,
7013        "show ip bgp",
7014        SHOW_STR
7015        IP_STR
7016        BGP_STR)
7017 {
7018   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7019 }
7020 
7021 DEFUN (show_ip_bgp_ipv4,
7022        show_ip_bgp_ipv4_cmd,
7023        "show ip bgp ipv4 (unicast|multicast)",
7024        SHOW_STR
7025        IP_STR
7026        BGP_STR
7027        "Address family\n"
7028        "Address Family modifier\n"
7029        "Address Family modifier\n")
7030 {
7031   if (strncmp (argv[0], "m", 1) == 0)
7032     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7033                      NULL);
7034 
7035   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7036 }
7037 
7038 DEFUN (show_ip_bgp_route,
7039        show_ip_bgp_route_cmd,
7040        "show ip bgp A.B.C.D",
7041        SHOW_STR
7042        IP_STR
7043        BGP_STR
7044        "Network in the BGP routing table to display\n")
7045 {
7046   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7047 }
7048 
7049 DEFUN (show_ip_bgp_route_pathtype,
7050        show_ip_bgp_route_pathtype_cmd,
7051        "show ip bgp A.B.C.D (bestpath|multipath)",
7052        SHOW_STR
7053        IP_STR
7054        BGP_STR
7055        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7056        "Display only the bestpath\n"
7057        "Display only multipaths\n")
7058 {
7059   if (strncmp (argv[1], "b", 1) == 0)
7060     return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7061   else
7062     return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7063 }
7064 
7065 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7066        show_bgp_ipv4_safi_route_pathtype_cmd,
7067        "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
7068        SHOW_STR
7069        BGP_STR
7070        "Address family\n"
7071        "Address Family modifier\n"
7072        "Address Family modifier\n"
7073        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7074        "Display only the bestpath\n"
7075        "Display only multipaths\n")
7076 {
7077   if (strncmp (argv[0], "m", 1) == 0)
7078     if (strncmp (argv[2], "b", 1) == 0)
7079       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7080     else
7081       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7082   else
7083     if (strncmp (argv[2], "b", 1) == 0)
7084       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7085     else
7086       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7087 }
7088 
7089 DEFUN (show_ip_bgp_ipv4_route,
7090        show_ip_bgp_ipv4_route_cmd,
7091        "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7092        SHOW_STR
7093        IP_STR
7094        BGP_STR
7095        "Address family\n"
7096        "Address Family modifier\n"
7097        "Address Family modifier\n"
7098        "Network in the BGP routing table to display\n")
7099 {
7100   if (strncmp (argv[0], "m", 1) == 0)
7101     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7102 
7103   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7104 }
7105 
7106 DEFUN (show_ip_bgp_vpnv4_all_route,
7107        show_ip_bgp_vpnv4_all_route_cmd,
7108        "show ip bgp vpnv4 all A.B.C.D",
7109        SHOW_STR
7110        IP_STR
7111        BGP_STR
7112        "Display VPNv4 NLRI specific information\n"
7113        "Display information about all VPNv4 NLRIs\n"
7114        "Network in the BGP routing table to display\n")
7115 {
7116   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
7117 }
7118 
7119 
7120 DEFUN (show_ip_bgp_vpnv4_rd_route,
7121        show_ip_bgp_vpnv4_rd_route_cmd,
7122        "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7123        SHOW_STR
7124        IP_STR
7125        BGP_STR
7126        "Display VPNv4 NLRI specific information\n"
7127        "Display information for a route distinguisher\n"
7128        "VPN Route Distinguisher\n"
7129        "Network in the BGP routing table to display\n")
7130 {
7131   int ret;
7132   struct prefix_rd prd;
7133 
7134   ret = str2prefix_rd (argv[0], &prd);
7135   if (! ret)
7136     {
7137       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7138       return CMD_WARNING;
7139     }
7140   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7141 }
7142 
7143 DEFUN (show_ip_bgp_prefix,
7144        show_ip_bgp_prefix_cmd,
7145        "show ip bgp A.B.C.D/M",
7146        SHOW_STR
7147        IP_STR
7148        BGP_STR
7149        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7150 {
7151   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7152 }
7153 
7154 DEFUN (show_ip_bgp_prefix_pathtype,
7155        show_ip_bgp_prefix_pathtype_cmd,
7156        "show ip bgp A.B.C.D/M (bestpath|multipath)",
7157        SHOW_STR
7158        IP_STR
7159        BGP_STR
7160        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7161        "Display only the bestpath\n"
7162        "Display only multipaths\n")
7163 {
7164   if (strncmp (argv[1], "b", 1) == 0)
7165     return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7166   else
7167     return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7168 }
7169 
7170 DEFUN (show_ip_bgp_ipv4_prefix,
7171        show_ip_bgp_ipv4_prefix_cmd,
7172        "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7173        SHOW_STR
7174        IP_STR
7175        BGP_STR
7176        "Address family\n"
7177        "Address Family modifier\n"
7178        "Address Family modifier\n"
7179        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7180 {
7181   if (strncmp (argv[0], "m", 1) == 0)
7182     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7183 
7184   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7185 }
7186 
7187 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7188        show_ip_bgp_ipv4_prefix_pathtype_cmd,
7189        "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7190        SHOW_STR
7191        IP_STR
7192        BGP_STR
7193        "Address family\n"
7194        "Address Family modifier\n"
7195        "Address Family modifier\n"
7196        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7197        "Display only the bestpath\n"
7198        "Display only multipaths\n")
7199 {
7200   if (strncmp (argv[0], "m", 1) == 0)
7201     if (strncmp (argv[2], "b", 1) == 0)
7202       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7203     else
7204       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7205   else
7206     if (strncmp (argv[2], "b", 1) == 0)
7207       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7208     else
7209       return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7210 }
7211 
7212 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7213        show_bgp_ipv4_safi_prefix_pathtype_cmd,
7214        "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7215        SHOW_STR
7216        BGP_STR
7217        "Address family\n"
7218        "Address Family modifier\n"
7219        "Address Family modifier\n"
7220        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7221        "Display only the bestpath\n"
7222        "Display only multipaths\n")
7223 
7224 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7225        show_ip_bgp_vpnv4_all_prefix_cmd,
7226        "show ip bgp vpnv4 all A.B.C.D/M",
7227        SHOW_STR
7228        IP_STR
7229        BGP_STR
7230        "Display VPNv4 NLRI specific information\n"
7231        "Display information about all VPNv4 NLRIs\n"
7232        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7233 {
7234   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
7235 }
7236 
7237 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7238        show_ip_bgp_vpnv4_rd_prefix_cmd,
7239        "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7240        SHOW_STR
7241        IP_STR
7242        BGP_STR
7243        "Display VPNv4 NLRI specific information\n"
7244        "Display information for a route distinguisher\n"
7245        "VPN Route Distinguisher\n"
7246        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7247 {
7248   int ret;
7249   struct prefix_rd prd;
7250 
7251   ret = str2prefix_rd (argv[0], &prd);
7252   if (! ret)
7253     {
7254       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7255       return CMD_WARNING;
7256     }
7257   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
7258 }
7259 
7260 DEFUN (show_ip_bgp_view,
7261        show_ip_bgp_view_cmd,
7262        "show ip bgp view WORD",
7263        SHOW_STR
7264        IP_STR
7265        BGP_STR
7266        "BGP view\n"
7267        "View name\n")
7268 {
7269   struct bgp *bgp;
7270 
7271   /* BGP structure lookup. */
7272   bgp = bgp_lookup_by_name (argv[0]);
7273   if (bgp == NULL)
7274 	{
7275 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7276 	  return CMD_WARNING;
7277 	}
7278 
7279   return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7280 }
7281 
7282 DEFUN (show_ip_bgp_view_route,
7283        show_ip_bgp_view_route_cmd,
7284        "show ip bgp view WORD A.B.C.D",
7285        SHOW_STR
7286        IP_STR
7287        BGP_STR
7288        "BGP view\n"
7289        "View name\n"
7290        "Network in the BGP routing table to display\n")
7291 {
7292   return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7293 }
7294 
7295 DEFUN (show_ip_bgp_view_prefix,
7296        show_ip_bgp_view_prefix_cmd,
7297        "show ip bgp view WORD A.B.C.D/M",
7298        SHOW_STR
7299        IP_STR
7300        BGP_STR
7301        "BGP view\n"
7302        "View name\n"
7303        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7304 {
7305   return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7306 }
7307 
7308 DEFUN (show_bgp,
7309        show_bgp_cmd,
7310        "show bgp",
7311        SHOW_STR
7312        BGP_STR)
7313 {
7314   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7315                    NULL);
7316 }
7317 
7318 ALIAS (show_bgp,
7319        show_bgp_ipv6_cmd,
7320        "show bgp ipv6",
7321        SHOW_STR
7322        BGP_STR
7323        "Address family\n")
7324 
7325 /* old command */
7326 DEFUN (show_ipv6_bgp,
7327        show_ipv6_bgp_cmd,
7328        "show ipv6 bgp",
7329        SHOW_STR
7330        IP_STR
7331        BGP_STR)
7332 {
7333   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7334                    NULL);
7335 }
7336 
7337 DEFUN (show_bgp_route,
7338        show_bgp_route_cmd,
7339        "show bgp X:X::X:X",
7340        SHOW_STR
7341        BGP_STR
7342        "Network in the BGP routing table to display\n")
7343 {
7344   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7345 }
7346 
7347 DEFUN (show_bgp_ipv4_safi,
7348        show_bgp_ipv4_safi_cmd,
7349        "show bgp ipv4 (unicast|multicast)",
7350        SHOW_STR
7351        BGP_STR
7352        "Address family\n"
7353        "Address Family modifier\n"
7354        "Address Family modifier\n")
7355 {
7356   if (strncmp (argv[0], "m", 1) == 0)
7357     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7358                      NULL);
7359 
7360   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7361 }
7362 
7363 DEFUN (show_bgp_ipv4_safi_route,
7364        show_bgp_ipv4_safi_route_cmd,
7365        "show bgp ipv4 (unicast|multicast) A.B.C.D",
7366        SHOW_STR
7367        BGP_STR
7368        "Address family\n"
7369        "Address Family modifier\n"
7370        "Address Family modifier\n"
7371        "Network in the BGP routing table to display\n")
7372 {
7373   if (strncmp (argv[0], "m", 1) == 0)
7374     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7375 
7376   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7377 }
7378 
7379 DEFUN (show_bgp_route_pathtype,
7380        show_bgp_route_pathtype_cmd,
7381        "show bgp X:X::X:X (bestpath|multipath)",
7382        SHOW_STR
7383        BGP_STR
7384        "Network in the BGP routing table to display\n"
7385        "Display only the bestpath\n"
7386        "Display only multipaths\n")
7387 {
7388   if (strncmp (argv[1], "b", 1) == 0)
7389     return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7390   else
7391     return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7392 }
7393 
7394 ALIAS (show_bgp_route_pathtype,
7395        show_bgp_ipv6_route_pathtype_cmd,
7396        "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7397        SHOW_STR
7398        BGP_STR
7399        "Address family\n"
7400        "Network in the BGP routing table to display\n"
7401        "Display only the bestpath\n"
7402        "Display only multipaths\n")
7403 
7404 DEFUN (show_bgp_ipv6_safi_route_pathtype,
7405        show_bgp_ipv6_safi_route_pathtype_cmd,
7406        "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7407        SHOW_STR
7408        BGP_STR
7409        "Address family\n"
7410        "Address Family modifier\n"
7411        "Address Family modifier\n"
7412        "Network in the BGP routing table to display\n"
7413        "Display only the bestpath\n"
7414        "Display only multipaths\n")
7415 {
7416   if (strncmp (argv[0], "m", 1) == 0)
7417     if (strncmp (argv[2], "b", 1) == 0)
7418       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7419     else
7420       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7421   else
7422     if (strncmp (argv[2], "b", 1) == 0)
7423       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7424     else
7425       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7426 }
7427 
7428 DEFUN (show_bgp_ipv4_vpn_route,
7429        show_bgp_ipv4_vpn_route_cmd,
7430        "show bgp ipv4 vpn A.B.C.D",
7431        SHOW_STR
7432        BGP_STR
7433        "Address Family\n"
7434        "Display VPN NLRI specific information\n"
7435        "Network in the BGP routing table to display\n")
7436 {
7437   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
7438 }
7439 
7440 DEFUN (show_bgp_ipv6_vpn_route,
7441        show_bgp_ipv6_vpn_route_cmd,
7442        "show bgp ipv6 vpn X:X::X:X",
7443        SHOW_STR
7444        BGP_STR
7445        "Address Family\n"
7446        "Display VPN NLRI specific information\n"
7447        "Network in the BGP routing table to display\n")
7448 {
7449   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
7450 }
7451 
7452 DEFUN (show_bgp_ipv4_vpn_rd_route,
7453        show_bgp_ipv4_vpn_rd_route_cmd,
7454        "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7455        SHOW_STR
7456        BGP_STR
7457        IP_STR
7458        "Display VPN NLRI specific information\n"
7459        "Display information for a route distinguisher\n"
7460        "VPN Route Distinguisher\n"
7461        "Network in the BGP routing table to display\n")
7462 {
7463   int ret;
7464   struct prefix_rd prd;
7465 
7466   ret = str2prefix_rd (argv[0], &prd);
7467   if (! ret)
7468     {
7469       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7470       return CMD_WARNING;
7471     }
7472   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7473 }
7474 
7475 DEFUN (show_bgp_ipv6_vpn_rd_route,
7476        show_bgp_ipv6_vpn_rd_route_cmd,
7477        "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
7478        SHOW_STR
7479        BGP_STR
7480        "Address Family\n"
7481        "Display VPN NLRI specific information\n"
7482        "Display information for a route distinguisher\n"
7483        "VPN Route Distinguisher\n"
7484        "Network in the BGP routing table to display\n")
7485 {
7486   int ret;
7487   struct prefix_rd prd;
7488 
7489   ret = str2prefix_rd (argv[0], &prd);
7490   if (! ret)
7491     {
7492       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7493       return CMD_WARNING;
7494     }
7495   return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7496 }
7497 
7498 DEFUN (show_bgp_prefix_pathtype,
7499        show_bgp_prefix_pathtype_cmd,
7500        "show bgp X:X::X:X/M (bestpath|multipath)",
7501        SHOW_STR
7502        BGP_STR
7503        "IPv6 prefix <network>/<length>\n"
7504        "Display only the bestpath\n"
7505        "Display only multipaths\n")
7506 {
7507   if (strncmp (argv[1], "b", 1) == 0)
7508     return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7509   else
7510     return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7511 }
7512 
7513 ALIAS (show_bgp_prefix_pathtype,
7514        show_bgp_ipv6_prefix_pathtype_cmd,
7515        "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7516        SHOW_STR
7517        BGP_STR
7518        "Address family\n"
7519        "IPv6 prefix <network>/<length>\n"
7520        "Display only the bestpath\n"
7521        "Display only multipaths\n")
7522 
7523 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7524        show_bgp_ipv6_safi_prefix_pathtype_cmd,
7525        "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7526        SHOW_STR
7527        BGP_STR
7528        "Address family\n"
7529        "Address Family modifier\n"
7530        "Address Family modifier\n"
7531        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7532        "Display only the bestpath\n"
7533        "Display only multipaths\n")
7534 {
7535   if (strncmp (argv[0], "m", 1) == 0)
7536     if (strncmp (argv[2], "b", 1) == 0)
7537       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7538     else
7539       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7540   else
7541     if (strncmp (argv[2], "b", 1) == 0)
7542       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7543     else
7544       return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7545 }
7546 
7547 DEFUN (show_bgp_ipv4_encap_route,
7548        show_bgp_ipv4_encap_route_cmd,
7549        "show bgp ipv4 encap A.B.C.D",
7550        SHOW_STR
7551        BGP_STR
7552        IP_STR
7553        "Display ENCAP NLRI specific information\n"
7554        "Network in the BGP routing table to display\n")
7555 {
7556   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
7557 }
7558 
7559 DEFUN (show_bgp_ipv6_encap_route,
7560        show_bgp_ipv6_encap_route_cmd,
7561        "show bgp ipv6 encap X:X::X:X",
7562        SHOW_STR
7563        BGP_STR
7564        IP6_STR
7565        "Display ENCAP NLRI specific information\n"
7566        "Network in the BGP routing table to display\n")
7567 {
7568   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
7569 }
7570 
7571 DEFUN (show_bgp_ipv4_safi_rd_route,
7572        show_bgp_ipv4_safi_rd_route_cmd,
7573        "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
7574        SHOW_STR
7575        BGP_STR
7576        "Address Family\n"
7577        "Address Family Modifier\n"
7578        "Address Family Modifier\n"
7579        "Display information for a route distinguisher\n"
7580        "ENCAP Route Distinguisher\n"
7581        "Network in the BGP routing table to display\n")
7582 {
7583   int ret;
7584   struct prefix_rd prd;
7585   safi_t	safi;
7586 
7587   if (bgp_parse_safi(argv[0], &safi)) {
7588     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7589     return CMD_WARNING;
7590   }
7591   ret = str2prefix_rd (argv[1], &prd);
7592   if (! ret)
7593     {
7594       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7595       return CMD_WARNING;
7596     }
7597   return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
7598 }
7599 
7600 DEFUN (show_bgp_ipv6_safi_rd_route,
7601        show_bgp_ipv6_safi_rd_route_cmd,
7602        "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
7603        SHOW_STR
7604        BGP_STR
7605        "Address Family\n"
7606        "Address Family Modifier\n"
7607        "Address Family Modifier\n"
7608        "Display information for a route distinguisher\n"
7609        "ENCAP Route Distinguisher\n"
7610        "Network in the BGP routing table to display\n")
7611 {
7612   int ret;
7613   struct prefix_rd prd;
7614   safi_t	safi;
7615 
7616   if (bgp_parse_safi(argv[0], &safi)) {
7617     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7618     return CMD_WARNING;
7619   }
7620   ret = str2prefix_rd (argv[1], &prd);
7621   if (! ret)
7622     {
7623       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7624       return CMD_WARNING;
7625     }
7626   return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
7627 }
7628 
7629 DEFUN (show_bgp_ipv4_prefix,
7630        show_bgp_ipv4_prefix_cmd,
7631        "show bgp ipv4 A.B.C.D/M",
7632        SHOW_STR
7633        BGP_STR
7634        IP_STR
7635        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7636 {
7637   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7638 }
7639 
7640 DEFUN (show_bgp_ipv4_safi_prefix,
7641        show_bgp_ipv4_safi_prefix_cmd,
7642        "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7643        SHOW_STR
7644        BGP_STR
7645        "Address family\n"
7646        "Address Family modifier\n"
7647        "Address Family modifier\n"
7648        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7649 {
7650   if (strncmp (argv[0], "m", 1) == 0)
7651     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7652 
7653   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7654 }
7655 
7656 DEFUN (show_bgp_ipv4_vpn_prefix,
7657        show_bgp_ipv4_vpn_prefix_cmd,
7658        "show bgp ipv4 vpn A.B.C.D/M",
7659        SHOW_STR
7660        BGP_STR
7661        IP_STR
7662        "Display VPN NLRI specific information\n"
7663        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7664 {
7665   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
7666 }
7667 
7668 DEFUN (show_bgp_ipv6_vpn_prefix,
7669        show_bgp_ipv6_vpn_prefix_cmd,
7670        "show bgp ipv6 vpn X:X::X:X/M",
7671        SHOW_STR
7672        BGP_STR
7673        "Address Family\n"
7674        "Display VPN NLRI specific information\n"
7675        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7676 {
7677   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
7678 }
7679 
7680 DEFUN (show_bgp_ipv4_encap_prefix,
7681        show_bgp_ipv4_encap_prefix_cmd,
7682        "show bgp ipv4 encap A.B.C.D/M",
7683        SHOW_STR
7684        BGP_STR
7685        IP_STR
7686        "Display ENCAP NLRI specific information\n"
7687        "Display information about ENCAP NLRIs\n"
7688        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7689 {
7690   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
7691 }
7692 
7693 DEFUN (show_bgp_ipv6_encap_prefix,
7694        show_bgp_ipv6_encap_prefix_cmd,
7695        "show bgp ipv6 encap X:X::X:X/M",
7696        SHOW_STR
7697        BGP_STR
7698        IP_STR
7699        "Display ENCAP NLRI specific information\n"
7700        "Display information about ENCAP NLRIs\n"
7701        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7702 {
7703   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
7704 }
7705 
7706 DEFUN (show_bgp_ipv4_safi_rd_prefix,
7707        show_bgp_ipv4_safi_rd_prefix_cmd,
7708        "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7709        SHOW_STR
7710        BGP_STR
7711        "Address Family\n"
7712        "Address Family Modifier\n"
7713        "Address Family Modifier\n"
7714        "Display information for a route distinguisher\n"
7715        "ENCAP Route Distinguisher\n"
7716        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7717 {
7718   int ret;
7719   struct prefix_rd prd;
7720   safi_t	safi;
7721 
7722   if (bgp_parse_safi(argv[0], &safi)) {
7723     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7724     return CMD_WARNING;
7725   }
7726 
7727   ret = str2prefix_rd (argv[1], &prd);
7728   if (! ret)
7729     {
7730       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7731       return CMD_WARNING;
7732     }
7733   return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
7734 }
7735 
7736 DEFUN (show_bgp_ipv6_safi_rd_prefix,
7737        show_bgp_ipv6_safi_rd_prefix_cmd,
7738        "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7739        SHOW_STR
7740        BGP_STR
7741        "Address Family\n"
7742        "Address Family Modifier\n"
7743        "Address Family Modifier\n"
7744        "Display information for a route distinguisher\n"
7745        "ENCAP Route Distinguisher\n"
7746        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7747 {
7748   int ret;
7749   struct prefix_rd prd;
7750   safi_t	safi;
7751 
7752   if (bgp_parse_safi(argv[0], &safi)) {
7753     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7754     return CMD_WARNING;
7755   }
7756 
7757   ret = str2prefix_rd (argv[1], &prd);
7758   if (! ret)
7759     {
7760       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7761       return CMD_WARNING;
7762     }
7763   return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
7764 }
7765 
7766 DEFUN (show_bgp_afi_safi_view,
7767        show_bgp_afi_safi_view_cmd,
7768        "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7769        SHOW_STR
7770        BGP_STR
7771        "BGP view\n"
7772        "BGP view name\n"
7773        "Address Family\n"
7774        "Address Family\n"
7775        "Address Family Modifier\n"
7776        "Address Family Modifier\n"
7777        "Address Family Modifier\n"
7778        "Address Family Modifier\n"
7779        )
7780 {
7781   struct bgp *bgp;
7782   safi_t	safi;
7783   afi_t		afi;
7784 
7785   if (bgp_parse_afi(argv[1], &afi)) {
7786     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7787     return CMD_WARNING;
7788   }
7789   if (bgp_parse_safi(argv[2], &safi)) {
7790     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7791     return CMD_WARNING;
7792   }
7793 
7794   /* BGP structure lookup. */
7795   bgp = bgp_lookup_by_name (argv[0]);
7796   if (bgp == NULL)
7797 	{
7798 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7799 	  return CMD_WARNING;
7800 	}
7801 
7802   return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7803 }
7804 
7805 DEFUN (show_bgp_view_afi_safi_route,
7806        show_bgp_view_afi_safi_route_cmd,
7807        "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7808        SHOW_STR
7809        BGP_STR
7810        "BGP view\n"
7811        "View name\n"
7812        "Address Family\n"
7813        "Address Family\n"
7814        "Address Family Modifier\n"
7815        "Address Family Modifier\n"
7816        "Address Family Modifier\n"
7817        "Address Family Modifier\n"
7818        "Network in the BGP routing table to display\n")
7819 {
7820   safi_t	safi;
7821   afi_t		afi;
7822 
7823   if (bgp_parse_afi(argv[1], &afi)) {
7824     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7825     return CMD_WARNING;
7826   }
7827   if (bgp_parse_safi(argv[2], &safi)) {
7828     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7829     return CMD_WARNING;
7830   }
7831   return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
7832 }
7833 
7834 DEFUN (show_bgp_view_afi_safi_prefix,
7835        show_bgp_view_afi_safi_prefix_cmd,
7836        "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7837        SHOW_STR
7838        BGP_STR
7839        "BGP view\n"
7840        "View name\n"
7841        "Address Family\n"
7842        "Address Family\n"
7843        "Address Family Modifier\n"
7844        "Address Family Modifier\n"
7845        "Address Family Modifier\n"
7846        "Address Family Modifier\n"
7847        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7848 {
7849   safi_t	safi;
7850   afi_t		afi;
7851 
7852   if (bgp_parse_afi(argv[1], &afi)) {
7853     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7854     return CMD_WARNING;
7855   }
7856   if (bgp_parse_safi(argv[2], &safi)) {
7857     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7858     return CMD_WARNING;
7859   }
7860   return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
7861 }
7862 
7863 /* new001 */
7864 DEFUN (show_bgp_afi,
7865        show_bgp_afi_cmd,
7866        "show bgp (ipv4|ipv6)",
7867        SHOW_STR
7868        BGP_STR
7869        "Address family\n"
7870        "Address family\n")
7871 {
7872   afi_t	afi;
7873 
7874   if (bgp_parse_afi(argv[0], &afi)) {
7875     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7876     return CMD_WARNING;
7877   }
7878   return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7879                    NULL);
7880 }
7881 
7882 DEFUN (show_bgp_ipv6_safi,
7883        show_bgp_ipv6_safi_cmd,
7884        "show bgp ipv6 (unicast|multicast)",
7885        SHOW_STR
7886        BGP_STR
7887        "Address family\n"
7888        "Address Family modifier\n"
7889        "Address Family modifier\n")
7890 {
7891   if (strncmp (argv[0], "m", 1) == 0)
7892     return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7893                      NULL);
7894 
7895   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7896 }
7897 
7898 DEFUN (show_bgp_ipv6_route,
7899        show_bgp_ipv6_route_cmd,
7900        "show bgp ipv6 X:X::X:X",
7901        SHOW_STR
7902        BGP_STR
7903        "Address family\n"
7904        "Network in the BGP routing table to display\n")
7905 {
7906   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7907 }
7908 
7909 DEFUN (show_bgp_ipv6_safi_route,
7910        show_bgp_ipv6_safi_route_cmd,
7911        "show bgp ipv6 (unicast|multicast) X:X::X:X",
7912        SHOW_STR
7913        BGP_STR
7914        "Address family\n"
7915        "Address Family modifier\n"
7916        "Address Family modifier\n"
7917        "Network in the BGP routing table to display\n")
7918 {
7919   if (strncmp (argv[0], "m", 1) == 0)
7920     return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7921 
7922   return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7923 }
7924 
7925 /* old command */
7926 DEFUN (show_ipv6_bgp_route,
7927        show_ipv6_bgp_route_cmd,
7928        "show ipv6 bgp X:X::X:X",
7929        SHOW_STR
7930        IP_STR
7931        BGP_STR
7932        "Network in the BGP routing table to display\n")
7933 {
7934   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7935 }
7936 
7937 DEFUN (show_bgp_prefix,
7938        show_bgp_prefix_cmd,
7939        "show bgp X:X::X:X/M",
7940        SHOW_STR
7941        BGP_STR
7942        "IPv6 prefix <network>/<length>\n")
7943 {
7944   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7945 }
7946 
7947 
7948 /* new002 */
7949 DEFUN (show_bgp_ipv6_prefix,
7950        show_bgp_ipv6_prefix_cmd,
7951        "show bgp ipv6 X:X::X:X/M",
7952        SHOW_STR
7953        BGP_STR
7954        "Address family\n"
7955        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7956 {
7957   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7958 }
7959 DEFUN (show_bgp_ipv6_safi_prefix,
7960        show_bgp_ipv6_safi_prefix_cmd,
7961        "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7962        SHOW_STR
7963        BGP_STR
7964        "Address family\n"
7965        "Address Family modifier\n"
7966        "Address Family modifier\n"
7967        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7968 {
7969   if (strncmp (argv[0], "m", 1) == 0)
7970     return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7971 
7972   return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7973 }
7974 
7975 /* old command */
7976 DEFUN (show_ipv6_bgp_prefix,
7977        show_ipv6_bgp_prefix_cmd,
7978        "show ipv6 bgp X:X::X:X/M",
7979        SHOW_STR
7980        IP_STR
7981        BGP_STR
7982        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7983 {
7984   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7985 }
7986 
7987 DEFUN (show_bgp_view,
7988        show_bgp_view_cmd,
7989        "show bgp view WORD",
7990        SHOW_STR
7991        BGP_STR
7992        "BGP view\n"
7993        "View name\n")
7994 {
7995   struct bgp *bgp;
7996 
7997   /* BGP structure lookup. */
7998   bgp = bgp_lookup_by_name (argv[0]);
7999   if (bgp == NULL)
8000 	{
8001 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8002 	  return CMD_WARNING;
8003 	}
8004 
8005   return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
8006 }
8007 
8008 DEFUN (show_bgp_view_ipv6,
8009        show_bgp_view_ipv6_cmd,
8010        "show bgp view WORD ipv6",
8011        SHOW_STR
8012        BGP_STR
8013        "BGP view\n"
8014        "View name\n"
8015        "Address family\n")
8016 {
8017   struct bgp *bgp;
8018 
8019   /* BGP structure lookup. */
8020   bgp = bgp_lookup_by_name (argv[0]);
8021   if (bgp == NULL)
8022 	{
8023 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8024 	  return CMD_WARNING;
8025 	}
8026 
8027   return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
8028 }
8029 
8030 DEFUN (show_bgp_view_route,
8031        show_bgp_view_route_cmd,
8032        "show bgp view WORD X:X::X:X",
8033        SHOW_STR
8034        BGP_STR
8035        "BGP view\n"
8036        "View name\n"
8037        "Network in the BGP routing table to display\n")
8038 {
8039   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
8040 }
8041 
8042 DEFUN (show_bgp_view_ipv6_route,
8043        show_bgp_view_ipv6_route_cmd,
8044        "show bgp view WORD ipv6 X:X::X:X",
8045        SHOW_STR
8046        BGP_STR
8047        "BGP view\n"
8048        "View name\n"
8049        "Address family\n"
8050        "Network in the BGP routing table to display\n")
8051 {
8052   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
8053 }
8054 
8055 /* old command */
8056 DEFUN (show_ipv6_mbgp,
8057        show_ipv6_mbgp_cmd,
8058        "show ipv6 mbgp",
8059        SHOW_STR
8060        IP_STR
8061        MBGP_STR)
8062 {
8063   return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8064                    NULL);
8065 }
8066 
8067 /* old command */
8068 DEFUN (show_ipv6_mbgp_route,
8069        show_ipv6_mbgp_route_cmd,
8070        "show ipv6 mbgp X:X::X:X",
8071        SHOW_STR
8072        IP_STR
8073        MBGP_STR
8074        "Network in the MBGP routing table to display\n")
8075 {
8076   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
8077 }
8078 
8079 /* old command */
8080 DEFUN (show_ipv6_mbgp_prefix,
8081        show_ipv6_mbgp_prefix_cmd,
8082        "show ipv6 mbgp X:X::X:X/M",
8083        SHOW_STR
8084        IP_STR
8085        MBGP_STR
8086        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
8087 {
8088   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
8089 }
8090 
8091 DEFUN (show_bgp_view_prefix,
8092        show_bgp_view_prefix_cmd,
8093        "show bgp view WORD X:X::X:X/M",
8094        SHOW_STR
8095        BGP_STR
8096        "BGP view\n"
8097        "View name\n"
8098        "IPv6 prefix <network>/<length>\n")
8099 {
8100   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
8101 }
8102 
8103 DEFUN (show_bgp_view_ipv6_prefix,
8104        show_bgp_view_ipv6_prefix_cmd,
8105        "show bgp view WORD ipv6 X:X::X:X/M",
8106        SHOW_STR
8107        BGP_STR
8108        "BGP view\n"
8109        "View name\n"
8110        "Address family\n"
8111        "IPv6 prefix <network>/<length>\n")
8112 {
8113   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
8114 }
8115 
8116 static int
bgp_show_regexp(struct vty * vty,int argc,const char ** argv,afi_t afi,safi_t safi,enum bgp_show_type type)8117 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8118 		 safi_t safi, enum bgp_show_type type)
8119 {
8120   int i;
8121   struct buffer *b;
8122   char *regstr;
8123   int first;
8124   regex_t *regex;
8125   int rc;
8126 
8127   first = 0;
8128   b = buffer_new (1024);
8129   for (i = 0; i < argc; i++)
8130     {
8131       if (first)
8132 	buffer_putc (b, ' ');
8133       else
8134 	{
8135 	  if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8136 	    continue;
8137 	  first = 1;
8138 	}
8139 
8140       buffer_putstr (b, argv[i]);
8141     }
8142   buffer_putc (b, '\0');
8143 
8144   regstr = buffer_getstr (b);
8145   buffer_free (b);
8146 
8147   regex = bgp_regcomp (regstr);
8148   XFREE(MTYPE_TMP, regstr);
8149   if (! regex)
8150     {
8151       vty_out (vty, "Can't compile regexp %s%s", argv[0],
8152 	       VTY_NEWLINE);
8153       return CMD_WARNING;
8154     }
8155 
8156   rc = bgp_show (vty, NULL, afi, safi, type, regex);
8157   bgp_regex_free (regex);
8158   return rc;
8159 }
8160 
8161 
8162 DEFUN (show_ip_bgp_regexp,
8163        show_ip_bgp_regexp_cmd,
8164        "show ip bgp regexp .LINE",
8165        SHOW_STR
8166        IP_STR
8167        BGP_STR
8168        "Display routes matching the AS path regular expression\n"
8169        "A regular-expression to match the BGP AS paths\n")
8170 {
8171   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8172 			  bgp_show_type_regexp);
8173 }
8174 
8175 DEFUN (show_ip_bgp_flap_regexp,
8176        show_ip_bgp_flap_regexp_cmd,
8177        "show ip bgp flap-statistics regexp .LINE",
8178        SHOW_STR
8179        IP_STR
8180        BGP_STR
8181        "Display flap statistics of routes\n"
8182        "Display routes matching the AS path regular expression\n"
8183        "A regular-expression to match the BGP AS paths\n")
8184 {
8185   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8186 			  bgp_show_type_flap_regexp);
8187 }
8188 
8189 ALIAS (show_ip_bgp_flap_regexp,
8190        show_ip_bgp_damp_flap_regexp_cmd,
8191        "show ip bgp dampening flap-statistics regexp .LINE",
8192        SHOW_STR
8193        IP_STR
8194        BGP_STR
8195        "Display detailed information about dampening\n"
8196        "Display flap statistics of routes\n"
8197        "Display routes matching the AS path regular expression\n"
8198        "A regular-expression to match the BGP AS paths\n")
8199 
8200 DEFUN (show_ip_bgp_ipv4_regexp,
8201        show_ip_bgp_ipv4_regexp_cmd,
8202        "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8203        SHOW_STR
8204        IP_STR
8205        BGP_STR
8206        "Address family\n"
8207        "Address Family modifier\n"
8208        "Address Family modifier\n"
8209        "Display routes matching the AS path regular expression\n"
8210        "A regular-expression to match the BGP AS paths\n")
8211 {
8212   if (strncmp (argv[0], "m", 1) == 0)
8213     return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8214 			    bgp_show_type_regexp);
8215 
8216   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8217 			  bgp_show_type_regexp);
8218 }
8219 
8220 DEFUN (show_bgp_regexp,
8221        show_bgp_regexp_cmd,
8222        "show bgp regexp .LINE",
8223        SHOW_STR
8224        BGP_STR
8225        "Display routes matching the AS path regular expression\n"
8226        "A regular-expression to match the BGP AS paths\n")
8227 {
8228   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8229 			  bgp_show_type_regexp);
8230 }
8231 
8232 /* old command */
8233 DEFUN (show_ipv6_bgp_regexp,
8234        show_ipv6_bgp_regexp_cmd,
8235        "show ipv6 bgp regexp .LINE",
8236        SHOW_STR
8237        IP_STR
8238        BGP_STR
8239        "Display routes matching the AS path regular expression\n"
8240        "A regular-expression to match the BGP AS paths\n")
8241 {
8242   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8243 			  bgp_show_type_regexp);
8244 }
8245 
8246 /* old command */
8247 DEFUN (show_ipv6_mbgp_regexp,
8248        show_ipv6_mbgp_regexp_cmd,
8249        "show ipv6 mbgp regexp .LINE",
8250        SHOW_STR
8251        IP_STR
8252        BGP_STR
8253        "Display routes matching the AS path regular expression\n"
8254        "A regular-expression to match the MBGP AS paths\n")
8255 {
8256   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8257 			  bgp_show_type_regexp);
8258 }
8259 
8260 DEFUN (show_bgp_ipv4_safi_flap_regexp,
8261        show_bgp_ipv4_safi_flap_regexp_cmd,
8262        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
8263        SHOW_STR
8264        BGP_STR
8265        IP_STR
8266        "Address Family Modifier\n"
8267        "Address Family Modifier\n"
8268        "Address Family Modifier\n"
8269        "Address Family Modifier\n"
8270        "Display flap statistics of routes\n"
8271        "Display routes matching the AS path regular expression\n"
8272        "A regular-expression to match the BGP AS paths\n")
8273 {
8274   safi_t	safi;
8275 
8276   if (bgp_parse_safi(argv[0], &safi)) {
8277     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8278     return CMD_WARNING;
8279   }
8280     return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8281 	bgp_show_type_flap_regexp);
8282 }
8283 
8284 ALIAS (show_bgp_ipv4_safi_flap_regexp,
8285        show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8286        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8287        SHOW_STR
8288        BGP_STR
8289        IP_STR
8290        "Address Family Modifier\n"
8291        "Address Family Modifier\n"
8292        "Address Family Modifier\n"
8293        "Address Family Modifier\n"
8294        "Display detailed information about dampening\n"
8295        "Display flap statistics of routes\n"
8296        "Display routes matching the AS path regular expression\n"
8297        "A regular-expression to match the BGP AS paths\n")
8298 
8299 DEFUN (show_bgp_ipv6_safi_flap_regexp,
8300        show_bgp_ipv6_safi_flap_regexp_cmd,
8301        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
8302        SHOW_STR
8303        BGP_STR
8304        IPV6_STR
8305        "Address Family Modifier\n"
8306        "Address Family Modifier\n"
8307        "Address Family Modifier\n"
8308        "Address Family Modifier\n"
8309        "Display flap statistics of routes\n"
8310        "Display routes matching the AS path regular expression\n"
8311        "A regular-expression to match the BGP AS paths\n")
8312 {
8313   safi_t	safi;
8314 
8315   if (bgp_parse_safi(argv[0], &safi)) {
8316     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8317     return CMD_WARNING;
8318   }
8319     return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8320 	bgp_show_type_flap_regexp);
8321 }
8322 
8323 ALIAS (show_bgp_ipv6_safi_flap_regexp,
8324        show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8325        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8326        SHOW_STR
8327        BGP_STR
8328        IPV6_STR
8329        "Address Family Modifier\n"
8330        "Address Family Modifier\n"
8331        "Address Family Modifier\n"
8332        "Address Family Modifier\n"
8333        "Display detailed information about dampening\n"
8334        "Display flap statistics of routes\n"
8335        "Display routes matching the AS path regular expression\n"
8336        "A regular-expression to match the BGP AS paths\n")
8337 
8338 DEFUN (show_bgp_ipv4_safi_regexp,
8339        show_bgp_ipv4_safi_regexp_cmd,
8340        "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8341        SHOW_STR
8342        BGP_STR
8343        "Address family\n"
8344        "Address Family modifier\n"
8345        "Address Family modifier\n"
8346        "Address Family modifier\n"
8347        "Address Family modifier\n"
8348        "Display routes matching the AS path regular expression\n"
8349        "A regular-expression to match the BGP AS paths\n")
8350 {
8351   safi_t	safi;
8352   if (bgp_parse_safi(argv[0], &safi)) {
8353     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8354     return CMD_WARNING;
8355   }
8356 
8357   return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8358 			  bgp_show_type_regexp);
8359 }
8360 
8361 DEFUN (show_bgp_ipv6_safi_regexp,
8362        show_bgp_ipv6_safi_regexp_cmd,
8363        "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
8364        SHOW_STR
8365        BGP_STR
8366        "Address family\n"
8367        "Address Family modifier\n"
8368        "Address Family modifier\n"
8369        "Address Family modifier\n"
8370        "Address Family modifier\n"
8371        "Display routes matching the AS path regular expression\n"
8372        "A regular-expression to match the BGP AS paths\n")
8373 {
8374   safi_t	safi;
8375   if (bgp_parse_safi(argv[0], &safi)) {
8376     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8377     return CMD_WARNING;
8378   }
8379 
8380   return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8381 			  bgp_show_type_regexp);
8382 }
8383 
8384 DEFUN (show_bgp_ipv6_regexp,
8385        show_bgp_ipv6_regexp_cmd,
8386        "show bgp ipv6 regexp .LINE",
8387        SHOW_STR
8388        BGP_STR
8389        "Address family\n"
8390        "Display routes matching the AS path regular expression\n"
8391        "A regular-expression to match the BGP AS paths\n")
8392 {
8393   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8394 			  bgp_show_type_regexp);
8395 }
8396 
8397 static int
bgp_show_prefix_list(struct vty * vty,const char * prefix_list_str,afi_t afi,safi_t safi,enum bgp_show_type type)8398 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
8399 		      safi_t safi, enum bgp_show_type type)
8400 {
8401   struct prefix_list *plist;
8402 
8403   plist = prefix_list_lookup (afi, prefix_list_str);
8404   if (plist == NULL)
8405     {
8406       vty_out (vty, "%% %s is not a valid prefix-list name%s",
8407                prefix_list_str, VTY_NEWLINE);
8408       return CMD_WARNING;
8409     }
8410 
8411   return bgp_show (vty, NULL, afi, safi, type, plist);
8412 }
8413 DEFUN (show_ip_bgp_prefix_list,
8414        show_ip_bgp_prefix_list_cmd,
8415        "show ip bgp prefix-list WORD",
8416        SHOW_STR
8417        IP_STR
8418        BGP_STR
8419        "Display routes conforming to the prefix-list\n"
8420        "IP prefix-list name\n")
8421 {
8422   return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8423 			       bgp_show_type_prefix_list);
8424 }
8425 
8426 DEFUN (show_ip_bgp_flap_prefix_list,
8427        show_ip_bgp_flap_prefix_list_cmd,
8428        "show ip bgp flap-statistics prefix-list WORD",
8429        SHOW_STR
8430        IP_STR
8431        BGP_STR
8432        "Display flap statistics of routes\n"
8433        "Display routes conforming to the prefix-list\n"
8434        "IP prefix-list name\n")
8435 {
8436   return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8437 			       bgp_show_type_flap_prefix_list);
8438 }
8439 
8440 ALIAS (show_ip_bgp_flap_prefix_list,
8441        show_ip_bgp_damp_flap_prefix_list_cmd,
8442        "show ip bgp dampening flap-statistics prefix-list WORD",
8443        SHOW_STR
8444        IP_STR
8445        BGP_STR
8446        "Display detailed information about dampening\n"
8447        "Display flap statistics of routes\n"
8448        "Display routes conforming to the prefix-list\n"
8449        "IP prefix-list name\n")
8450 
8451 DEFUN (show_ip_bgp_ipv4_prefix_list,
8452        show_ip_bgp_ipv4_prefix_list_cmd,
8453        "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8454        SHOW_STR
8455        IP_STR
8456        BGP_STR
8457        "Address family\n"
8458        "Address Family modifier\n"
8459        "Address Family modifier\n"
8460        "Display routes conforming to the prefix-list\n"
8461        "IP prefix-list name\n")
8462 {
8463   if (strncmp (argv[0], "m", 1) == 0)
8464     return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8465 			         bgp_show_type_prefix_list);
8466 
8467   return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8468 			       bgp_show_type_prefix_list);
8469 }
8470 
8471 DEFUN (show_bgp_prefix_list,
8472        show_bgp_prefix_list_cmd,
8473        "show bgp prefix-list WORD",
8474        SHOW_STR
8475        BGP_STR
8476        "Display routes conforming to the prefix-list\n"
8477        "IPv6 prefix-list name\n")
8478 {
8479   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8480 			       bgp_show_type_prefix_list);
8481 }
8482 
8483 ALIAS (show_bgp_prefix_list,
8484        show_bgp_ipv6_prefix_list_cmd,
8485        "show bgp ipv6 prefix-list WORD",
8486        SHOW_STR
8487        BGP_STR
8488        "Address family\n"
8489        "Display routes conforming to the prefix-list\n"
8490        "IPv6 prefix-list name\n")
8491 
8492 /* old command */
8493 DEFUN (show_ipv6_bgp_prefix_list,
8494        show_ipv6_bgp_prefix_list_cmd,
8495        "show ipv6 bgp prefix-list WORD",
8496        SHOW_STR
8497        IPV6_STR
8498        BGP_STR
8499        "Display routes matching the prefix-list\n"
8500        "IPv6 prefix-list name\n")
8501 {
8502   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8503 			       bgp_show_type_prefix_list);
8504 }
8505 
8506 /* old command */
8507 DEFUN (show_ipv6_mbgp_prefix_list,
8508        show_ipv6_mbgp_prefix_list_cmd,
8509        "show ipv6 mbgp prefix-list WORD",
8510        SHOW_STR
8511        IPV6_STR
8512        MBGP_STR
8513        "Display routes matching the prefix-list\n"
8514        "IPv6 prefix-list name\n")
8515 {
8516   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8517 			       bgp_show_type_prefix_list);
8518 }
8519 
8520 DEFUN (show_bgp_ipv4_prefix_list,
8521        show_bgp_ipv4_prefix_list_cmd,
8522        "show bgp ipv4 prefix-list WORD",
8523        SHOW_STR
8524        BGP_STR
8525        IP_STR
8526        "Display routes conforming to the prefix-list\n"
8527        "IP prefix-list name\n")
8528 {
8529   return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8530 			       bgp_show_type_prefix_list);
8531 }
8532 
8533 DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8534        show_bgp_ipv4_safi_flap_prefix_list_cmd,
8535        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
8536        SHOW_STR
8537        BGP_STR
8538        IP_STR
8539        "Address Family Modifier\n"
8540        "Address Family Modifier\n"
8541        "Address Family Modifier\n"
8542        "Address Family Modifier\n"
8543        "Display flap statistics of routes\n"
8544        "Display routes conforming to the prefix-list\n"
8545        "IP prefix-list name\n")
8546 {
8547   safi_t	safi;
8548   if (bgp_parse_safi(argv[0], &safi)) {
8549     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8550     return CMD_WARNING;
8551   }
8552   return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
8553 			       bgp_show_type_flap_prefix_list);
8554 }
8555 
8556 ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8557        show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8558        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8559        SHOW_STR
8560        BGP_STR
8561        IP_STR
8562        "Address Family Modifier\n"
8563        "Address Family Modifier\n"
8564        "Address Family Modifier\n"
8565        "Address Family Modifier\n"
8566        "Display detailed information about dampening\n"
8567        "Display flap statistics of routes\n"
8568        "Display routes conforming to the prefix-list\n"
8569        "IP prefix-list name\n")
8570 
8571 DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8572        show_bgp_ipv6_safi_flap_prefix_list_cmd,
8573        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
8574        SHOW_STR
8575        BGP_STR
8576        IPV6_STR
8577        "Address Family Modifier\n"
8578        "Address Family Modifier\n"
8579        "Address Family Modifier\n"
8580        "Address Family Modifier\n"
8581        "Display flap statistics of routes\n"
8582        "Display routes conforming to the prefix-list\n"
8583        "IP prefix-list name\n")
8584 {
8585   safi_t	safi;
8586   if (bgp_parse_safi(argv[0], &safi)) {
8587     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8588     return CMD_WARNING;
8589   }
8590   return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8591 			       bgp_show_type_flap_prefix_list);
8592 }
8593 ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8594        show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8595        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8596        SHOW_STR
8597        BGP_STR
8598        IPV6_STR
8599        "Address Family Modifier\n"
8600        "Address Family Modifier\n"
8601        "Address Family Modifier\n"
8602        "Address Family Modifier\n"
8603        "Display detailed information about dampening\n"
8604        "Display flap statistics of routes\n"
8605        "Display routes conforming to the prefix-list\n"
8606        "IP prefix-list name\n")
8607 
8608 DEFUN (show_bgp_ipv4_safi_prefix_list,
8609        show_bgp_ipv4_safi_prefix_list_cmd,
8610        "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8611        SHOW_STR
8612        BGP_STR
8613        "Address family\n"
8614        "Address Family modifier\n"
8615        "Address Family modifier\n"
8616        "Address Family modifier\n"
8617        "Address Family modifier\n"
8618        "Display routes conforming to the prefix-list\n"
8619        "IP prefix-list name\n")
8620 {
8621   safi_t	safi;
8622   if (bgp_parse_safi(argv[0], &safi)) {
8623     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8624     return CMD_WARNING;
8625   }
8626   return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
8627 			       bgp_show_type_prefix_list);
8628 }
8629 
8630 DEFUN (show_bgp_ipv6_safi_prefix_list,
8631        show_bgp_ipv6_safi_prefix_list_cmd,
8632        "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
8633        SHOW_STR
8634        BGP_STR
8635        "Address family\n"
8636        "Address Family modifier\n"
8637        "Address Family modifier\n"
8638        "Address Family modifier\n"
8639        "Address Family modifier\n"
8640        "Display routes conforming to the prefix-list\n"
8641        "IP prefix-list name\n")
8642 {
8643   safi_t	safi;
8644   if (bgp_parse_safi(argv[0], &safi)) {
8645     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8646     return CMD_WARNING;
8647   }
8648   return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8649 			       bgp_show_type_prefix_list);
8650 }
8651 
8652 static int
bgp_show_filter_list(struct vty * vty,const char * filter,afi_t afi,safi_t safi,enum bgp_show_type type)8653 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
8654 		      safi_t safi, enum bgp_show_type type)
8655 {
8656   struct as_list *as_list;
8657 
8658   as_list = as_list_lookup (filter);
8659   if (as_list == NULL)
8660     {
8661       vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8662       return CMD_WARNING;
8663     }
8664 
8665   return bgp_show (vty, NULL, afi, safi, type, as_list);
8666 }
8667 
8668 DEFUN (show_ip_bgp_filter_list,
8669        show_ip_bgp_filter_list_cmd,
8670        "show ip bgp filter-list WORD",
8671        SHOW_STR
8672        IP_STR
8673        BGP_STR
8674        "Display routes conforming to the filter-list\n"
8675        "Regular expression access list name\n")
8676 {
8677   return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8678 			       bgp_show_type_filter_list);
8679 }
8680 
8681 DEFUN (show_ip_bgp_flap_filter_list,
8682        show_ip_bgp_flap_filter_list_cmd,
8683        "show ip bgp flap-statistics filter-list WORD",
8684        SHOW_STR
8685        IP_STR
8686        BGP_STR
8687        "Display flap statistics of routes\n"
8688        "Display routes conforming to the filter-list\n"
8689        "Regular expression access list name\n")
8690 {
8691   return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8692 			       bgp_show_type_flap_filter_list);
8693 }
8694 
8695 ALIAS (show_ip_bgp_flap_filter_list,
8696        show_ip_bgp_damp_flap_filter_list_cmd,
8697        "show ip bgp dampening flap-statistics filter-list WORD",
8698        SHOW_STR
8699        IP_STR
8700        BGP_STR
8701        "Display detailed information about dampening\n"
8702        "Display flap statistics of routes\n"
8703        "Display routes conforming to the filter-list\n"
8704        "Regular expression access list name\n")
8705 
8706 DEFUN (show_ip_bgp_ipv4_filter_list,
8707        show_ip_bgp_ipv4_filter_list_cmd,
8708        "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8709        SHOW_STR
8710        IP_STR
8711        BGP_STR
8712        "Address family\n"
8713        "Address Family modifier\n"
8714        "Address Family modifier\n"
8715        "Display routes conforming to the filter-list\n"
8716        "Regular expression access list name\n")
8717 {
8718   if (strncmp (argv[0], "m", 1) == 0)
8719     return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8720 			         bgp_show_type_filter_list);
8721 
8722   return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8723 			       bgp_show_type_filter_list);
8724 }
8725 
8726 DEFUN (show_bgp_filter_list,
8727        show_bgp_filter_list_cmd,
8728        "show bgp filter-list WORD",
8729        SHOW_STR
8730        BGP_STR
8731        "Display routes conforming to the filter-list\n"
8732        "Regular expression access list name\n")
8733 {
8734   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8735 			       bgp_show_type_filter_list);
8736 }
8737 
8738 /* old command */
8739 DEFUN (show_ipv6_bgp_filter_list,
8740        show_ipv6_bgp_filter_list_cmd,
8741        "show ipv6 bgp filter-list WORD",
8742        SHOW_STR
8743        IPV6_STR
8744        BGP_STR
8745        "Display routes conforming to the filter-list\n"
8746        "Regular expression access list name\n")
8747 {
8748   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8749 			       bgp_show_type_filter_list);
8750 }
8751 
8752 /* old command */
8753 DEFUN (show_ipv6_mbgp_filter_list,
8754        show_ipv6_mbgp_filter_list_cmd,
8755        "show ipv6 mbgp filter-list WORD",
8756        SHOW_STR
8757        IPV6_STR
8758        MBGP_STR
8759        "Display routes conforming to the filter-list\n"
8760        "Regular expression access list name\n")
8761 {
8762   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8763 			       bgp_show_type_filter_list);
8764 }
8765 
8766 DEFUN (show_ip_bgp_dampening_info,
8767        show_ip_bgp_dampening_params_cmd,
8768        "show ip bgp dampening parameters",
8769        SHOW_STR
8770        IP_STR
8771        BGP_STR
8772        "Display detailed information about dampening\n"
8773        "Display detail of configured dampening parameters\n")
8774 {
8775     return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8776 }
8777 
8778 DEFUN (show_bgp_ipv4_filter_list,
8779        show_bgp_ipv4_filter_list_cmd,
8780        "show bgp ipv4 filter-list WORD",
8781        SHOW_STR
8782        BGP_STR
8783        IP_STR
8784        "Display routes conforming to the filter-list\n"
8785        "Regular expression access list name\n")
8786 {
8787   return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8788 			       bgp_show_type_filter_list);
8789 }
8790 
8791 DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8792        show_bgp_ipv4_safi_flap_filter_list_cmd,
8793        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
8794        SHOW_STR
8795        BGP_STR
8796        IP_STR
8797        "Address Family modifier\n"
8798        "Address Family modifier\n"
8799        "Address Family modifier\n"
8800        "Address Family modifier\n"
8801        "Display flap statistics of routes\n"
8802        "Display routes conforming to the filter-list\n"
8803        "Regular expression access list name\n")
8804 {
8805   safi_t	safi;
8806 
8807   if (bgp_parse_safi(argv[0], &safi)) {
8808     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8809     return CMD_WARNING;
8810   }
8811   return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8812 			       bgp_show_type_flap_filter_list);
8813 }
8814 
8815 ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8816        show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8817        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8818        SHOW_STR
8819        BGP_STR
8820        IP_STR
8821        "Address Family modifier\n"
8822        "Address Family modifier\n"
8823        "Address Family modifier\n"
8824        "Address Family modifier\n"
8825        "Display detailed information about dampening\n"
8826        "Display flap statistics of routes\n"
8827        "Display routes conforming to the filter-list\n"
8828        "Regular expression access list name\n")
8829 
8830 DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8831        show_bgp_ipv6_safi_flap_filter_list_cmd,
8832        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
8833        SHOW_STR
8834        BGP_STR
8835        IPV6_STR
8836        "Address Family modifier\n"
8837        "Address Family modifier\n"
8838        "Address Family modifier\n"
8839        "Address Family modifier\n"
8840        "Display flap statistics of routes\n"
8841        "Display routes conforming to the filter-list\n"
8842        "Regular expression access list name\n")
8843 {
8844   safi_t	safi;
8845 
8846   if (bgp_parse_safi(argv[0], &safi)) {
8847     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8848     return CMD_WARNING;
8849   }
8850   return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8851 			       bgp_show_type_flap_filter_list);
8852 }
8853 ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8854        show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8855        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8856        SHOW_STR
8857        BGP_STR
8858        IPV6_STR
8859        "Address Family modifier\n"
8860        "Address Family modifier\n"
8861        "Address Family modifier\n"
8862        "Address Family modifier\n"
8863        "Display detailed information about dampening\n"
8864        "Display flap statistics of routes\n"
8865        "Display routes conforming to the filter-list\n"
8866        "Regular expression access list name\n")
8867 
8868 DEFUN (show_bgp_ipv4_safi_filter_list,
8869        show_bgp_ipv4_safi_filter_list_cmd,
8870        "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8871        SHOW_STR
8872        BGP_STR
8873        "Address Family modifier\n"
8874        "Address Family modifier\n"
8875        "Address Family modifier\n"
8876        "Address Family modifier\n"
8877        "Display routes conforming to the filter-list\n"
8878        "Regular expression access list name\n")
8879 {
8880   safi_t	safi;
8881 
8882   if (bgp_parse_safi(argv[0], &safi)) {
8883     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8884     return CMD_WARNING;
8885   }
8886   return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8887 			         bgp_show_type_filter_list);
8888 }
8889 
8890 DEFUN (show_bgp_ipv6_safi_filter_list,
8891        show_bgp_ipv6_safi_filter_list_cmd,
8892        "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8893        SHOW_STR
8894        BGP_STR
8895        "Address Family modifier\n"
8896        "Address Family modifier\n"
8897        "Address Family modifier\n"
8898        "Address Family modifier\n"
8899        "Display routes conforming to the filter-list\n"
8900        "Regular expression access list name\n")
8901 {
8902   safi_t	safi;
8903 
8904   if (bgp_parse_safi(argv[0], &safi)) {
8905     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8906     return CMD_WARNING;
8907   }
8908   return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8909 			         bgp_show_type_filter_list);
8910 }
8911 
8912 DEFUN (show_bgp_ipv6_filter_list,
8913        show_bgp_ipv6_filter_list_cmd,
8914        "show bgp ipv6 filter-list WORD",
8915        SHOW_STR
8916        BGP_STR
8917        "Address family\n"
8918        "Display routes conforming to the filter-list\n"
8919        "Regular expression access list name\n")
8920 {
8921   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8922 			       bgp_show_type_filter_list);
8923 }
8924 
8925 
8926 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8927        show_ip_bgp_ipv4_dampening_parameters_cmd,
8928        "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8929        SHOW_STR
8930        IP_STR
8931        BGP_STR
8932        "Address family\n"
8933        "Address Family modifier\n"
8934        "Address Family modifier\n"
8935        "Display detailed information about dampening\n"
8936        "Display detail of configured dampening parameters\n")
8937 {
8938     if (strncmp(argv[0], "m", 1) == 0)
8939       return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8940 
8941     return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8942 }
8943 
8944 
8945 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8946        show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8947        "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8948        SHOW_STR
8949        IP_STR
8950        BGP_STR
8951        "Address family\n"
8952        "Address Family modifier\n"
8953        "Address Family modifier\n"
8954        "Display detailed information about dampening\n"
8955        "Display flap statistics of routes\n")
8956 {
8957     if (strncmp(argv[0], "m", 1) == 0)
8958       return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8959                      bgp_show_type_flap_statistics, NULL);
8960 
8961     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8962                  bgp_show_type_flap_statistics, NULL);
8963 }
8964 
8965 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8966        show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8967        "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8968        SHOW_STR
8969        IP_STR
8970        BGP_STR
8971        "Address family\n"
8972        "Address Family modifier\n"
8973        "Address Family modifier\n"
8974        "Display detailed information about dampening\n"
8975        "Display paths suppressed due to dampening\n")
8976 {
8977     if (strncmp(argv[0], "m", 1) == 0)
8978       return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8979                      bgp_show_type_dampend_paths, NULL);
8980 
8981     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8982                  bgp_show_type_dampend_paths, NULL);
8983 }
8984 
8985 static int
bgp_show_route_map(struct vty * vty,const char * rmap_str,afi_t afi,safi_t safi,enum bgp_show_type type)8986 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
8987 		    safi_t safi, enum bgp_show_type type)
8988 {
8989   struct route_map *rmap;
8990 
8991   rmap = route_map_lookup_by_name (rmap_str);
8992   if (! rmap)
8993     {
8994       vty_out (vty, "%% %s is not a valid route-map name%s",
8995 	       rmap_str, VTY_NEWLINE);
8996       return CMD_WARNING;
8997     }
8998 
8999   return bgp_show (vty, NULL, afi, safi, type, rmap);
9000 }
9001 
9002 DEFUN (show_ip_bgp_route_map,
9003        show_ip_bgp_route_map_cmd,
9004        "show ip bgp route-map WORD",
9005        SHOW_STR
9006        IP_STR
9007        BGP_STR
9008        "Display routes matching the route-map\n"
9009        "A route-map to match on\n")
9010 {
9011   return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9012 			     bgp_show_type_route_map);
9013 }
9014 
9015 DEFUN (show_ip_bgp_flap_route_map,
9016        show_ip_bgp_flap_route_map_cmd,
9017        "show ip bgp flap-statistics route-map WORD",
9018        SHOW_STR
9019        IP_STR
9020        BGP_STR
9021        "Display flap statistics of routes\n"
9022        "Display routes matching the route-map\n"
9023        "A route-map to match on\n")
9024 {
9025   return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9026 			     bgp_show_type_flap_route_map);
9027 }
9028 
9029 ALIAS (show_ip_bgp_flap_route_map,
9030        show_ip_bgp_damp_flap_route_map_cmd,
9031        "show ip bgp dampening flap-statistics route-map WORD",
9032        SHOW_STR
9033        IP_STR
9034        BGP_STR
9035        "Display detailed information about dampening\n"
9036        "Display flap statistics of routes\n"
9037        "Display routes matching the route-map\n"
9038        "A route-map to match on\n")
9039 
9040 DEFUN (show_ip_bgp_ipv4_route_map,
9041        show_ip_bgp_ipv4_route_map_cmd,
9042        "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9043        SHOW_STR
9044        IP_STR
9045        BGP_STR
9046        "Address family\n"
9047        "Address Family modifier\n"
9048        "Address Family modifier\n"
9049        "Display routes matching the route-map\n"
9050        "A route-map to match on\n")
9051 {
9052   if (strncmp (argv[0], "m", 1) == 0)
9053     return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9054 			       bgp_show_type_route_map);
9055 
9056   return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
9057 			     bgp_show_type_route_map);
9058 }
9059 
9060 DEFUN (show_bgp_route_map,
9061        show_bgp_route_map_cmd,
9062        "show bgp route-map WORD",
9063        SHOW_STR
9064        BGP_STR
9065        "Display routes matching the route-map\n"
9066        "A route-map to match on\n")
9067 {
9068   return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9069 			     bgp_show_type_route_map);
9070 }
9071 
9072 DEFUN (show_ip_bgp_cidr_only,
9073        show_ip_bgp_cidr_only_cmd,
9074        "show ip bgp cidr-only",
9075        SHOW_STR
9076        IP_STR
9077        BGP_STR
9078        "Display only routes with non-natural netmasks\n")
9079 {
9080     return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9081 		     bgp_show_type_cidr_only, NULL);
9082 }
9083 
9084 DEFUN (show_ip_bgp_flap_cidr_only,
9085        show_ip_bgp_flap_cidr_only_cmd,
9086        "show ip bgp flap-statistics cidr-only",
9087        SHOW_STR
9088        IP_STR
9089        BGP_STR
9090        "Display flap statistics of routes\n"
9091        "Display only routes with non-natural netmasks\n")
9092 {
9093   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9094 		   bgp_show_type_flap_cidr_only, NULL);
9095 }
9096 
9097 ALIAS (show_ip_bgp_flap_cidr_only,
9098        show_ip_bgp_damp_flap_cidr_only_cmd,
9099        "show ip bgp dampening flap-statistics cidr-only",
9100        SHOW_STR
9101        IP_STR
9102        BGP_STR
9103        "Display detailed information about dampening\n"
9104        "Display flap statistics of routes\n"
9105        "Display only routes with non-natural netmasks\n")
9106 
9107 DEFUN (show_ip_bgp_ipv4_cidr_only,
9108        show_ip_bgp_ipv4_cidr_only_cmd,
9109        "show ip bgp ipv4 (unicast|multicast) cidr-only",
9110        SHOW_STR
9111        IP_STR
9112        BGP_STR
9113        "Address family\n"
9114        "Address Family modifier\n"
9115        "Address Family modifier\n"
9116        "Display only routes with non-natural netmasks\n")
9117 {
9118   if (strncmp (argv[0], "m", 1) == 0)
9119     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9120 		     bgp_show_type_cidr_only, NULL);
9121 
9122   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9123 		     bgp_show_type_cidr_only, NULL);
9124 }
9125 
9126 DEFUN (show_ip_bgp_community_all,
9127        show_ip_bgp_community_all_cmd,
9128        "show ip bgp community",
9129        SHOW_STR
9130        IP_STR
9131        BGP_STR
9132        "Display routes matching the communities\n")
9133 {
9134   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9135 		     bgp_show_type_community_all, NULL);
9136 }
9137 
9138 DEFUN (show_ip_bgp_ipv4_community_all,
9139        show_ip_bgp_ipv4_community_all_cmd,
9140        "show ip bgp ipv4 (unicast|multicast) community",
9141        SHOW_STR
9142        IP_STR
9143        BGP_STR
9144        "Address family\n"
9145        "Address Family modifier\n"
9146        "Address Family modifier\n"
9147        "Display routes matching the communities\n")
9148 {
9149   if (strncmp (argv[0], "m", 1) == 0)
9150     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9151 		     bgp_show_type_community_all, NULL);
9152 
9153   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9154 		   bgp_show_type_community_all, NULL);
9155 }
9156 
9157 DEFUN (show_bgp_community_all,
9158        show_bgp_community_all_cmd,
9159        "show bgp community",
9160        SHOW_STR
9161        BGP_STR
9162        "Display routes matching the communities\n")
9163 {
9164   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9165 		   bgp_show_type_community_all, NULL);
9166 }
9167 
9168 ALIAS (show_bgp_community_all,
9169        show_bgp_ipv6_community_all_cmd,
9170        "show bgp ipv6 community",
9171        SHOW_STR
9172        BGP_STR
9173        "Address family\n"
9174        "Display routes matching the communities\n")
9175 
9176 /* old command */
9177 DEFUN (show_ipv6_bgp_community_all,
9178        show_ipv6_bgp_community_all_cmd,
9179        "show ipv6 bgp community",
9180        SHOW_STR
9181        IPV6_STR
9182        BGP_STR
9183        "Display routes matching the communities\n")
9184 {
9185   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9186 		   bgp_show_type_community_all, NULL);
9187 }
9188 
9189 /* old command */
9190 DEFUN (show_ipv6_mbgp_community_all,
9191        show_ipv6_mbgp_community_all_cmd,
9192        "show ipv6 mbgp community",
9193        SHOW_STR
9194        IPV6_STR
9195        MBGP_STR
9196        "Display routes matching the communities\n")
9197 {
9198   return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9199 		   bgp_show_type_community_all, NULL);
9200 }
9201 
9202 /* large-community */
9203 DEFUN (show_ip_bgp_lcommunity_all,
9204        show_ip_bgp_lcommunity_all_cmd,
9205        "show ip bgp large-community",
9206        SHOW_STR
9207        IP_STR
9208        BGP_STR
9209        "Display routes matching the large-communities\n")
9210 {
9211   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9212 		     bgp_show_type_lcommunity_all, NULL);
9213 }
9214 
9215 DEFUN (show_ip_bgp_ipv4_lcommunity_all,
9216        show_ip_bgp_ipv4_lcommunity_all_cmd,
9217        "show ip bgp ipv4 (unicast|multicast) large-community",
9218        SHOW_STR
9219        IP_STR
9220        BGP_STR
9221        "Address family\n"
9222        "Address Family modifier\n"
9223        "Address Family modifier\n"
9224        "Display routes matching the large-communities\n")
9225 {
9226   if (strncmp (argv[0], "m", 1) == 0)
9227     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9228 		     bgp_show_type_lcommunity_all, NULL);
9229 
9230   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9231 		   bgp_show_type_lcommunity_all, NULL);
9232 }
9233 
9234 DEFUN (show_bgp_lcommunity_all,
9235        show_bgp_lcommunity_all_cmd,
9236        "show bgp large-community",
9237        SHOW_STR
9238        BGP_STR
9239        "Display routes matching the large-communities\n")
9240 {
9241   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9242 		   bgp_show_type_lcommunity_all, NULL);
9243 }
9244 
9245 ALIAS (show_bgp_lcommunity_all,
9246        show_bgp_ipv6_lcommunity_all_cmd,
9247        "show bgp ipv6 large-community",
9248        SHOW_STR
9249        BGP_STR
9250        "Address family\n"
9251        "Display routes matching the large-communities\n")
9252 
9253 /* old command */
9254 DEFUN (show_ipv6_bgp_lcommunity_all,
9255        show_ipv6_bgp_lcommunity_all_cmd,
9256        "show ipv6 bgp large-community",
9257        SHOW_STR
9258        IPV6_STR
9259        BGP_STR
9260        "Display routes matching the large-communities\n")
9261 {
9262   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9263 		   bgp_show_type_lcommunity_all, NULL);
9264 }
9265 
9266 /* old command */
9267 DEFUN (show_ipv6_mbgp_lcommunity_all,
9268        show_ipv6_mbgp_lcommunity_all_cmd,
9269        "show ipv6 mbgp large-community",
9270        SHOW_STR
9271        IPV6_STR
9272        MBGP_STR
9273        "Display routes matching the large-communities\n")
9274 {
9275   return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9276 		   bgp_show_type_lcommunity_all, NULL);
9277 }
9278 
9279 
9280 DEFUN (show_bgp_ipv4_route_map,
9281        show_bgp_ipv4_route_map_cmd,
9282        "show bgp ipv4 route-map WORD",
9283        SHOW_STR
9284        BGP_STR
9285        IP_STR
9286        "Display routes matching the route-map\n"
9287        "A route-map to match on\n")
9288 {
9289   return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9290 			     bgp_show_type_route_map);
9291 }
9292 
9293 DEFUN (show_bgp_ipv4_safi_flap_route_map,
9294        show_bgp_ipv4_safi_flap_route_map_cmd,
9295        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
9296        SHOW_STR
9297        BGP_STR
9298        IP_STR
9299        "Address Family Modifier\n"
9300        "Address Family Modifier\n"
9301        "Address Family Modifier\n"
9302        "Address Family Modifier\n"
9303        "Display flap statistics of routes\n"
9304        "Display routes matching the route-map\n"
9305        "A route-map to match on\n")
9306 {
9307   safi_t	safi;
9308   if (bgp_parse_safi(argv[0], &safi)) {
9309     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9310     return CMD_WARNING;
9311   }
9312   return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
9313 			     bgp_show_type_flap_route_map);
9314 }
9315 
9316 ALIAS (show_bgp_ipv4_safi_flap_route_map,
9317        show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9318        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9319        SHOW_STR
9320        BGP_STR
9321        IP_STR
9322        "Address Family Modifier\n"
9323        "Address Family Modifier\n"
9324        "Address Family Modifier\n"
9325        "Address Family Modifier\n"
9326        "Display detailed information about dampening\n"
9327        "Display flap statistics of routes\n"
9328        "Display routes matching the route-map\n"
9329        "A route-map to match on\n")
9330 
9331 DEFUN (show_bgp_ipv6_safi_flap_route_map,
9332        show_bgp_ipv6_safi_flap_route_map_cmd,
9333        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
9334        SHOW_STR
9335        BGP_STR
9336        IPV6_STR
9337        "Address Family Modifier\n"
9338        "Address Family Modifier\n"
9339        "Address Family Modifier\n"
9340        "Address Family Modifier\n"
9341        "Display flap statistics of routes\n"
9342        "Display routes matching the route-map\n"
9343        "A route-map to match on\n")
9344 {
9345   safi_t	safi;
9346   if (bgp_parse_safi(argv[0], &safi)) {
9347     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9348     return CMD_WARNING;
9349   }
9350   return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9351 			     bgp_show_type_flap_route_map);
9352 }
9353 ALIAS (show_bgp_ipv6_safi_flap_route_map,
9354        show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9355        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9356        SHOW_STR
9357        BGP_STR
9358        IPV6_STR
9359        "Address Family Modifier\n"
9360        "Address Family Modifier\n"
9361        "Address Family Modifier\n"
9362        "Address Family Modifier\n"
9363        "Display detailed information about dampening\n"
9364        "Display flap statistics of routes\n"
9365        "Display routes matching the route-map\n"
9366        "A route-map to match on\n")
9367 
9368 DEFUN (show_bgp_ipv4_safi_route_map,
9369        show_bgp_ipv4_safi_route_map_cmd,
9370        "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9371        SHOW_STR
9372        BGP_STR
9373        "Address family\n"
9374        "Address Family modifier\n"
9375        "Address Family modifier\n"
9376        "Address Family modifier\n"
9377        "Address Family modifier\n"
9378        "Display routes matching the route-map\n"
9379        "A route-map to match on\n")
9380 {
9381   safi_t	safi;
9382   if (bgp_parse_safi(argv[0], &safi)) {
9383     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9384     return CMD_WARNING;
9385   }
9386   return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
9387 			     bgp_show_type_route_map);
9388 }
9389 
9390 DEFUN (show_bgp_ipv6_safi_route_map,
9391        show_bgp_ipv6_safi_route_map_cmd,
9392        "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
9393        SHOW_STR
9394        BGP_STR
9395        "Address family\n"
9396        "Address Family modifier\n"
9397        "Address Family modifier\n"
9398        "Address Family modifier\n"
9399        "Address Family modifier\n"
9400        "Display routes matching the route-map\n"
9401        "A route-map to match on\n")
9402 {
9403   safi_t	safi;
9404   if (bgp_parse_safi(argv[0], &safi)) {
9405     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9406     return CMD_WARNING;
9407   }
9408   return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9409 			     bgp_show_type_route_map);
9410 }
9411 
9412 DEFUN (show_bgp_ipv6_route_map,
9413        show_bgp_ipv6_route_map_cmd,
9414        "show bgp ipv6 route-map WORD",
9415        SHOW_STR
9416        BGP_STR
9417        "Address family\n"
9418        "Display routes matching the route-map\n"
9419        "A route-map to match on\n")
9420 {
9421   return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9422 			     bgp_show_type_route_map);
9423 }
9424 
9425 DEFUN (show_bgp_ipv4_cidr_only,
9426        show_bgp_ipv4_cidr_only_cmd,
9427        "show bgp ipv4 cidr-only",
9428        SHOW_STR
9429        BGP_STR
9430        IP_STR
9431        "Display only routes with non-natural netmasks\n")
9432 {
9433     return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9434 		     bgp_show_type_cidr_only, NULL);
9435 }
9436 
9437 DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9438        show_bgp_ipv4_safi_flap_cidr_only_cmd,
9439        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
9440        SHOW_STR
9441        BGP_STR
9442        "Address Family\n"
9443        "Address Family Modifier\n"
9444        "Address Family Modifier\n"
9445        "Address Family Modifier\n"
9446        "Address Family Modifier\n"
9447        "Display flap statistics of routes\n"
9448        "Display only routes with non-natural netmasks\n")
9449 {
9450   safi_t	safi;
9451 
9452   if (bgp_parse_safi(argv[0], &safi)) {
9453     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9454     return CMD_WARNING;
9455   }
9456   return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
9457 }
9458 
9459 ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9460        show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9461        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
9462        SHOW_STR
9463        BGP_STR
9464        "Address Family\n"
9465        "Address Family Modifier\n"
9466        "Address Family Modifier\n"
9467        "Address Family Modifier\n"
9468        "Address Family Modifier\n"
9469        "Display detailed information about dampening\n"
9470        "Display flap statistics of routes\n"
9471        "Display only routes with non-natural netmasks\n")
9472 
9473 DEFUN (show_bgp_ipv4_safi_cidr_only,
9474        show_bgp_ipv4_safi_cidr_only_cmd,
9475        "show bgp ipv4 (unicast|multicast) cidr-only",
9476        SHOW_STR
9477        BGP_STR
9478        "Address family\n"
9479        "Address Family modifier\n"
9480        "Address Family modifier\n"
9481        "Display only routes with non-natural netmasks\n")
9482 {
9483   if (strncmp (argv[0], "m", 1) == 0)
9484     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9485 		     bgp_show_type_cidr_only, NULL);
9486 
9487   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9488 		     bgp_show_type_cidr_only, NULL);
9489 }
9490 
9491 /* new046 */
9492 DEFUN (show_bgp_afi_safi_community_all,
9493        show_bgp_afi_safi_community_all_cmd,
9494        "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
9495        SHOW_STR
9496        BGP_STR
9497        "Address family\n"
9498        "Address family\n"
9499        "Address Family modifier\n"
9500        "Address Family modifier\n"
9501        "Address Family modifier\n"
9502        "Address Family modifier\n"
9503        "Display routes matching the communities\n")
9504 {
9505   safi_t	safi;
9506   afi_t		afi;
9507 
9508   if (bgp_parse_afi(argv[0], &afi)) {
9509     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9510     return CMD_WARNING;
9511   }
9512   if (bgp_parse_safi(argv[1], &safi)) {
9513     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9514     return CMD_WARNING;
9515   }
9516 
9517   return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9518 }
9519 DEFUN (show_bgp_afi_community_all,
9520        show_bgp_afi_community_all_cmd,
9521        "show bgp (ipv4|ipv6) community",
9522        SHOW_STR
9523        BGP_STR
9524        "Address family\n"
9525        "Address family\n"
9526        "Display routes matching the communities\n")
9527 {
9528   afi_t		afi;
9529   safi_t	safi = SAFI_UNICAST;
9530 
9531   if (bgp_parse_afi(argv[0], &afi)) {
9532     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9533     return CMD_WARNING;
9534   }
9535   return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9536 }
9537 
9538 static int
bgp_show_community(struct vty * vty,const char * view_name,int argc,const char ** argv,int exact,afi_t afi,safi_t safi)9539 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9540 		    const char **argv, int exact, afi_t afi, safi_t safi)
9541 {
9542   struct community *com;
9543   struct buffer *b;
9544   struct bgp *bgp;
9545   int i, rv;
9546   char *str;
9547   int first = 0;
9548 
9549   /* BGP structure lookup */
9550   if (view_name)
9551     {
9552       bgp = bgp_lookup_by_name (view_name);
9553       if (bgp == NULL)
9554 	{
9555 	  vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9556 	  return CMD_WARNING;
9557 	}
9558     }
9559   else
9560     {
9561       bgp = bgp_get_default ();
9562       if (bgp == NULL)
9563 	{
9564 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9565 	  return CMD_WARNING;
9566 	}
9567     }
9568 
9569   b = buffer_new (1024);
9570   for (i = 0; i < argc; i++)
9571     {
9572       if (first)
9573         buffer_putc (b, ' ');
9574       else
9575 	{
9576 	  if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9577 	    continue;
9578 	  first = 1;
9579 	}
9580 
9581       buffer_putstr (b, argv[i]);
9582     }
9583   buffer_putc (b, '\0');
9584 
9585   str = buffer_getstr (b);
9586   buffer_free (b);
9587 
9588   com = community_str2com (str);
9589   XFREE (MTYPE_TMP, str);
9590   if (! com)
9591     {
9592       vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9593       return CMD_WARNING;
9594     }
9595 
9596   rv = bgp_show (vty, bgp, afi, safi,
9597                  (exact ? bgp_show_type_community_exact :
9598 		          bgp_show_type_community), com);
9599   community_free(com);
9600   return rv;
9601 }
9602 
9603 DEFUN (show_ip_bgp_community,
9604        show_ip_bgp_community_cmd,
9605        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9606        SHOW_STR
9607        IP_STR
9608        BGP_STR
9609        "Display routes matching the communities\n"
9610        "community number\n"
9611        "Do not send outside local AS (well-known community)\n"
9612        "Do not advertise to any peer (well-known community)\n"
9613        "Do not export to next AS (well-known community)\n")
9614 {
9615   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9616 }
9617 
9618 ALIAS (show_ip_bgp_community,
9619        show_ip_bgp_community2_cmd,
9620        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9621        SHOW_STR
9622        IP_STR
9623        BGP_STR
9624        "Display routes matching the communities\n"
9625        "community number\n"
9626        "Do not send outside local AS (well-known community)\n"
9627        "Do not advertise to any peer (well-known community)\n"
9628        "Do not export to next AS (well-known community)\n"
9629        "community number\n"
9630        "Do not send outside local AS (well-known community)\n"
9631        "Do not advertise to any peer (well-known community)\n"
9632        "Do not export to next AS (well-known community)\n")
9633 
9634 ALIAS (show_ip_bgp_community,
9635        show_ip_bgp_community3_cmd,
9636        "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)",
9637        SHOW_STR
9638        IP_STR
9639        BGP_STR
9640        "Display routes matching the communities\n"
9641        "community number\n"
9642        "Do not send outside local AS (well-known community)\n"
9643        "Do not advertise to any peer (well-known community)\n"
9644        "Do not export to next AS (well-known community)\n"
9645        "community number\n"
9646        "Do not send outside local AS (well-known community)\n"
9647        "Do not advertise to any peer (well-known community)\n"
9648        "Do not export to next AS (well-known community)\n"
9649        "community number\n"
9650        "Do not send outside local AS (well-known community)\n"
9651        "Do not advertise to any peer (well-known community)\n"
9652        "Do not export to next AS (well-known community)\n")
9653 
9654 ALIAS (show_ip_bgp_community,
9655        show_ip_bgp_community4_cmd,
9656        "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)",
9657        SHOW_STR
9658        IP_STR
9659        BGP_STR
9660        "Display routes matching the communities\n"
9661        "community number\n"
9662        "Do not send outside local AS (well-known community)\n"
9663        "Do not advertise to any peer (well-known community)\n"
9664        "Do not export to next AS (well-known community)\n"
9665        "community number\n"
9666        "Do not send outside local AS (well-known community)\n"
9667        "Do not advertise to any peer (well-known community)\n"
9668        "Do not export to next AS (well-known community)\n"
9669        "community number\n"
9670        "Do not send outside local AS (well-known community)\n"
9671        "Do not advertise to any peer (well-known community)\n"
9672        "Do not export to next AS (well-known community)\n"
9673        "community number\n"
9674        "Do not send outside local AS (well-known community)\n"
9675        "Do not advertise to any peer (well-known community)\n"
9676        "Do not export to next AS (well-known community)\n")
9677 
9678 DEFUN (show_ip_bgp_ipv4_community,
9679        show_ip_bgp_ipv4_community_cmd,
9680        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9681        SHOW_STR
9682        IP_STR
9683        BGP_STR
9684        "Address family\n"
9685        "Address Family modifier\n"
9686        "Address Family modifier\n"
9687        "Display routes matching the communities\n"
9688        "community number\n"
9689        "Do not send outside local AS (well-known community)\n"
9690        "Do not advertise to any peer (well-known community)\n"
9691        "Do not export to next AS (well-known community)\n")
9692 {
9693   if (strncmp (argv[0], "m", 1) == 0)
9694     return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9695 
9696   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9697 }
9698 
9699 ALIAS (show_ip_bgp_ipv4_community,
9700        show_ip_bgp_ipv4_community2_cmd,
9701        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9702        SHOW_STR
9703        IP_STR
9704        BGP_STR
9705        "Address family\n"
9706        "Address Family modifier\n"
9707        "Address Family modifier\n"
9708        "Display routes matching the communities\n"
9709        "community number\n"
9710        "Do not send outside local AS (well-known community)\n"
9711        "Do not advertise to any peer (well-known community)\n"
9712        "Do not export to next AS (well-known community)\n"
9713        "community number\n"
9714        "Do not send outside local AS (well-known community)\n"
9715        "Do not advertise to any peer (well-known community)\n"
9716        "Do not export to next AS (well-known community)\n")
9717 
9718 ALIAS (show_ip_bgp_ipv4_community,
9719        show_ip_bgp_ipv4_community3_cmd,
9720        "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)",
9721        SHOW_STR
9722        IP_STR
9723        BGP_STR
9724        "Address family\n"
9725        "Address Family modifier\n"
9726        "Address Family modifier\n"
9727        "Display routes matching the communities\n"
9728        "community number\n"
9729        "Do not send outside local AS (well-known community)\n"
9730        "Do not advertise to any peer (well-known community)\n"
9731        "Do not export to next AS (well-known community)\n"
9732        "community number\n"
9733        "Do not send outside local AS (well-known community)\n"
9734        "Do not advertise to any peer (well-known community)\n"
9735        "Do not export to next AS (well-known community)\n"
9736        "community number\n"
9737        "Do not send outside local AS (well-known community)\n"
9738        "Do not advertise to any peer (well-known community)\n"
9739        "Do not export to next AS (well-known community)\n")
9740 
9741 ALIAS (show_ip_bgp_ipv4_community,
9742        show_ip_bgp_ipv4_community4_cmd,
9743        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9744        SHOW_STR
9745        IP_STR
9746        BGP_STR
9747        "Address family\n"
9748        "Address Family modifier\n"
9749        "Address Family modifier\n"
9750        "Display routes matching the communities\n"
9751        "community number\n"
9752        "Do not send outside local AS (well-known community)\n"
9753        "Do not advertise to any peer (well-known community)\n"
9754        "Do not export to next AS (well-known community)\n"
9755        "community number\n"
9756        "Do not send outside local AS (well-known community)\n"
9757        "Do not advertise to any peer (well-known community)\n"
9758        "Do not export to next AS (well-known community)\n"
9759        "community number\n"
9760        "Do not send outside local AS (well-known community)\n"
9761        "Do not advertise to any peer (well-known community)\n"
9762        "Do not export to next AS (well-known community)\n"
9763        "community number\n"
9764        "Do not send outside local AS (well-known community)\n"
9765        "Do not advertise to any peer (well-known community)\n"
9766        "Do not export to next AS (well-known community)\n")
9767 
9768 DEFUN (show_ip_bgp_community_exact,
9769        show_ip_bgp_community_exact_cmd,
9770        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9771        SHOW_STR
9772        IP_STR
9773        BGP_STR
9774        "Display routes matching the communities\n"
9775        "community number\n"
9776        "Do not send outside local AS (well-known community)\n"
9777        "Do not advertise to any peer (well-known community)\n"
9778        "Do not export to next AS (well-known community)\n"
9779        "Exact match of the communities")
9780 {
9781   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9782 }
9783 
9784 ALIAS (show_ip_bgp_community_exact,
9785        show_ip_bgp_community2_exact_cmd,
9786        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9787        SHOW_STR
9788        IP_STR
9789        BGP_STR
9790        "Display routes matching the communities\n"
9791        "community number\n"
9792        "Do not send outside local AS (well-known community)\n"
9793        "Do not advertise to any peer (well-known community)\n"
9794        "Do not export to next AS (well-known community)\n"
9795        "community number\n"
9796        "Do not send outside local AS (well-known community)\n"
9797        "Do not advertise to any peer (well-known community)\n"
9798        "Do not export to next AS (well-known community)\n"
9799        "Exact match of the communities")
9800 
9801 ALIAS (show_ip_bgp_community_exact,
9802        show_ip_bgp_community3_exact_cmd,
9803        "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",
9804        SHOW_STR
9805        IP_STR
9806        BGP_STR
9807        "Display routes matching the communities\n"
9808        "community number\n"
9809        "Do not send outside local AS (well-known community)\n"
9810        "Do not advertise to any peer (well-known community)\n"
9811        "Do not export to next AS (well-known community)\n"
9812        "community number\n"
9813        "Do not send outside local AS (well-known community)\n"
9814        "Do not advertise to any peer (well-known community)\n"
9815        "Do not export to next AS (well-known community)\n"
9816        "community number\n"
9817        "Do not send outside local AS (well-known community)\n"
9818        "Do not advertise to any peer (well-known community)\n"
9819        "Do not export to next AS (well-known community)\n"
9820        "Exact match of the communities")
9821 
9822 ALIAS (show_ip_bgp_community_exact,
9823        show_ip_bgp_community4_exact_cmd,
9824        "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",
9825        SHOW_STR
9826        IP_STR
9827        BGP_STR
9828        "Display routes matching the communities\n"
9829        "community number\n"
9830        "Do not send outside local AS (well-known community)\n"
9831        "Do not advertise to any peer (well-known community)\n"
9832        "Do not export to next AS (well-known community)\n"
9833        "community number\n"
9834        "Do not send outside local AS (well-known community)\n"
9835        "Do not advertise to any peer (well-known community)\n"
9836        "Do not export to next AS (well-known community)\n"
9837        "community number\n"
9838        "Do not send outside local AS (well-known community)\n"
9839        "Do not advertise to any peer (well-known community)\n"
9840        "Do not export to next AS (well-known community)\n"
9841        "community number\n"
9842        "Do not send outside local AS (well-known community)\n"
9843        "Do not advertise to any peer (well-known community)\n"
9844        "Do not export to next AS (well-known community)\n"
9845        "Exact match of the communities")
9846 
9847 DEFUN (show_ip_bgp_ipv4_community_exact,
9848        show_ip_bgp_ipv4_community_exact_cmd,
9849        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9850        SHOW_STR
9851        IP_STR
9852        BGP_STR
9853        "Address family\n"
9854        "Address Family modifier\n"
9855        "Address Family modifier\n"
9856        "Display routes matching the communities\n"
9857        "community number\n"
9858        "Do not send outside local AS (well-known community)\n"
9859        "Do not advertise to any peer (well-known community)\n"
9860        "Do not export to next AS (well-known community)\n"
9861        "Exact match of the communities")
9862 {
9863   if (strncmp (argv[0], "m", 1) == 0)
9864     return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9865 
9866   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9867 }
9868 
9869 ALIAS (show_ip_bgp_ipv4_community_exact,
9870        show_ip_bgp_ipv4_community2_exact_cmd,
9871        "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",
9872        SHOW_STR
9873        IP_STR
9874        BGP_STR
9875        "Address family\n"
9876        "Address Family modifier\n"
9877        "Address Family modifier\n"
9878        "Display routes matching the communities\n"
9879        "community number\n"
9880        "Do not send outside local AS (well-known community)\n"
9881        "Do not advertise to any peer (well-known community)\n"
9882        "Do not export to next AS (well-known community)\n"
9883        "community number\n"
9884        "Do not send outside local AS (well-known community)\n"
9885        "Do not advertise to any peer (well-known community)\n"
9886        "Do not export to next AS (well-known community)\n"
9887        "Exact match of the communities")
9888 
9889 ALIAS (show_ip_bgp_ipv4_community_exact,
9890        show_ip_bgp_ipv4_community3_exact_cmd,
9891        "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",
9892        SHOW_STR
9893        IP_STR
9894        BGP_STR
9895        "Address family\n"
9896        "Address Family modifier\n"
9897        "Address Family modifier\n"
9898        "Display routes matching the communities\n"
9899        "community number\n"
9900        "Do not send outside local AS (well-known community)\n"
9901        "Do not advertise to any peer (well-known community)\n"
9902        "Do not export to next AS (well-known community)\n"
9903        "community number\n"
9904        "Do not send outside local AS (well-known community)\n"
9905        "Do not advertise to any peer (well-known community)\n"
9906        "Do not export to next AS (well-known community)\n"
9907        "community number\n"
9908        "Do not send outside local AS (well-known community)\n"
9909        "Do not advertise to any peer (well-known community)\n"
9910        "Do not export to next AS (well-known community)\n"
9911        "Exact match of the communities")
9912 
9913 ALIAS (show_ip_bgp_ipv4_community_exact,
9914        show_ip_bgp_ipv4_community4_exact_cmd,
9915        "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",
9916        SHOW_STR
9917        IP_STR
9918        BGP_STR
9919        "Address family\n"
9920        "Address Family modifier\n"
9921        "Address Family modifier\n"
9922        "Display routes matching the communities\n"
9923        "community number\n"
9924        "Do not send outside local AS (well-known community)\n"
9925        "Do not advertise to any peer (well-known community)\n"
9926        "Do not export to next AS (well-known community)\n"
9927        "community number\n"
9928        "Do not send outside local AS (well-known community)\n"
9929        "Do not advertise to any peer (well-known community)\n"
9930        "Do not export to next AS (well-known community)\n"
9931        "community number\n"
9932        "Do not send outside local AS (well-known community)\n"
9933        "Do not advertise to any peer (well-known community)\n"
9934        "Do not export to next AS (well-known community)\n"
9935        "community number\n"
9936        "Do not send outside local AS (well-known community)\n"
9937        "Do not advertise to any peer (well-known community)\n"
9938        "Do not export to next AS (well-known community)\n"
9939        "Exact match of the communities")
9940 
9941 DEFUN (show_bgp_community,
9942        show_bgp_community_cmd,
9943        "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9944        SHOW_STR
9945        BGP_STR
9946        "Display routes matching the communities\n"
9947        "community number\n"
9948        "Do not send outside local AS (well-known community)\n"
9949        "Do not advertise to any peer (well-known community)\n"
9950        "Do not export to next AS (well-known community)\n")
9951 {
9952   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9953 }
9954 
9955 ALIAS (show_bgp_community,
9956        show_bgp_ipv6_community_cmd,
9957        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9958        SHOW_STR
9959        BGP_STR
9960        "Address family\n"
9961        "Display routes matching the communities\n"
9962        "community number\n"
9963        "Do not send outside local AS (well-known community)\n"
9964        "Do not advertise to any peer (well-known community)\n"
9965        "Do not export to next AS (well-known community)\n")
9966 
9967 ALIAS (show_bgp_community,
9968        show_bgp_community2_cmd,
9969        "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9970        SHOW_STR
9971        BGP_STR
9972        "Display routes matching the communities\n"
9973        "community number\n"
9974        "Do not send outside local AS (well-known community)\n"
9975        "Do not advertise to any peer (well-known community)\n"
9976        "Do not export to next AS (well-known community)\n"
9977        "community number\n"
9978        "Do not send outside local AS (well-known community)\n"
9979        "Do not advertise to any peer (well-known community)\n"
9980        "Do not export to next AS (well-known community)\n")
9981 
9982 ALIAS (show_bgp_community,
9983        show_bgp_ipv6_community2_cmd,
9984        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9985        SHOW_STR
9986        BGP_STR
9987        "Address family\n"
9988        "Display routes matching the communities\n"
9989        "community number\n"
9990        "Do not send outside local AS (well-known community)\n"
9991        "Do not advertise to any peer (well-known community)\n"
9992        "Do not export to next AS (well-known community)\n"
9993        "community number\n"
9994        "Do not send outside local AS (well-known community)\n"
9995        "Do not advertise to any peer (well-known community)\n"
9996        "Do not export to next AS (well-known community)\n")
9997 
9998 ALIAS (show_bgp_community,
9999        show_bgp_community3_cmd,
10000        "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)",
10001        SHOW_STR
10002        BGP_STR
10003        "Display routes matching the communities\n"
10004        "community number\n"
10005        "Do not send outside local AS (well-known community)\n"
10006        "Do not advertise to any peer (well-known community)\n"
10007        "Do not export to next AS (well-known community)\n"
10008        "community number\n"
10009        "Do not send outside local AS (well-known community)\n"
10010        "Do not advertise to any peer (well-known community)\n"
10011        "Do not export to next AS (well-known community)\n"
10012        "community number\n"
10013        "Do not send outside local AS (well-known community)\n"
10014        "Do not advertise to any peer (well-known community)\n"
10015        "Do not export to next AS (well-known community)\n")
10016 
10017 ALIAS (show_bgp_community,
10018        show_bgp_ipv6_community3_cmd,
10019        "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)",
10020        SHOW_STR
10021        BGP_STR
10022        "Address family\n"
10023        "Display routes matching the communities\n"
10024        "community number\n"
10025        "Do not send outside local AS (well-known community)\n"
10026        "Do not advertise to any peer (well-known community)\n"
10027        "Do not export to next AS (well-known community)\n"
10028        "community number\n"
10029        "Do not send outside local AS (well-known community)\n"
10030        "Do not advertise to any peer (well-known community)\n"
10031        "Do not export to next AS (well-known community)\n"
10032        "community number\n"
10033        "Do not send outside local AS (well-known community)\n"
10034        "Do not advertise to any peer (well-known community)\n"
10035        "Do not export to next AS (well-known community)\n")
10036 
10037 ALIAS (show_bgp_community,
10038        show_bgp_community4_cmd,
10039        "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)",
10040        SHOW_STR
10041        BGP_STR
10042        "Display routes matching the communities\n"
10043        "community number\n"
10044        "Do not send outside local AS (well-known community)\n"
10045        "Do not advertise to any peer (well-known community)\n"
10046        "Do not export to next AS (well-known community)\n"
10047        "community number\n"
10048        "Do not send outside local AS (well-known community)\n"
10049        "Do not advertise to any peer (well-known community)\n"
10050        "Do not export to next AS (well-known community)\n"
10051        "community number\n"
10052        "Do not send outside local AS (well-known community)\n"
10053        "Do not advertise to any peer (well-known community)\n"
10054        "Do not export to next AS (well-known community)\n"
10055        "community number\n"
10056        "Do not send outside local AS (well-known community)\n"
10057        "Do not advertise to any peer (well-known community)\n"
10058        "Do not export to next AS (well-known community)\n")
10059 
10060 ALIAS (show_bgp_community,
10061        show_bgp_ipv6_community4_cmd,
10062        "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)",
10063        SHOW_STR
10064        BGP_STR
10065        "Address family\n"
10066        "Display routes matching the communities\n"
10067        "community number\n"
10068        "Do not send outside local AS (well-known community)\n"
10069        "Do not advertise to any peer (well-known community)\n"
10070        "Do not export to next AS (well-known community)\n"
10071        "community number\n"
10072        "Do not send outside local AS (well-known community)\n"
10073        "Do not advertise to any peer (well-known community)\n"
10074        "Do not export to next AS (well-known community)\n"
10075        "community number\n"
10076        "Do not send outside local AS (well-known community)\n"
10077        "Do not advertise to any peer (well-known community)\n"
10078        "Do not export to next AS (well-known community)\n"
10079        "community number\n"
10080        "Do not send outside local AS (well-known community)\n"
10081        "Do not advertise to any peer (well-known community)\n"
10082        "Do not export to next AS (well-known community)\n")
10083 
10084 /* old command */
10085 DEFUN (show_ipv6_bgp_community,
10086        show_ipv6_bgp_community_cmd,
10087        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10088        SHOW_STR
10089        IPV6_STR
10090        BGP_STR
10091        "Display routes matching the communities\n"
10092        "community number\n"
10093        "Do not send outside local AS (well-known community)\n"
10094        "Do not advertise to any peer (well-known community)\n"
10095        "Do not export to next AS (well-known community)\n")
10096 {
10097   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10098 }
10099 
10100 /* old command */
10101 ALIAS (show_ipv6_bgp_community,
10102        show_ipv6_bgp_community2_cmd,
10103        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10104        SHOW_STR
10105        IPV6_STR
10106        BGP_STR
10107        "Display routes matching the communities\n"
10108        "community number\n"
10109        "Do not send outside local AS (well-known community)\n"
10110        "Do not advertise to any peer (well-known community)\n"
10111        "Do not export to next AS (well-known community)\n"
10112        "community number\n"
10113        "Do not send outside local AS (well-known community)\n"
10114        "Do not advertise to any peer (well-known community)\n"
10115        "Do not export to next AS (well-known community)\n")
10116 
10117 /* old command */
10118 ALIAS (show_ipv6_bgp_community,
10119        show_ipv6_bgp_community3_cmd,
10120        "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)",
10121        SHOW_STR
10122        IPV6_STR
10123        BGP_STR
10124        "Display routes matching the communities\n"
10125        "community number\n"
10126        "Do not send outside local AS (well-known community)\n"
10127        "Do not advertise to any peer (well-known community)\n"
10128        "Do not export to next AS (well-known community)\n"
10129        "community number\n"
10130        "Do not send outside local AS (well-known community)\n"
10131        "Do not advertise to any peer (well-known community)\n"
10132        "Do not export to next AS (well-known community)\n"
10133        "community number\n"
10134        "Do not send outside local AS (well-known community)\n"
10135        "Do not advertise to any peer (well-known community)\n"
10136        "Do not export to next AS (well-known community)\n")
10137 
10138 /* old command */
10139 ALIAS (show_ipv6_bgp_community,
10140        show_ipv6_bgp_community4_cmd,
10141        "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)",
10142        SHOW_STR
10143        IPV6_STR
10144        BGP_STR
10145        "Display routes matching the communities\n"
10146        "community number\n"
10147        "Do not send outside local AS (well-known community)\n"
10148        "Do not advertise to any peer (well-known community)\n"
10149        "Do not export to next AS (well-known community)\n"
10150        "community number\n"
10151        "Do not send outside local AS (well-known community)\n"
10152        "Do not advertise to any peer (well-known community)\n"
10153        "Do not export to next AS (well-known community)\n"
10154        "community number\n"
10155        "Do not send outside local AS (well-known community)\n"
10156        "Do not advertise to any peer (well-known community)\n"
10157        "Do not export to next AS (well-known community)\n"
10158        "community number\n"
10159        "Do not send outside local AS (well-known community)\n"
10160        "Do not advertise to any peer (well-known community)\n"
10161        "Do not export to next AS (well-known community)\n")
10162 
10163 DEFUN (show_bgp_community_exact,
10164        show_bgp_community_exact_cmd,
10165        "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10166        SHOW_STR
10167        BGP_STR
10168        "Display routes matching the communities\n"
10169        "community number\n"
10170        "Do not send outside local AS (well-known community)\n"
10171        "Do not advertise to any peer (well-known community)\n"
10172        "Do not export to next AS (well-known community)\n"
10173        "Exact match of the communities")
10174 {
10175   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10176 }
10177 
10178 ALIAS (show_bgp_community_exact,
10179        show_bgp_ipv6_community_exact_cmd,
10180        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10181        SHOW_STR
10182        BGP_STR
10183        "Address family\n"
10184        "Display routes matching the communities\n"
10185        "community number\n"
10186        "Do not send outside local AS (well-known community)\n"
10187        "Do not advertise to any peer (well-known community)\n"
10188        "Do not export to next AS (well-known community)\n"
10189        "Exact match of the communities")
10190 
10191 ALIAS (show_bgp_community_exact,
10192        show_bgp_community2_exact_cmd,
10193        "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10194        SHOW_STR
10195        BGP_STR
10196        "Display routes matching the communities\n"
10197        "community number\n"
10198        "Do not send outside local AS (well-known community)\n"
10199        "Do not advertise to any peer (well-known community)\n"
10200        "Do not export to next AS (well-known community)\n"
10201        "community number\n"
10202        "Do not send outside local AS (well-known community)\n"
10203        "Do not advertise to any peer (well-known community)\n"
10204        "Do not export to next AS (well-known community)\n"
10205        "Exact match of the communities")
10206 
10207 ALIAS (show_bgp_community_exact,
10208        show_bgp_ipv6_community2_exact_cmd,
10209        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10210        SHOW_STR
10211        BGP_STR
10212        "Address family\n"
10213        "Display routes matching the communities\n"
10214        "community number\n"
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        "community number\n"
10219        "Do not send outside local AS (well-known community)\n"
10220        "Do not advertise to any peer (well-known community)\n"
10221        "Do not export to next AS (well-known community)\n"
10222        "Exact match of the communities")
10223 
10224 ALIAS (show_bgp_community_exact,
10225        show_bgp_community3_exact_cmd,
10226        "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",
10227        SHOW_STR
10228        BGP_STR
10229        "Display routes matching the communities\n"
10230        "community number\n"
10231        "Do not send outside local AS (well-known community)\n"
10232        "Do not advertise to any peer (well-known community)\n"
10233        "Do not export to next AS (well-known community)\n"
10234        "community number\n"
10235        "Do not send outside local AS (well-known community)\n"
10236        "Do not advertise to any peer (well-known community)\n"
10237        "Do not export to next AS (well-known community)\n"
10238        "community number\n"
10239        "Do not send outside local AS (well-known community)\n"
10240        "Do not advertise to any peer (well-known community)\n"
10241        "Do not export to next AS (well-known community)\n"
10242        "Exact match of the communities")
10243 
10244 ALIAS (show_bgp_community_exact,
10245        show_bgp_ipv6_community3_exact_cmd,
10246        "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",
10247        SHOW_STR
10248        BGP_STR
10249        "Address family\n"
10250        "Display routes matching the communities\n"
10251        "community number\n"
10252        "Do not send outside local AS (well-known community)\n"
10253        "Do not advertise to any peer (well-known community)\n"
10254        "Do not export to next AS (well-known community)\n"
10255        "community number\n"
10256        "Do not send outside local AS (well-known community)\n"
10257        "Do not advertise to any peer (well-known community)\n"
10258        "Do not export to next AS (well-known community)\n"
10259        "community number\n"
10260        "Do not send outside local AS (well-known community)\n"
10261        "Do not advertise to any peer (well-known community)\n"
10262        "Do not export to next AS (well-known community)\n"
10263        "Exact match of the communities")
10264 
10265 ALIAS (show_bgp_community_exact,
10266        show_bgp_community4_exact_cmd,
10267        "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",
10268        SHOW_STR
10269        BGP_STR
10270        "Display routes matching the communities\n"
10271        "community number\n"
10272        "Do not send outside local AS (well-known community)\n"
10273        "Do not advertise to any peer (well-known community)\n"
10274        "Do not export to next AS (well-known community)\n"
10275        "community number\n"
10276        "Do not send outside local AS (well-known community)\n"
10277        "Do not advertise to any peer (well-known community)\n"
10278        "Do not export to next AS (well-known community)\n"
10279        "community number\n"
10280        "Do not send outside local AS (well-known community)\n"
10281        "Do not advertise to any peer (well-known community)\n"
10282        "Do not export to next AS (well-known community)\n"
10283        "community number\n"
10284        "Do not send outside local AS (well-known community)\n"
10285        "Do not advertise to any peer (well-known community)\n"
10286        "Do not export to next AS (well-known community)\n"
10287        "Exact match of the communities")
10288 
10289 ALIAS (show_bgp_community_exact,
10290        show_bgp_ipv6_community4_exact_cmd,
10291        "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",
10292        SHOW_STR
10293        BGP_STR
10294        "Address family\n"
10295        "Display routes matching the communities\n"
10296        "community number\n"
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 number\n"
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 number\n"
10305        "Do not send outside local AS (well-known community)\n"
10306        "Do not advertise to any peer (well-known community)\n"
10307        "Do not export to next AS (well-known community)\n"
10308        "community number\n"
10309        "Do not send outside local AS (well-known community)\n"
10310        "Do not advertise to any peer (well-known community)\n"
10311        "Do not export to next AS (well-known community)\n"
10312        "Exact match of the communities")
10313 
10314 /* old command */
10315 DEFUN (show_ipv6_bgp_community_exact,
10316        show_ipv6_bgp_community_exact_cmd,
10317        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10318        SHOW_STR
10319        IPV6_STR
10320        BGP_STR
10321        "Display routes matching the communities\n"
10322        "community number\n"
10323        "Do not send outside local AS (well-known community)\n"
10324        "Do not advertise to any peer (well-known community)\n"
10325        "Do not export to next AS (well-known community)\n"
10326        "Exact match of the communities")
10327 {
10328   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10329 }
10330 
10331 /* old command */
10332 ALIAS (show_ipv6_bgp_community_exact,
10333        show_ipv6_bgp_community2_exact_cmd,
10334        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10335        SHOW_STR
10336        IPV6_STR
10337        BGP_STR
10338        "Display routes matching the communities\n"
10339        "community number\n"
10340        "Do not send outside local AS (well-known community)\n"
10341        "Do not advertise to any peer (well-known community)\n"
10342        "Do not export to next AS (well-known community)\n"
10343        "community number\n"
10344        "Do not send outside local AS (well-known community)\n"
10345        "Do not advertise to any peer (well-known community)\n"
10346        "Do not export to next AS (well-known community)\n"
10347        "Exact match of the communities")
10348 
10349 /* old command */
10350 ALIAS (show_ipv6_bgp_community_exact,
10351        show_ipv6_bgp_community3_exact_cmd,
10352        "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",
10353        SHOW_STR
10354        IPV6_STR
10355        BGP_STR
10356        "Display routes matching the communities\n"
10357        "community number\n"
10358        "Do not send outside local AS (well-known community)\n"
10359        "Do not advertise to any peer (well-known community)\n"
10360        "Do not export to next AS (well-known community)\n"
10361        "community number\n"
10362        "Do not send outside local AS (well-known community)\n"
10363        "Do not advertise to any peer (well-known community)\n"
10364        "Do not export to next AS (well-known community)\n"
10365        "community number\n"
10366        "Do not send outside local AS (well-known community)\n"
10367        "Do not advertise to any peer (well-known community)\n"
10368        "Do not export to next AS (well-known community)\n"
10369        "Exact match of the communities")
10370 
10371 /* old command */
10372 ALIAS (show_ipv6_bgp_community_exact,
10373        show_ipv6_bgp_community4_exact_cmd,
10374        "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",
10375        SHOW_STR
10376        IPV6_STR
10377        BGP_STR
10378        "Display routes matching the communities\n"
10379        "community number\n"
10380        "Do not send outside local AS (well-known community)\n"
10381        "Do not advertise to any peer (well-known community)\n"
10382        "Do not export to next AS (well-known community)\n"
10383        "community number\n"
10384        "Do not send outside local AS (well-known community)\n"
10385        "Do not advertise to any peer (well-known community)\n"
10386        "Do not export to next AS (well-known community)\n"
10387        "community number\n"
10388        "Do not send outside local AS (well-known community)\n"
10389        "Do not advertise to any peer (well-known community)\n"
10390        "Do not export to next AS (well-known community)\n"
10391        "community number\n"
10392        "Do not send outside local AS (well-known community)\n"
10393        "Do not advertise to any peer (well-known community)\n"
10394        "Do not export to next AS (well-known community)\n"
10395        "Exact match of the communities")
10396 
10397 /* old command */
10398 DEFUN (show_ipv6_mbgp_community,
10399        show_ipv6_mbgp_community_cmd,
10400        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10401        SHOW_STR
10402        IPV6_STR
10403        MBGP_STR
10404        "Display routes matching the communities\n"
10405        "community number\n"
10406        "Do not send outside local AS (well-known community)\n"
10407        "Do not advertise to any peer (well-known community)\n"
10408        "Do not export to next AS (well-known community)\n")
10409 {
10410   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10411 }
10412 
10413 /* old command */
10414 ALIAS (show_ipv6_mbgp_community,
10415        show_ipv6_mbgp_community2_cmd,
10416        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10417        SHOW_STR
10418        IPV6_STR
10419        MBGP_STR
10420        "Display routes matching the communities\n"
10421        "community number\n"
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 number\n"
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 
10430 /* old command */
10431 ALIAS (show_ipv6_mbgp_community,
10432        show_ipv6_mbgp_community3_cmd,
10433        "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)",
10434        SHOW_STR
10435        IPV6_STR
10436        MBGP_STR
10437        "Display routes matching the communities\n"
10438        "community number\n"
10439        "Do not send outside local AS (well-known community)\n"
10440        "Do not advertise to any peer (well-known community)\n"
10441        "Do not export to next AS (well-known community)\n"
10442        "community number\n"
10443        "Do not send outside local AS (well-known community)\n"
10444        "Do not advertise to any peer (well-known community)\n"
10445        "Do not export to next AS (well-known community)\n"
10446        "community number\n"
10447        "Do not send outside local AS (well-known community)\n"
10448        "Do not advertise to any peer (well-known community)\n"
10449        "Do not export to next AS (well-known community)\n")
10450 
10451 /* old command */
10452 ALIAS (show_ipv6_mbgp_community,
10453        show_ipv6_mbgp_community4_cmd,
10454        "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)",
10455        SHOW_STR
10456        IPV6_STR
10457        MBGP_STR
10458        "Display routes matching the communities\n"
10459        "community number\n"
10460        "Do not send outside local AS (well-known community)\n"
10461        "Do not advertise to any peer (well-known community)\n"
10462        "Do not export to next AS (well-known community)\n"
10463        "community number\n"
10464        "Do not send outside local AS (well-known community)\n"
10465        "Do not advertise to any peer (well-known community)\n"
10466        "Do not export to next AS (well-known community)\n"
10467        "community number\n"
10468        "Do not send outside local AS (well-known community)\n"
10469        "Do not advertise to any peer (well-known community)\n"
10470        "Do not export to next AS (well-known community)\n"
10471        "community number\n"
10472        "Do not send outside local AS (well-known community)\n"
10473        "Do not advertise to any peer (well-known community)\n"
10474        "Do not export to next AS (well-known community)\n")
10475 
10476 /* old command */
10477 DEFUN (show_ipv6_mbgp_community_exact,
10478        show_ipv6_mbgp_community_exact_cmd,
10479        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10480        SHOW_STR
10481        IPV6_STR
10482        MBGP_STR
10483        "Display routes matching the communities\n"
10484        "community number\n"
10485        "Do not send outside local AS (well-known community)\n"
10486        "Do not advertise to any peer (well-known community)\n"
10487        "Do not export to next AS (well-known community)\n"
10488        "Exact match of the communities")
10489 {
10490   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10491 }
10492 
10493 /* old command */
10494 ALIAS (show_ipv6_mbgp_community_exact,
10495        show_ipv6_mbgp_community2_exact_cmd,
10496        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10497        SHOW_STR
10498        IPV6_STR
10499        MBGP_STR
10500        "Display routes matching the communities\n"
10501        "community number\n"
10502        "Do not send outside local AS (well-known community)\n"
10503        "Do not advertise to any peer (well-known community)\n"
10504        "Do not export to next AS (well-known community)\n"
10505        "community number\n"
10506        "Do not send outside local AS (well-known community)\n"
10507        "Do not advertise to any peer (well-known community)\n"
10508        "Do not export to next AS (well-known community)\n"
10509        "Exact match of the communities")
10510 
10511 /* old command */
10512 ALIAS (show_ipv6_mbgp_community_exact,
10513        show_ipv6_mbgp_community3_exact_cmd,
10514        "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",
10515        SHOW_STR
10516        IPV6_STR
10517        MBGP_STR
10518        "Display routes matching the communities\n"
10519        "community number\n"
10520        "Do not send outside local AS (well-known community)\n"
10521        "Do not advertise to any peer (well-known community)\n"
10522        "Do not export to next AS (well-known community)\n"
10523        "community number\n"
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        "community number\n"
10528        "Do not send outside local AS (well-known community)\n"
10529        "Do not advertise to any peer (well-known community)\n"
10530        "Do not export to next AS (well-known community)\n"
10531        "Exact match of the communities")
10532 
10533 /* old command */
10534 ALIAS (show_ipv6_mbgp_community_exact,
10535        show_ipv6_mbgp_community4_exact_cmd,
10536        "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",
10537        SHOW_STR
10538        IPV6_STR
10539        MBGP_STR
10540        "Display routes matching the communities\n"
10541        "community number\n"
10542        "Do not send outside local AS (well-known community)\n"
10543        "Do not advertise to any peer (well-known community)\n"
10544        "Do not export to next AS (well-known community)\n"
10545        "community number\n"
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 number\n"
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        "community number\n"
10554        "Do not send outside local AS (well-known community)\n"
10555        "Do not advertise to any peer (well-known community)\n"
10556        "Do not export to next AS (well-known community)\n"
10557        "Exact match of the communities")
10558 
10559 DEFUN (show_bgp_ipv4_community,
10560        show_bgp_ipv4_community_cmd,
10561        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
10562        SHOW_STR
10563        BGP_STR
10564        IP_STR
10565        "Display routes matching the communities\n"
10566        "community number\n"
10567        "Do not send outside local AS (well-known community)\n"
10568        "Do not advertise to any peer (well-known community)\n"
10569        "Do not export to next AS (well-known community)\n")
10570 {
10571   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10572 }
10573 
10574 ALIAS (show_bgp_ipv4_community,
10575        show_bgp_ipv4_community2_cmd,
10576        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10577        SHOW_STR
10578        BGP_STR
10579        IP_STR
10580        "Display routes matching the communities\n"
10581        "community number\n"
10582        "Do not send outside local AS (well-known community)\n"
10583        "Do not advertise to any peer (well-known community)\n"
10584        "Do not export to next AS (well-known community)\n"
10585        "community number\n"
10586        "Do not send outside local AS (well-known community)\n"
10587        "Do not advertise to any peer (well-known community)\n"
10588        "Do not export to next AS (well-known community)\n")
10589 
10590 ALIAS (show_bgp_ipv4_community,
10591        show_bgp_ipv4_community3_cmd,
10592        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10593        SHOW_STR
10594        BGP_STR
10595        IP_STR
10596        "Display routes matching the communities\n"
10597        "community number\n"
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 number\n"
10602        "Do not send outside local AS (well-known community)\n"
10603        "Do not advertise to any peer (well-known community)\n"
10604        "Do not export to next AS (well-known community)\n"
10605        "community number\n"
10606        "Do not send outside local AS (well-known community)\n"
10607        "Do not advertise to any peer (well-known community)\n"
10608        "Do not export to next AS (well-known community)\n")
10609 
10610 ALIAS (show_bgp_ipv4_community,
10611        show_bgp_ipv4_community4_cmd,
10612        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10613        SHOW_STR
10614        BGP_STR
10615        IP_STR
10616        "Display routes matching the communities\n"
10617        "community number\n"
10618        "Do not send outside local AS (well-known community)\n"
10619        "Do not advertise to any peer (well-known community)\n"
10620        "Do not export to next AS (well-known community)\n"
10621        "community number\n"
10622        "Do not send outside local AS (well-known community)\n"
10623        "Do not advertise to any peer (well-known community)\n"
10624        "Do not export to next AS (well-known community)\n"
10625        "community number\n"
10626        "Do not send outside local AS (well-known community)\n"
10627        "Do not advertise to any peer (well-known community)\n"
10628        "Do not export to next AS (well-known community)\n"
10629        "community number\n"
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 DEFUN (show_bgp_ipv4_safi_community,
10635        show_bgp_ipv4_safi_community_cmd,
10636        "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10637        SHOW_STR
10638        BGP_STR
10639        "Address family\n"
10640        "Address Family modifier\n"
10641        "Address Family modifier\n"
10642        "Display routes matching the communities\n"
10643        "community number\n"
10644        "Do not send outside local AS (well-known community)\n"
10645        "Do not advertise to any peer (well-known community)\n"
10646        "Do not export to next AS (well-known community)\n")
10647 {
10648   if (strncmp (argv[0], "m", 1) == 0)
10649     return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
10650 
10651   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10652 }
10653 
10654 ALIAS (show_bgp_ipv4_safi_community,
10655        show_bgp_ipv4_safi_community2_cmd,
10656        "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10657        SHOW_STR
10658        BGP_STR
10659        "Address family\n"
10660        "Address Family modifier\n"
10661        "Address Family modifier\n"
10662        "Display routes matching the communities\n"
10663        "community number\n"
10664        "Do not send outside local AS (well-known community)\n"
10665        "Do not advertise to any peer (well-known community)\n"
10666        "Do not export to next AS (well-known community)\n"
10667        "community number\n"
10668        "Do not send outside local AS (well-known community)\n"
10669        "Do not advertise to any peer (well-known community)\n"
10670        "Do not export to next AS (well-known community)\n")
10671 
10672 ALIAS (show_bgp_ipv4_safi_community,
10673        show_bgp_ipv4_safi_community3_cmd,
10674        "show 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)",
10675        SHOW_STR
10676        BGP_STR
10677        "Address family\n"
10678        "Address Family modifier\n"
10679        "Address Family modifier\n"
10680        "Display routes matching the communities\n"
10681        "community number\n"
10682        "Do not send outside local AS (well-known community)\n"
10683        "Do not advertise to any peer (well-known community)\n"
10684        "Do not export to next AS (well-known community)\n"
10685        "community number\n"
10686        "Do not send outside local AS (well-known community)\n"
10687        "Do not advertise to any peer (well-known community)\n"
10688        "Do not export to next AS (well-known community)\n"
10689        "community number\n"
10690        "Do not send outside local AS (well-known community)\n"
10691        "Do not advertise to any peer (well-known community)\n"
10692        "Do not export to next AS (well-known community)\n")
10693 
10694 ALIAS (show_bgp_ipv4_safi_community,
10695        show_bgp_ipv4_safi_community4_cmd,
10696        "show 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)",
10697        SHOW_STR
10698        BGP_STR
10699        "Address family\n"
10700        "Address Family modifier\n"
10701        "Address Family modifier\n"
10702        "Display routes matching the communities\n"
10703        "community number\n"
10704        "Do not send outside local AS (well-known community)\n"
10705        "Do not advertise to any peer (well-known community)\n"
10706        "Do not export to next AS (well-known community)\n"
10707        "community number\n"
10708        "Do not send outside local AS (well-known community)\n"
10709        "Do not advertise to any peer (well-known community)\n"
10710        "Do not export to next AS (well-known community)\n"
10711        "community number\n"
10712        "Do not send outside local AS (well-known community)\n"
10713        "Do not advertise to any peer (well-known community)\n"
10714        "Do not export to next AS (well-known community)\n"
10715        "community number\n"
10716        "Do not send outside local AS (well-known community)\n"
10717        "Do not advertise to any peer (well-known community)\n"
10718        "Do not export to next AS (well-known community)\n")
10719 
10720 DEFUN (show_bgp_view_afi_safi_community_all,
10721        show_bgp_view_afi_safi_community_all_cmd,
10722        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
10723        SHOW_STR
10724        BGP_STR
10725        "BGP view\n"
10726        "View name\n"
10727        "Address family\n"
10728        "Address family\n"
10729        "Address Family modifier\n"
10730        "Address Family modifier\n"
10731        "Display routes matching the communities\n")
10732 {
10733   int afi;
10734   int safi;
10735   struct bgp *bgp;
10736 
10737   /* BGP structure lookup. */
10738   bgp = bgp_lookup_by_name (argv[0]);
10739   if (bgp == NULL)
10740     {
10741       vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10742       return CMD_WARNING;
10743     }
10744 
10745   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10746   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10747   return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10748 }
10749 
10750 DEFUN (show_bgp_view_afi_safi_community,
10751        show_bgp_view_afi_safi_community_cmd,
10752        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10753        SHOW_STR
10754        BGP_STR
10755        "BGP view\n"
10756        "View name\n"
10757        "Address family\n"
10758        "Address family\n"
10759        "Address family modifier\n"
10760        "Address family modifier\n"
10761        "Display routes matching the communities\n"
10762        "community number\n"
10763        "Do not send outside local AS (well-known community)\n"
10764        "Do not advertise to any peer (well-known community)\n"
10765        "Do not export to next AS (well-known community)\n")
10766 {
10767   int afi;
10768   int safi;
10769 
10770   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10771   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10772   return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
10773 }
10774 
10775 ALIAS (show_bgp_view_afi_safi_community,
10776        show_bgp_view_afi_safi_community2_cmd,
10777        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10778        SHOW_STR
10779        BGP_STR
10780        "BGP view\n"
10781        "View name\n"
10782        "Address family\n"
10783        "Address family\n"
10784        "Address family modifier\n"
10785        "Address family modifier\n"
10786        "Display routes matching the communities\n"
10787        "community number\n"
10788        "Do not send outside local AS (well-known community)\n"
10789        "Do not advertise to any peer (well-known community)\n"
10790        "Do not export to next AS (well-known community)\n"
10791        "community number\n"
10792        "Do not send outside local AS (well-known community)\n"
10793        "Do not advertise to any peer (well-known community)\n"
10794        "Do not export to next AS (well-known community)\n")
10795 
10796 ALIAS (show_bgp_view_afi_safi_community,
10797        show_bgp_view_afi_safi_community3_cmd,
10798        "show bgp view WORD (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)",
10799        SHOW_STR
10800        BGP_STR
10801        "BGP view\n"
10802        "View name\n"
10803        "Address family\n"
10804        "Address family\n"
10805        "Address family modifier\n"
10806        "Address family modifier\n"
10807        "Display routes matching the communities\n"
10808        "community number\n"
10809        "Do not send outside local AS (well-known community)\n"
10810        "Do not advertise to any peer (well-known community)\n"
10811        "Do not export to next AS (well-known community)\n"
10812        "community number\n"
10813        "Do not send outside local AS (well-known community)\n"
10814        "Do not advertise to any peer (well-known community)\n"
10815        "Do not export to next AS (well-known community)\n"
10816        "community number\n"
10817        "Do not send outside local AS (well-known community)\n"
10818        "Do not advertise to any peer (well-known community)\n"
10819        "Do not export to next AS (well-known community)\n")
10820 
10821 ALIAS (show_bgp_view_afi_safi_community,
10822        show_bgp_view_afi_safi_community4_cmd,
10823        "show bgp view WORD (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)",
10824        SHOW_STR
10825        BGP_STR
10826        "BGP view\n"
10827        "View name\n"
10828        "Address family\n"
10829        "Address family\n"
10830        "Address family modifier\n"
10831        "Address family modifier\n"
10832        "Display routes matching the communities\n"
10833        "community number\n"
10834        "Do not send outside local AS (well-known community)\n"
10835        "Do not advertise to any peer (well-known community)\n"
10836        "Do not export to next AS (well-known community)\n"
10837        "community number\n"
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        "community number\n"
10842        "Do not send outside local AS (well-known community)\n"
10843        "Do not advertise to any peer (well-known community)\n"
10844        "Do not export to next AS (well-known community)\n"
10845        "community number\n"
10846        "Do not send outside local AS (well-known community)\n"
10847        "Do not advertise to any peer (well-known community)\n"
10848        "Do not export to next AS (well-known community)\n")
10849 
10850 DEFUN (show_bgp_ipv4_community_exact,
10851        show_bgp_ipv4_community_exact_cmd,
10852        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10853        SHOW_STR
10854        BGP_STR
10855        IP_STR
10856        "Display routes matching the communities\n"
10857        "community number\n"
10858        "Do not send outside local AS (well-known community)\n"
10859        "Do not advertise to any peer (well-known community)\n"
10860        "Do not export to next AS (well-known community)\n"
10861        "Exact match of the communities")
10862 {
10863   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10864 }
10865 
10866 ALIAS (show_bgp_ipv4_community_exact,
10867        show_bgp_ipv4_community2_exact_cmd,
10868        "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10869        SHOW_STR
10870        BGP_STR
10871        IP_STR
10872        "Display routes matching the communities\n"
10873        "community number\n"
10874        "Do not send outside local AS (well-known community)\n"
10875        "Do not advertise to any peer (well-known community)\n"
10876        "Do not export to next AS (well-known community)\n"
10877        "community number\n"
10878        "Do not send outside local AS (well-known community)\n"
10879        "Do not advertise to any peer (well-known community)\n"
10880        "Do not export to next AS (well-known community)\n"
10881        "Exact match of the communities")
10882 
10883 ALIAS (show_bgp_ipv4_community_exact,
10884        show_bgp_ipv4_community3_exact_cmd,
10885        "show bgp ipv4 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",
10886        SHOW_STR
10887        BGP_STR
10888        IP_STR
10889        "Display routes matching the communities\n"
10890        "community number\n"
10891        "Do not send outside local AS (well-known community)\n"
10892        "Do not advertise to any peer (well-known community)\n"
10893        "Do not export to next AS (well-known community)\n"
10894        "community number\n"
10895        "Do not send outside local AS (well-known community)\n"
10896        "Do not advertise to any peer (well-known community)\n"
10897        "Do not export to next AS (well-known community)\n"
10898        "community number\n"
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        "Exact match of the communities")
10903 
10904 ALIAS (show_bgp_ipv4_community_exact,
10905        show_bgp_ipv4_community4_exact_cmd,
10906        "show bgp ipv4 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",
10907        SHOW_STR
10908        BGP_STR
10909        IP_STR
10910        "Display routes matching the communities\n"
10911        "community number\n"
10912        "Do not send outside local AS (well-known community)\n"
10913        "Do not advertise to any peer (well-known community)\n"
10914        "Do not export to next AS (well-known community)\n"
10915        "community number\n"
10916        "Do not send outside local AS (well-known community)\n"
10917        "Do not advertise to any peer (well-known community)\n"
10918        "Do not export to next AS (well-known community)\n"
10919        "community number\n"
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 number\n"
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        "Exact match of the communities")
10928 
10929 DEFUN (show_bgp_ipv4_safi_community4_exact,
10930        show_bgp_ipv4_safi_community_exact_cmd,
10931        "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10932        SHOW_STR
10933        BGP_STR
10934        "Address family\n"
10935        "Address Family modifier\n"
10936        "Address Family modifier\n"
10937        "Display routes matching the communities\n"
10938        "community number\n"
10939        "Do not send outside local AS (well-known community)\n"
10940        "Do not advertise to any peer (well-known community)\n"
10941        "Do not export to next AS (well-known community)\n"
10942        "Exact match of the communities")
10943 {
10944   if (strncmp (argv[0], "m", 1) == 0)
10945     return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
10946 
10947   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10948 }
10949 
10950 ALIAS (show_bgp_ipv4_safi_community4_exact,
10951        show_bgp_ipv4_safi_community2_exact_cmd,
10952        "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10953        SHOW_STR
10954        BGP_STR
10955        "Address family\n"
10956        "Address Family modifier\n"
10957        "Address Family modifier\n"
10958        "Display routes matching the communities\n"
10959        "community number\n"
10960        "Do not send outside local AS (well-known community)\n"
10961        "Do not advertise to any peer (well-known community)\n"
10962        "Do not export to next AS (well-known community)\n"
10963        "community number\n"
10964        "Do not send outside local AS (well-known community)\n"
10965        "Do not advertise to any peer (well-known community)\n"
10966        "Do not export to next AS (well-known community)\n"
10967        "Exact match of the communities")
10968 
10969 ALIAS (show_bgp_ipv4_safi_community4_exact,
10970        show_bgp_ipv4_safi_community3_exact_cmd,
10971        "show 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",
10972        SHOW_STR
10973        BGP_STR
10974        "Address family\n"
10975        "Address Family modifier\n"
10976        "Address Family modifier\n"
10977        "Display routes matching the communities\n"
10978        "community number\n"
10979        "Do not send outside local AS (well-known community)\n"
10980        "Do not advertise to any peer (well-known community)\n"
10981        "Do not export to next AS (well-known community)\n"
10982        "community number\n"
10983        "Do not send outside local AS (well-known community)\n"
10984        "Do not advertise to any peer (well-known community)\n"
10985        "Do not export to next AS (well-known community)\n"
10986        "community number\n"
10987        "Do not send outside local AS (well-known community)\n"
10988        "Do not advertise to any peer (well-known community)\n"
10989        "Do not export to next AS (well-known community)\n"
10990        "Exact match of the communities")
10991 
10992 ALIAS (show_bgp_ipv4_safi_community4_exact,
10993        show_bgp_ipv4_safi_community4_exact_cmd,
10994        "show 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",
10995        SHOW_STR
10996        BGP_STR
10997        "Address family\n"
10998        "Address Family modifier\n"
10999        "Address Family modifier\n"
11000        "Display routes matching the communities\n"
11001        "community number\n"
11002        "Do not send outside local AS (well-known community)\n"
11003        "Do not advertise to any peer (well-known community)\n"
11004        "Do not export to next AS (well-known community)\n"
11005        "community number\n"
11006        "Do not send outside local AS (well-known community)\n"
11007        "Do not advertise to any peer (well-known community)\n"
11008        "Do not export to next AS (well-known community)\n"
11009        "community number\n"
11010        "Do not send outside local AS (well-known community)\n"
11011        "Do not advertise to any peer (well-known community)\n"
11012        "Do not export to next AS (well-known community)\n"
11013        "community number\n"
11014        "Do not send outside local AS (well-known community)\n"
11015        "Do not advertise to any peer (well-known community)\n"
11016        "Do not export to next AS (well-known community)\n"
11017        "Exact match of the communities")
11018 
11019 DEFUN (show_bgp_ipv6_safi_community,
11020        show_bgp_ipv6_safi_community_cmd,
11021        "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
11022        SHOW_STR
11023        BGP_STR
11024        "Address family\n"
11025        "Address family modifier\n"
11026        "Address family modifier\n"
11027        "Address family modifier\n"
11028        "Address family modifier\n"
11029        "Display routes matching the communities\n"
11030        "community number\n"
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 {
11035   safi_t	safi;
11036 
11037   if (bgp_parse_safi(argv[0], &safi)) {
11038     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11039     return CMD_WARNING;
11040   }
11041   return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
11042 }
11043 
11044 ALIAS (show_bgp_ipv6_safi_community,
11045        show_bgp_ipv6_safi_community2_cmd,
11046        "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
11047        SHOW_STR
11048        BGP_STR
11049        "Address family\n"
11050        "Address family modifier\n"
11051        "Address family modifier\n"
11052        "Address family modifier\n"
11053        "Address family modifier\n"
11054        "Display routes matching the communities\n"
11055        "community number\n"
11056        "Do not send outside local AS (well-known community)\n"
11057        "Do not advertise to any peer (well-known community)\n"
11058        "Do not export to next AS (well-known community)\n"
11059        "community number\n"
11060        "Do not send outside local AS (well-known community)\n"
11061        "Do not advertise to any peer (well-known community)\n"
11062        "Do not export to next AS (well-known community)\n")
11063 
11064 ALIAS (show_bgp_ipv6_safi_community,
11065        show_bgp_ipv6_safi_community3_cmd,
11066        "show bgp ipv6 (encap|multicast|unicast|vpn) 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)",
11067        SHOW_STR
11068        BGP_STR
11069        "Address family\n"
11070        "Address family modifier\n"
11071        "Address family modifier\n"
11072        "Address family modifier\n"
11073        "Address family modifier\n"
11074        "Display routes matching the communities\n"
11075        "community number\n"
11076        "Do not send outside local AS (well-known community)\n"
11077        "Do not advertise to any peer (well-known community)\n"
11078        "Do not export to next AS (well-known community)\n"
11079        "community number\n"
11080        "Do not send outside local AS (well-known community)\n"
11081        "Do not advertise to any peer (well-known community)\n"
11082        "Do not export to next AS (well-known community)\n"
11083        "community number\n"
11084        "Do not send outside local AS (well-known community)\n"
11085        "Do not advertise to any peer (well-known community)\n"
11086        "Do not export to next AS (well-known community)\n")
11087 
11088 ALIAS (show_bgp_ipv6_safi_community,
11089        show_bgp_ipv6_safi_community4_cmd,
11090        "show bgp ipv6 (encap|multicast|unicast|vpn) 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)",
11091        SHOW_STR
11092        BGP_STR
11093        "Address family\n"
11094        "Address family modifier\n"
11095        "Address family modifier\n"
11096        "Address family modifier\n"
11097        "Address family modifier\n"
11098        "Display routes matching the communities\n"
11099        "community number\n"
11100        "Do not send outside local AS (well-known community)\n"
11101        "Do not advertise to any peer (well-known community)\n"
11102        "Do not export to next AS (well-known community)\n"
11103        "community number\n"
11104        "Do not send outside local AS (well-known community)\n"
11105        "Do not advertise to any peer (well-known community)\n"
11106        "Do not export to next AS (well-known community)\n"
11107        "community number\n"
11108        "Do not send outside local AS (well-known community)\n"
11109        "Do not advertise to any peer (well-known community)\n"
11110        "Do not export to next AS (well-known community)\n"
11111        "community number\n"
11112        "Do not send outside local AS (well-known community)\n"
11113        "Do not advertise to any peer (well-known community)\n"
11114        "Do not export to next AS (well-known community)\n")
11115 
11116 
11117 DEFUN (show_bgp_ipv6_safi_community_exact,
11118        show_bgp_ipv6_safi_community_exact_cmd,
11119        "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11120        SHOW_STR
11121        BGP_STR
11122        "Address family\n"
11123        "Address family modifier\n"
11124        "Address family modifier\n"
11125        "Address family modifier\n"
11126        "Address family modifier\n"
11127        "Display routes matching the communities\n"
11128        "community number\n"
11129        "Do not send outside local AS (well-known community)\n"
11130        "Do not advertise to any peer (well-known community)\n"
11131        "Do not export to next AS (well-known community)\n"
11132        "Exact match of the communities")
11133 {
11134   safi_t	safi;
11135 
11136   if (bgp_parse_safi(argv[0], &safi)) {
11137     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11138     return CMD_WARNING;
11139   }
11140   return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
11141 }
11142 
11143 
11144 ALIAS (show_bgp_community_exact,
11145        show_bgp_ipv6_safi_community2_exact_cmd,
11146        "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11147        SHOW_STR
11148        BGP_STR
11149        "Address family\n"
11150        "Address family modifier\n"
11151        "Address family modifier\n"
11152        "Address family modifier\n"
11153        "Address family modifier\n"
11154        "Display routes matching the communities\n"
11155        "community number\n"
11156        "Do not send outside local AS (well-known community)\n"
11157        "Do not advertise to any peer (well-known community)\n"
11158        "Do not export to next AS (well-known community)\n"
11159        "community number\n"
11160        "Do not send outside local AS (well-known community)\n"
11161        "Do not advertise to any peer (well-known community)\n"
11162        "Do not export to next AS (well-known community)\n"
11163        "Exact match of the communities")
11164 
11165 ALIAS (show_bgp_community_exact,
11166        show_bgp_ipv6_safi_community3_exact_cmd,
11167        "show bgp ipv6 (encap|multicast|unicast|vpn) 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",
11168        SHOW_STR
11169        BGP_STR
11170        "Address family\n"
11171        "Address family modifier\n"
11172        "Address family modifier\n"
11173        "Address family modifier\n"
11174        "Address family modifier\n"
11175        "Display routes matching the communities\n"
11176        "community number\n"
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        "community number\n"
11181        "Do not send outside local AS (well-known community)\n"
11182        "Do not advertise to any peer (well-known community)\n"
11183        "Do not export to next AS (well-known community)\n"
11184        "community number\n"
11185        "Do not send outside local AS (well-known community)\n"
11186        "Do not advertise to any peer (well-known community)\n"
11187        "Do not export to next AS (well-known community)\n"
11188        "Exact match of the communities")
11189 
11190 ALIAS (show_bgp_community_exact,
11191        show_bgp_ipv6_safi_community4_exact_cmd,
11192        "show bgp ipv6 (encap|multicast|unicast|vpn) 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",
11193        SHOW_STR
11194        BGP_STR
11195        "Address family\n"
11196        "Address family modifier\n"
11197        "Address family modifier\n"
11198        "Address family modifier\n"
11199        "Address family modifier\n"
11200        "Display routes matching the communities\n"
11201        "community number\n"
11202        "Do not send outside local AS (well-known community)\n"
11203        "Do not advertise to any peer (well-known community)\n"
11204        "Do not export to next AS (well-known community)\n"
11205        "community number\n"
11206        "Do not send outside local AS (well-known community)\n"
11207        "Do not advertise to any peer (well-known community)\n"
11208        "Do not export to next AS (well-known community)\n"
11209        "community number\n"
11210        "Do not send outside local AS (well-known community)\n"
11211        "Do not advertise to any peer (well-known community)\n"
11212        "Do not export to next AS (well-known community)\n"
11213        "community number\n"
11214        "Do not send outside local AS (well-known community)\n"
11215        "Do not advertise to any peer (well-known community)\n"
11216        "Do not export to next AS (well-known community)\n"
11217        "Exact match of the communities")
11218 
11219 static int
bgp_show_community_list(struct vty * vty,const char * com,int exact,afi_t afi,safi_t safi)11220 bgp_show_community_list (struct vty *vty, const char *com, int exact,
11221 			 afi_t afi, safi_t safi)
11222 {
11223   struct community_list *list;
11224 
11225   list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11226   if (list == NULL)
11227     {
11228       vty_out (vty, "%% %s is not a valid community-list name%s", com,
11229 	       VTY_NEWLINE);
11230       return CMD_WARNING;
11231     }
11232 
11233   return bgp_show (vty, NULL, afi, safi,
11234                    (exact ? bgp_show_type_community_list_exact :
11235 		            bgp_show_type_community_list), list);
11236 }
11237 
11238 DEFUN (show_ip_bgp_community_list,
11239        show_ip_bgp_community_list_cmd,
11240        "show ip bgp community-list (<1-500>|WORD)",
11241        SHOW_STR
11242        IP_STR
11243        BGP_STR
11244        "Display routes matching the community-list\n"
11245        "community-list number\n"
11246        "community-list name\n")
11247 {
11248   return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11249 }
11250 
11251 DEFUN (show_ip_bgp_ipv4_community_list,
11252        show_ip_bgp_ipv4_community_list_cmd,
11253        "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11254        SHOW_STR
11255        IP_STR
11256        BGP_STR
11257        "Address family\n"
11258        "Address Family modifier\n"
11259        "Address Family modifier\n"
11260        "Display routes matching the community-list\n"
11261        "community-list number\n"
11262        "community-list name\n")
11263 {
11264   if (strncmp (argv[0], "m", 1) == 0)
11265     return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11266 
11267   return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11268 }
11269 
11270 DEFUN (show_ip_bgp_community_list_exact,
11271        show_ip_bgp_community_list_exact_cmd,
11272        "show ip bgp community-list (<1-500>|WORD) exact-match",
11273        SHOW_STR
11274        IP_STR
11275        BGP_STR
11276        "Display routes matching the community-list\n"
11277        "community-list number\n"
11278        "community-list name\n"
11279        "Exact match of the communities\n")
11280 {
11281   return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11282 }
11283 
11284 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11285        show_ip_bgp_ipv4_community_list_exact_cmd,
11286        "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11287        SHOW_STR
11288        IP_STR
11289        BGP_STR
11290        "Address family\n"
11291        "Address Family modifier\n"
11292        "Address Family modifier\n"
11293        "Display routes matching the community-list\n"
11294        "community-list number\n"
11295        "community-list name\n"
11296        "Exact match of the communities\n")
11297 {
11298   if (strncmp (argv[0], "m", 1) == 0)
11299     return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11300 
11301   return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11302 }
11303 
11304 DEFUN (show_bgp_community_list,
11305        show_bgp_community_list_cmd,
11306        "show bgp community-list (<1-500>|WORD)",
11307        SHOW_STR
11308        BGP_STR
11309        "Display routes matching the community-list\n"
11310        "community-list number\n"
11311        "community-list name\n")
11312 {
11313   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11314 }
11315 
11316 ALIAS (show_bgp_community_list,
11317        show_bgp_ipv6_community_list_cmd,
11318        "show bgp ipv6 community-list (<1-500>|WORD)",
11319        SHOW_STR
11320        BGP_STR
11321        "Address family\n"
11322        "Display routes matching the community-list\n"
11323        "community-list number\n"
11324        "community-list name\n")
11325 
11326 /* old command */
11327 DEFUN (show_ipv6_bgp_community_list,
11328        show_ipv6_bgp_community_list_cmd,
11329        "show ipv6 bgp community-list WORD",
11330        SHOW_STR
11331        IPV6_STR
11332        BGP_STR
11333        "Display routes matching the community-list\n"
11334        "community-list name\n")
11335 {
11336   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11337 }
11338 
11339 /* old command */
11340 DEFUN (show_ipv6_mbgp_community_list,
11341        show_ipv6_mbgp_community_list_cmd,
11342        "show ipv6 mbgp community-list WORD",
11343        SHOW_STR
11344        IPV6_STR
11345        MBGP_STR
11346        "Display routes matching the community-list\n"
11347        "community-list name\n")
11348 {
11349   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11350 }
11351 
11352 DEFUN (show_bgp_community_list_exact,
11353        show_bgp_community_list_exact_cmd,
11354        "show bgp community-list (<1-500>|WORD) exact-match",
11355        SHOW_STR
11356        BGP_STR
11357        "Display routes matching the community-list\n"
11358        "community-list number\n"
11359        "community-list name\n"
11360        "Exact match of the communities\n")
11361 {
11362   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11363 }
11364 
11365 ALIAS (show_bgp_community_list_exact,
11366        show_bgp_ipv6_community_list_exact_cmd,
11367        "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11368        SHOW_STR
11369        BGP_STR
11370        "Address family\n"
11371        "Display routes matching the community-list\n"
11372        "community-list number\n"
11373        "community-list name\n"
11374        "Exact match of the communities\n")
11375 
11376 /* old command */
11377 DEFUN (show_ipv6_bgp_community_list_exact,
11378        show_ipv6_bgp_community_list_exact_cmd,
11379        "show ipv6 bgp community-list WORD exact-match",
11380        SHOW_STR
11381        IPV6_STR
11382        BGP_STR
11383        "Display routes matching the community-list\n"
11384        "community-list name\n"
11385        "Exact match of the communities\n")
11386 {
11387   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11388 }
11389 
11390 /* old command */
11391 DEFUN (show_ipv6_mbgp_community_list_exact,
11392        show_ipv6_mbgp_community_list_exact_cmd,
11393        "show ipv6 mbgp community-list WORD exact-match",
11394        SHOW_STR
11395        IPV6_STR
11396        MBGP_STR
11397        "Display routes matching the community-list\n"
11398        "community-list name\n"
11399        "Exact match of the communities\n")
11400 {
11401   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11402 }
11403 
11404 DEFUN (show_bgp_ipv4_community_list,
11405        show_bgp_ipv4_community_list_cmd,
11406        "show bgp ipv4 community-list (<1-500>|WORD)",
11407        SHOW_STR
11408        BGP_STR
11409        IP_STR
11410        "Display routes matching the community-list\n"
11411        "community-list number\n"
11412        "community-list name\n")
11413 {
11414   return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11415 }
11416 
11417 DEFUN (show_bgp_ipv4_safi_community_list,
11418        show_bgp_ipv4_safi_community_list_cmd,
11419        "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11420        SHOW_STR
11421        BGP_STR
11422        "Address family\n"
11423        "Address Family modifier\n"
11424        "Address Family modifier\n"
11425        "Display routes matching the community-list\n"
11426        "community-list number\n"
11427        "community-list name\n")
11428 {
11429   if (strncmp (argv[0], "m", 1) == 0)
11430     return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11431 
11432   return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11433 }
11434 
11435 DEFUN (show_bgp_ipv4_community_list_exact,
11436        show_bgp_ipv4_community_list_exact_cmd,
11437        "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
11438        SHOW_STR
11439        BGP_STR
11440        IP_STR
11441        "Display routes matching the community-list\n"
11442        "community-list number\n"
11443        "community-list name\n"
11444        "Exact match of the communities\n")
11445 {
11446   return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11447 }
11448 
11449 DEFUN (show_bgp_ipv4_safi_community_list_exact,
11450        show_bgp_ipv4_safi_community_list_exact_cmd,
11451        "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11452        SHOW_STR
11453        BGP_STR
11454        "Address family\n"
11455        "Address Family modifier\n"
11456        "Address Family modifier\n"
11457        "Display routes matching the community-list\n"
11458        "community-list number\n"
11459        "community-list name\n"
11460        "Exact match of the communities\n")
11461 {
11462   if (strncmp (argv[0], "m", 1) == 0)
11463     return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11464 
11465   return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11466 }
11467 
11468 DEFUN (show_bgp_ipv6_safi_community_list,
11469        show_bgp_ipv6_safi_community_list_cmd,
11470        "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
11471        SHOW_STR
11472        BGP_STR
11473        "Address family\n"
11474        "Address family modifier\n"
11475        "Address family modifier\n"
11476        "Address family modifier\n"
11477        "Address family modifier\n"
11478        "Display routes matching the community-list\n"
11479        "community-list number\n"
11480        "community-list name\n")
11481 {
11482   safi_t	safi;
11483 
11484   if (bgp_parse_safi(argv[0], &safi)) {
11485     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11486     return CMD_WARNING;
11487   }
11488   return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
11489 }
11490 
11491 DEFUN (show_bgp_ipv6_safi_community_list_exact,
11492        show_bgp_ipv6_safi_community_list_exact_cmd,
11493        "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
11494        SHOW_STR
11495        BGP_STR
11496        "Address family\n"
11497        "Address family modifier\n"
11498        "Address family modifier\n"
11499        "Address family modifier\n"
11500        "Address family modifier\n"
11501        "Display routes matching the community-list\n"
11502        "community-list number\n"
11503        "community-list name\n"
11504        "Exact match of the communities\n")
11505 {
11506   safi_t	safi;
11507 
11508   if (bgp_parse_safi(argv[0], &safi)) {
11509     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11510     return CMD_WARNING;
11511   }
11512   return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
11513 }
11514 
11515 /*
11516  * Large Community show commands.
11517  */
11518 
11519 DEFUN (show_bgp_afi_lcommunity_all,
11520        show_bgp_afi_lcommunity_all_cmd,
11521        "show bgp (ipv4|ipv6) large-community",
11522        SHOW_STR
11523        BGP_STR
11524        "Address family\n"
11525        "Address family\n"
11526        "Display routes matching the large-communities\n")
11527 {
11528   afi_t		afi;
11529   safi_t	safi = SAFI_UNICAST;
11530 
11531   if (bgp_parse_afi(argv[0], &afi)) {
11532     vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
11533     return CMD_WARNING;
11534   }
11535   return bgp_show (vty, NULL, afi, safi, bgp_show_type_lcommunity_all, NULL);
11536 }
11537 
11538 static int
bgp_show_lcommunity(struct vty * vty,const char * view_name,int argc,const char ** argv,afi_t afi,safi_t safi)11539 bgp_show_lcommunity (struct vty *vty, const char *view_name, int argc,
11540 		     const char **argv, afi_t afi, safi_t safi)
11541 {
11542   struct lcommunity *lcom;
11543   struct buffer *b;
11544   struct bgp *bgp;
11545   int i;
11546   char *str;
11547   int first = 0;
11548 
11549   /* BGP structure lookup */
11550   if (view_name)
11551     {
11552       bgp = bgp_lookup_by_name (view_name);
11553       if (bgp == NULL)
11554 	{
11555 	  vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11556 	  return CMD_WARNING;
11557 	}
11558     }
11559   else
11560     {
11561       bgp = bgp_get_default ();
11562       if (bgp == NULL)
11563 	{
11564 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11565 	  return CMD_WARNING;
11566 	}
11567     }
11568 
11569   b = buffer_new (1024);
11570   for (i = 0; i < argc; i++)
11571     {
11572       if (first)
11573         buffer_putc (b, ' ');
11574       else
11575 	{
11576 	  if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
11577 	    continue;
11578 	  first = 1;
11579 	}
11580 
11581       buffer_putstr (b, argv[i]);
11582     }
11583   buffer_putc (b, '\0');
11584 
11585   str = buffer_getstr (b);
11586   buffer_free (b);
11587 
11588   lcom = lcommunity_str2com (str);
11589   XFREE (MTYPE_TMP, str);
11590   if (! lcom)
11591     {
11592       vty_out (vty, "%% Large-community malformed: %s", VTY_NEWLINE);
11593       return CMD_WARNING;
11594     }
11595 
11596   return bgp_show (vty, bgp, afi, safi, bgp_show_type_lcommunity, lcom);
11597 }
11598 
11599 DEFUN (show_ip_bgp_lcommunity,
11600        show_ip_bgp_lcommunity_cmd,
11601        "show ip bgp large-community (AA:BB:CC)",
11602        SHOW_STR
11603        IP_STR
11604        BGP_STR
11605        "Display routes matching the large-communities\n"
11606        "large-community number\n")
11607 {
11608   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_UNICAST);
11609 }
11610 
11611 ALIAS (show_ip_bgp_lcommunity,
11612        show_ip_bgp_lcommunity2_cmd,
11613        "show ip bgp large-community (AA:BB:CC) (AA:BB:CC)",
11614        SHOW_STR
11615        IP_STR
11616        BGP_STR
11617        "Display routes matching the large-communities\n"
11618        "large-community number\n"
11619        "large-community number\n")
11620 
11621 ALIAS (show_ip_bgp_lcommunity,
11622        show_ip_bgp_lcommunity3_cmd,
11623        "show ip bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11624        SHOW_STR
11625        IP_STR
11626        BGP_STR
11627        "Display routes matching the large-communities\n"
11628        "largecommunity number\n"
11629        "largecommunity number\n"
11630        "largecommunity number\n")
11631 
11632 ALIAS (show_ip_bgp_lcommunity,
11633        show_ip_bgp_lcommunity4_cmd,
11634        "show ip bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11635        SHOW_STR
11636        IP_STR
11637        BGP_STR
11638        "Display routes matching the large-communities\n"
11639        "large-community number\n"
11640        "large-community number\n"
11641        "large-community number\n"
11642        "large-community number\n")
11643 
11644 DEFUN (show_ip_bgp_ipv4_lcommunity,
11645        show_ip_bgp_ipv4_lcommunity_cmd,
11646        "show ip bgp ipv4 (unicast|multicast) large-community (AA:BB:CC)",
11647        SHOW_STR
11648        IP_STR
11649        BGP_STR
11650        "Address family\n"
11651        "Address Family modifier\n"
11652        "Address Family modifier\n"
11653        "Display routes matching the large-communities\n"
11654        "large-community number\n")
11655 {
11656   if (strncmp (argv[0], "m", 1) == 0)
11657     return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_MULTICAST);
11658 
11659   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_UNICAST);
11660 }
11661 
11662 ALIAS (show_ip_bgp_ipv4_lcommunity,
11663        show_ip_bgp_ipv4_lcommunity2_cmd,
11664        "show ip bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC)",
11665        SHOW_STR
11666        IP_STR
11667        BGP_STR
11668        "Address family\n"
11669        "Address Family modifier\n"
11670        "Address Family modifier\n"
11671        "Display routes matching the large-communities\n"
11672        "large-community number\n"
11673        "large-community number\n")
11674 
11675 ALIAS (show_ip_bgp_ipv4_lcommunity,
11676        show_ip_bgp_ipv4_lcommunity3_cmd,
11677        "show ip bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11678        SHOW_STR
11679        IP_STR
11680        BGP_STR
11681        "Address family\n"
11682        "Address Family modifier\n"
11683        "Address Family modifier\n"
11684        "Display routes matching the large-communities\n"
11685        "large-community number\n"
11686        "large-community number\n"
11687        "large-community number\n")
11688 
11689 ALIAS (show_ip_bgp_ipv4_lcommunity,
11690        show_ip_bgp_ipv4_lcommunity4_cmd,
11691        "show ip bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11692        SHOW_STR
11693        IP_STR
11694        BGP_STR
11695        "Address family\n"
11696        "Address Family modifier\n"
11697        "Address Family modifier\n"
11698        "Display routes matching the large-communities\n"
11699        "large-community number\n"
11700        "large-community number\n"
11701        "large-community number\n"
11702        "large-community number\n")
11703 
11704 DEFUN (show_bgp_lcommunity,
11705        show_bgp_lcommunity_cmd,
11706        "show bgp large-community (AA:BB:CC)",
11707        SHOW_STR
11708        BGP_STR
11709        "Display routes matching the large-communities\n"
11710        "large-community number\n")
11711 {
11712   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP6, SAFI_UNICAST);
11713 }
11714 
11715 ALIAS (show_bgp_lcommunity,
11716        show_bgp_ipv6_lcommunity_cmd,
11717        "show bgp ipv6 large-community (AA:BB:CC)",
11718        SHOW_STR
11719        BGP_STR
11720        "Address family\n"
11721        "Display routes matching the large-communities\n"
11722        "large-community number\n")
11723 
11724 ALIAS (show_bgp_lcommunity,
11725        show_bgp_lcommunity2_cmd,
11726        "show bgp large-community (AA:BB:CC) (AA:BB:CC)",
11727        SHOW_STR
11728        BGP_STR
11729        "Display routes matching the large-communities\n"
11730        "large-community number\n"
11731        "large-community number\n")
11732 
11733 ALIAS (show_bgp_lcommunity,
11734        show_bgp_ipv6_lcommunity2_cmd,
11735        "show bgp ipv6 large-community (AA:BB:CC) (AA:BB:CC)",
11736        SHOW_STR
11737        BGP_STR
11738        "Address family\n"
11739        "Display routes matching the large-communities\n"
11740        "large-community number\n"
11741        "large-community number\n")
11742 
11743 ALIAS (show_bgp_lcommunity,
11744        show_bgp_lcommunity3_cmd,
11745        "show bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11746        SHOW_STR
11747        BGP_STR
11748        "Display routes matching the large-communities\n"
11749        "large-community number\n"
11750        "large-community number\n"
11751        "large-community number\n")
11752 
11753 ALIAS (show_bgp_lcommunity,
11754        show_bgp_ipv6_lcommunity3_cmd,
11755        "show bgp ipv6 large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11756        SHOW_STR
11757        BGP_STR
11758        "Address family\n"
11759        "Display routes matching the large-communities\n"
11760        "large-community number\n"
11761        "large-community number\n"
11762        "large-community number\n")
11763 
11764 ALIAS (show_bgp_lcommunity,
11765        show_bgp_lcommunity4_cmd,
11766        "show bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11767        SHOW_STR
11768        BGP_STR
11769        "Display routes matching the large-communities\n"
11770        "large-community number\n"
11771        "large-community number\n"
11772        "large-community number\n"
11773        "large-community number\n")
11774 
11775 ALIAS (show_bgp_lcommunity,
11776        show_bgp_ipv6_lcommunity4_cmd,
11777        "show bgp ipv6 large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11778        SHOW_STR
11779        BGP_STR
11780        "Address family\n"
11781        "Display routes matching the large-communities\n"
11782        "large-community number\n"
11783        "large-community number\n"
11784        "large-community number\n"
11785        "large-community number\n")
11786 
11787 /* old command */
11788 DEFUN (show_ipv6_bgp_lcommunity,
11789        show_ipv6_bgp_lcommunity_cmd,
11790        "show ipv6 bgp large-community (AA:BB:CC)",
11791        SHOW_STR
11792        IPV6_STR
11793        BGP_STR
11794        "Display routes matching the large-communities\n"
11795        "large-community number\n")
11796 {
11797   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP6, SAFI_UNICAST);
11798 }
11799 
11800 /* old command */
11801 ALIAS (show_ipv6_bgp_lcommunity,
11802        show_ipv6_bgp_lcommunity2_cmd,
11803        "show ipv6 bgp large-community (AA:BB:CC) (AA:BB:CC)",
11804        SHOW_STR
11805        IPV6_STR
11806        BGP_STR
11807        "Display routes matching the large-communities\n"
11808        "large-community number\n"
11809        "large-community number\n")
11810 
11811 /* old command */
11812 ALIAS (show_ipv6_bgp_lcommunity,
11813        show_ipv6_bgp_lcommunity3_cmd,
11814        "show ipv6 bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11815        SHOW_STR
11816        IPV6_STR
11817        BGP_STR
11818        "Display routes matching the large-communities\n"
11819        "large-community number\n"
11820        "large-community number\n"
11821        "large-community number\n")
11822 
11823 /* old command */
11824 ALIAS (show_ipv6_bgp_lcommunity,
11825        show_ipv6_bgp_lcommunity4_cmd,
11826        "show ipv6 bgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11827        SHOW_STR
11828        IPV6_STR
11829        BGP_STR
11830        "Display routes matching the large-communities\n"
11831        "large-community number\n"
11832        "large-community number\n"
11833        "large-community number\n"
11834        "large-community number\n")
11835 
11836 /* old command */
11837 DEFUN (show_ipv6_mbgp_lcommunity,
11838        show_ipv6_mbgp_lcommunity_cmd,
11839        "show ipv6 mbgp large-community (AA:BB:CC)",
11840        SHOW_STR
11841        IPV6_STR
11842        MBGP_STR
11843        "Display routes matching the large-communities\n"
11844        "large-community number\n")
11845 {
11846   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP6, SAFI_MULTICAST);
11847 }
11848 
11849 /* old command */
11850 ALIAS (show_ipv6_mbgp_lcommunity,
11851        show_ipv6_mbgp_lcommunity2_cmd,
11852        "show ipv6 mbgp large-community (AA:BB:CC) (AA:BB:CC)",
11853        SHOW_STR
11854        IPV6_STR
11855        MBGP_STR
11856        "Display routes matching the large-communities\n"
11857        "large-community number\n"
11858        "large-community number\n")
11859 
11860 /* old command */
11861 ALIAS (show_ipv6_mbgp_lcommunity,
11862        show_ipv6_mbgp_lcommunity3_cmd,
11863        "show ipv6 mbgp large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11864        SHOW_STR
11865        IPV6_STR
11866        MBGP_STR
11867        "Display routes matching the large-communities\n"
11868        "large-community number\n"
11869        "large-community number\n"
11870        "large-community number\n")
11871 
11872 /* old command */
11873 ALIAS (show_ipv6_mbgp_lcommunity,
11874        show_ipv6_mbgp_lcommunity4_cmd,
11875        "show ipv6 mbgp laarge-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11876        SHOW_STR
11877        IPV6_STR
11878        MBGP_STR
11879        "Display routes matching the large-communities\n"
11880        "large-community number\n"
11881        "large-community number\n"
11882        "large-community number\n"
11883        "large-community number\n")
11884 
11885 DEFUN (show_bgp_ipv4_lcommunity,
11886        show_bgp_ipv4_lcommunity_cmd,
11887        "show bgp ipv4 large-community (AA:BB:CC)",
11888        SHOW_STR
11889        BGP_STR
11890        IP_STR
11891        "Display routes matching the large-communities\n"
11892        "large-community number\n")
11893 {
11894   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_UNICAST);
11895 }
11896 
11897 ALIAS (show_bgp_ipv4_lcommunity,
11898        show_bgp_ipv4_lcommunity2_cmd,
11899        "show bgp ipv4 large-community (AA:BB:CC) (AA:BB:CC)",
11900        SHOW_STR
11901        BGP_STR
11902        IP_STR
11903        "Display routes matching the large-communities\n"
11904        "large-community number\n"
11905        "large-community number\n")
11906 
11907 ALIAS (show_bgp_ipv4_lcommunity,
11908        show_bgp_ipv4_lcommunity3_cmd,
11909        "show bgp ipv4 large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11910        SHOW_STR
11911        BGP_STR
11912        IP_STR
11913        "Display routes matching the large-communities\n"
11914        "large-community number\n"
11915        "large-community number\n"
11916        "large-community number\n")
11917 
11918 ALIAS (show_bgp_ipv4_lcommunity,
11919        show_bgp_ipv4_lcommunity4_cmd,
11920        "show bgp ipv4 large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11921        SHOW_STR
11922        BGP_STR
11923        IP_STR
11924        "Display routes matching the large-communities\n"
11925        "large-community number\n"
11926        "large-community number\n"
11927        "large-community number\n"
11928        "large-community number\n")
11929 
11930 DEFUN (show_bgp_ipv4_safi_lcommunity,
11931        show_bgp_ipv4_safi_lcommunity_cmd,
11932        "show bgp ipv4 (unicast|multicast) large-community (AA:BB:CC)",
11933        SHOW_STR
11934        BGP_STR
11935        "Address family\n"
11936        "Address Family modifier\n"
11937        "Address Family modifier\n"
11938        "Display routes matching the large-communities\n"
11939        "large-community number\n")
11940 {
11941   if (strncmp (argv[0], "m", 1) == 0)
11942     return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_MULTICAST);
11943 
11944   return bgp_show_lcommunity (vty, NULL, argc, argv, AFI_IP, SAFI_UNICAST);
11945 }
11946 
11947 ALIAS (show_bgp_ipv4_safi_lcommunity,
11948        show_bgp_ipv4_safi_lcommunity2_cmd,
11949        "show bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC)",
11950        SHOW_STR
11951        BGP_STR
11952        "Address family\n"
11953        "Address Family modifier\n"
11954        "Address Family modifier\n"
11955        "Display routes matching the large-communities\n"
11956        "large-community number\n"
11957        "large-community number\n")
11958 
11959 ALIAS (show_bgp_ipv4_safi_lcommunity,
11960        show_bgp_ipv4_safi_lcommunity3_cmd,
11961        "show bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11962        SHOW_STR
11963        BGP_STR
11964        "Address family\n"
11965        "Address Family modifier\n"
11966        "Address Family modifier\n"
11967        "Display routes matching the large-communities\n"
11968        "large-community number\n"
11969        "large-community number\n"
11970        "large-community number\n")
11971 
11972 ALIAS (show_bgp_ipv4_safi_lcommunity,
11973        show_bgp_ipv4_safi_lcommunity4_cmd,
11974        "show bgp ipv4 (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
11975        SHOW_STR
11976        BGP_STR
11977        "Address family\n"
11978        "Address Family modifier\n"
11979        "Address Family modifier\n"
11980        "Display routes matching the large-communities\n"
11981        "large-community number\n"
11982        "large-community number\n"
11983        "large-community number\n"
11984        "large-community number\n")
11985 
11986 DEFUN (show_bgp_view_afi_safi_lcommunity_all,
11987        show_bgp_view_afi_safi_lcommunity_all_cmd,
11988        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) large-community",
11989        SHOW_STR
11990        BGP_STR
11991        "BGP view\n"
11992        "View name\n"
11993        "Address family\n"
11994        "Address family\n"
11995        "Address Family modifier\n"
11996        "Address Family modifier\n"
11997        "Display routes matching the large-communities\n")
11998 {
11999   int afi;
12000   int safi;
12001   struct bgp *bgp;
12002 
12003   /* BGP structure lookup. */
12004   bgp = bgp_lookup_by_name (argv[0]);
12005   if (bgp == NULL)
12006     {
12007       vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12008       return CMD_WARNING;
12009     }
12010 
12011   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12012   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12013   return bgp_show (vty, bgp, afi, safi, bgp_show_type_lcommunity_all, NULL);
12014 }
12015 
12016 DEFUN (show_bgp_view_afi_safi_lcommunity,
12017        show_bgp_view_afi_safi_lcommunity_cmd,
12018        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) large-community (AA:BB:CC)",
12019        SHOW_STR
12020        BGP_STR
12021        "BGP view\n"
12022        "View name\n"
12023        "Address family\n"
12024        "Address family\n"
12025        "Address family modifier\n"
12026        "Address family modifier\n"
12027        "Display routes matching the large-communities\n"
12028        "large-community number\n")
12029 {
12030   int afi;
12031   int safi;
12032 
12033   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12034   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12035   return bgp_show_lcommunity (vty, argv[0], argc-3, &argv[3], afi, safi);
12036 }
12037 
12038 ALIAS (show_bgp_view_afi_safi_lcommunity,
12039        show_bgp_view_afi_safi_lcommunity2_cmd,
12040        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC)",
12041        SHOW_STR
12042        BGP_STR
12043        "BGP view\n"
12044        "View name\n"
12045        "Address family\n"
12046        "Address family\n"
12047        "Address family modifier\n"
12048        "Address family modifier\n"
12049        "Display routes matching the large-communities\n"
12050        "large-community number\n"
12051        "large-community number\n")
12052 
12053 ALIAS (show_bgp_view_afi_safi_lcommunity,
12054        show_bgp_view_afi_safi_lcommunity3_cmd,
12055        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
12056        SHOW_STR
12057        BGP_STR
12058        "BGP view\n"
12059        "View name\n"
12060        "Address family\n"
12061        "Address family\n"
12062        "Address family modifier\n"
12063        "Address family modifier\n"
12064        "Display routes matching the large-communities\n"
12065        "large-community number\n"
12066        "large-community number\n"
12067        "large-community number\n")
12068 
12069 ALIAS (show_bgp_view_afi_safi_lcommunity,
12070        show_bgp_view_afi_safi_lcommunity4_cmd,
12071        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
12072        SHOW_STR
12073        BGP_STR
12074        "BGP view\n"
12075        "View name\n"
12076        "Address family\n"
12077        "Address family\n"
12078        "Address family modifier\n"
12079        "Address family modifier\n"
12080        "Display routes matching the large-communities\n"
12081        "large-community number\n"
12082        "large-community number\n"
12083        "large-community number\n"
12084        "large-community number\n")
12085 
12086 DEFUN (show_bgp_ipv6_safi_lcommunity,
12087        show_bgp_ipv6_safi_lcommunity_cmd,
12088        "show bgp ipv6 (encap|multicast|unicast|vpn) large-community AA:BB:CC",
12089        SHOW_STR
12090        BGP_STR
12091        "Address family\n"
12092        "Address family modifier\n"
12093        "Address family modifier\n"
12094        "Address family modifier\n"
12095        "Address family modifier\n"
12096        "Display routes matching the large-communities\n"
12097        "large-community number\n")
12098 {
12099   safi_t	safi;
12100 
12101   if (bgp_parse_safi(argv[0], &safi)) {
12102     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12103     return CMD_WARNING;
12104   }
12105   return bgp_show_lcommunity (vty, NULL, argc-1, argv+1, AFI_IP6, safi);
12106 }
12107 
12108 ALIAS (show_bgp_ipv6_safi_lcommunity,
12109        show_bgp_ipv6_safi_lcommunity2_cmd,
12110        "show bgp ipv6 (encap|multicast|unicast|vpn) large-community (AA:BB:CC) (AA:BB:CC)",
12111        SHOW_STR
12112        BGP_STR
12113        "Address family\n"
12114        "Address family modifier\n"
12115        "Address family modifier\n"
12116        "Address family modifier\n"
12117        "Address family modifier\n"
12118        "Display routes matching the large-communities\n"
12119        "large-community number\n"
12120        "large-community number\n")
12121 
12122 ALIAS (show_bgp_ipv6_safi_lcommunity,
12123        show_bgp_ipv6_safi_lcommunity3_cmd,
12124        "show bgp ipv6 (encap|multicast|unicast|vpn) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
12125        SHOW_STR
12126        BGP_STR
12127        "Address family\n"
12128        "Address family modifier\n"
12129        "Address family modifier\n"
12130        "Address family modifier\n"
12131        "Address family modifier\n"
12132        "Display routes matching the large-communities\n"
12133        "large-community number\n"
12134        "large-community number\n"
12135        "large-community number\n")
12136 
12137 ALIAS (show_bgp_ipv6_safi_lcommunity,
12138        show_bgp_ipv6_safi_lcommunity4_cmd,
12139        "show bgp ipv6 (encap|multicast|unicast|vpn) large-community (AA:BB:CC) (AA:BB:CC) (AA:BB:CC) (AA:BB:CC)",
12140        SHOW_STR
12141        BGP_STR
12142        "Address family\n"
12143        "Address family modifier\n"
12144        "Address family modifier\n"
12145        "Address family modifier\n"
12146        "Address family modifier\n"
12147        "Display routes matching the large-communities\n"
12148        "large-community number\n"
12149        "large-community number\n"
12150        "large-community number\n"
12151        "large-community number\n")
12152 
12153 static int
bgp_show_lcommunity_list(struct vty * vty,const char * lcom,afi_t afi,safi_t safi)12154 bgp_show_lcommunity_list (struct vty *vty, const char *lcom,
12155 			  afi_t afi, safi_t safi)
12156 {
12157   struct community_list *list;
12158 
12159   list = community_list_lookup (bgp_clist, lcom, LARGE_COMMUNITY_LIST_MASTER);
12160   if (list == NULL)
12161     {
12162       vty_out (vty, "%% %s is not a valid large-community-list name%s", lcom,
12163 	       VTY_NEWLINE);
12164       return CMD_WARNING;
12165     }
12166 
12167   return bgp_show (vty, NULL, afi, safi, bgp_show_type_lcommunity_list, list);
12168 }
12169 
12170 DEFUN (show_ip_bgp_lcommunity_list,
12171        show_ip_bgp_lcommunity_list_cmd,
12172        "show ip bgp large-community-list (<1-500>|WORD)",
12173        SHOW_STR
12174        IP_STR
12175        BGP_STR
12176        "Display routes matching the large-community-list\n"
12177        "large-community-list number\n"
12178        "large-community-list name\n")
12179 {
12180   return bgp_show_lcommunity_list (vty, argv[0], AFI_IP, SAFI_UNICAST);
12181 }
12182 
12183 DEFUN (show_ip_bgp_ipv4_lcommunity_list,
12184        show_ip_bgp_ipv4_lcommunity_list_cmd,
12185        "show ip bgp ipv4 (unicast|multicast) large-community-list (<1-500>|WORD)",
12186        SHOW_STR
12187        IP_STR
12188        BGP_STR
12189        "Address family\n"
12190        "Address Family modifier\n"
12191        "Address Family modifier\n"
12192        "Display routes matching the large-community-list\n"
12193        "large-community-list number\n"
12194        "large-community-list name\n")
12195 {
12196   if (strncmp (argv[0], "m", 1) == 0)
12197     return bgp_show_lcommunity_list (vty, argv[1], AFI_IP, SAFI_MULTICAST);
12198 
12199   return bgp_show_lcommunity_list (vty, argv[1], AFI_IP, SAFI_UNICAST);
12200 }
12201 
12202 DEFUN (show_bgp_lcommunity_list,
12203        show_bgp_lcommunity_list_cmd,
12204        "show bgp large-community-list (<1-500>|WORD)",
12205        SHOW_STR
12206        BGP_STR
12207        "Display routes matching the large-community-list\n"
12208        "large-community-list number\n"
12209        "large-community-list name\n")
12210 {
12211   return bgp_show_lcommunity_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
12212 }
12213 
12214 ALIAS (show_bgp_lcommunity_list,
12215        show_bgp_ipv6_lcommunity_list_cmd,
12216        "show bgp ipv6 large-community-list (<1-500>|WORD)",
12217        SHOW_STR
12218        BGP_STR
12219        "Address family\n"
12220        "Display routes matching the large-community-list\n"
12221        "large-community-list number\n"
12222        "large-community-list name\n")
12223 
12224 /* old command */
12225 DEFUN (show_ipv6_bgp_lcommunity_list,
12226        show_ipv6_bgp_lcommunity_list_cmd,
12227        "show ipv6 bgp large-community-list WORD",
12228        SHOW_STR
12229        IPV6_STR
12230        BGP_STR
12231        "Display routes matching the large-community-list\n"
12232        "large-community-list name\n")
12233 {
12234   return bgp_show_lcommunity_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
12235 }
12236 
12237 /* old command */
12238 DEFUN (show_ipv6_mbgp_lcommunity_list,
12239        show_ipv6_mbgp_lcommunity_list_cmd,
12240        "show ipv6 mbgp large-community-list WORD",
12241        SHOW_STR
12242        IPV6_STR
12243        MBGP_STR
12244        "Display routes matching the large-community-list\n"
12245        "large-community-list name\n")
12246 {
12247   return bgp_show_lcommunity_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
12248 }
12249 
12250 DEFUN (show_bgp_ipv4_lcommunity_list,
12251        show_bgp_ipv4_lcommunity_list_cmd,
12252        "show bgp ipv4 large-community-list (<1-500>|WORD)",
12253        SHOW_STR
12254        BGP_STR
12255        IP_STR
12256        "Display routes matching the large-community-list\n"
12257        "large-community-list number\n"
12258        "large-community-list name\n")
12259 {
12260   return bgp_show_lcommunity_list (vty, argv[0], AFI_IP, SAFI_UNICAST);
12261 }
12262 
12263 DEFUN (show_bgp_ipv4_safi_lcommunity_list,
12264        show_bgp_ipv4_safi_lcommunity_list_cmd,
12265        "show bgp ipv4 (unicast|multicast) large-community-list (<1-500>|WORD)",
12266        SHOW_STR
12267        BGP_STR
12268        "Address family\n"
12269        "Address Family modifier\n"
12270        "Address Family modifier\n"
12271        "Display routes matching the large-community-list\n"
12272        "large-community-list number\n"
12273        "large-community-list name\n")
12274 {
12275   if (strncmp (argv[0], "m", 1) == 0)
12276     return bgp_show_lcommunity_list (vty, argv[1], AFI_IP, SAFI_MULTICAST);
12277 
12278   return bgp_show_lcommunity_list (vty, argv[1], AFI_IP, SAFI_UNICAST);
12279 }
12280 
12281 DEFUN (show_bgp_ipv6_safi_lcommunity_list,
12282        show_bgp_ipv6_safi_lcommunity_list_cmd,
12283        "show bgp ipv6 (encap|multicast|unicast|vpn) large-community-list (<1-500>|WORD)",
12284        SHOW_STR
12285        BGP_STR
12286        "Address family\n"
12287        "Address family modifier\n"
12288        "Address family modifier\n"
12289        "Address family modifier\n"
12290        "Address family modifier\n"
12291        "Display routes matching the large-community-list\n"
12292        "large-community-list number\n"
12293        "large-community-list name\n")
12294 {
12295   safi_t	safi;
12296 
12297   if (bgp_parse_safi(argv[0], &safi)) {
12298     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12299     return CMD_WARNING;
12300   }
12301   return bgp_show_lcommunity_list (vty, argv[1], AFI_IP6, safi);
12302 }
12303 
12304 static int
bgp_show_prefix_longer(struct vty * vty,const char * prefix,afi_t afi,safi_t safi,enum bgp_show_type type)12305 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
12306 			safi_t safi, enum bgp_show_type type)
12307 {
12308   int ret;
12309   struct prefix *p;
12310 
12311   p = prefix_new();
12312 
12313   ret = str2prefix (prefix, p);
12314   if (! ret)
12315     {
12316       vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
12317       return CMD_WARNING;
12318     }
12319 
12320   ret = bgp_show (vty, NULL, afi, safi, type, p);
12321   prefix_free(p);
12322   return ret;
12323 }
12324 
12325 DEFUN (show_ip_bgp_prefix_longer,
12326        show_ip_bgp_prefix_longer_cmd,
12327        "show ip bgp A.B.C.D/M longer-prefixes",
12328        SHOW_STR
12329        IP_STR
12330        BGP_STR
12331        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12332        "Display route and more specific routes\n")
12333 {
12334   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
12335 				 bgp_show_type_prefix_longer);
12336 }
12337 
12338 DEFUN (show_ip_bgp_flap_prefix_longer,
12339        show_ip_bgp_flap_prefix_longer_cmd,
12340        "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
12341        SHOW_STR
12342        IP_STR
12343        BGP_STR
12344        "Display flap statistics of routes\n"
12345        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12346        "Display route and more specific routes\n")
12347 {
12348   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
12349 				 bgp_show_type_flap_prefix_longer);
12350 }
12351 
12352 ALIAS (show_ip_bgp_flap_prefix_longer,
12353        show_ip_bgp_damp_flap_prefix_longer_cmd,
12354        "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
12355        SHOW_STR
12356        IP_STR
12357        BGP_STR
12358        "Display detailed information about dampening\n"
12359        "Display flap statistics of routes\n"
12360        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12361        "Display route and more specific routes\n")
12362 
12363 DEFUN (show_ip_bgp_ipv4_prefix_longer,
12364        show_ip_bgp_ipv4_prefix_longer_cmd,
12365        "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
12366        SHOW_STR
12367        IP_STR
12368        BGP_STR
12369        "Address family\n"
12370        "Address Family modifier\n"
12371        "Address Family modifier\n"
12372        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12373        "Display route and more specific routes\n")
12374 {
12375   if (strncmp (argv[0], "m", 1) == 0)
12376     return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
12377 				   bgp_show_type_prefix_longer);
12378 
12379   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
12380 				 bgp_show_type_prefix_longer);
12381 }
12382 
12383 DEFUN (show_ip_bgp_flap_address,
12384        show_ip_bgp_flap_address_cmd,
12385        "show ip bgp flap-statistics A.B.C.D",
12386        SHOW_STR
12387        IP_STR
12388        BGP_STR
12389        "Display flap statistics of routes\n"
12390        "Network in the BGP routing table to display\n")
12391 {
12392   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
12393 				 bgp_show_type_flap_address);
12394 }
12395 
12396 ALIAS (show_ip_bgp_flap_address,
12397        show_ip_bgp_damp_flap_address_cmd,
12398        "show ip bgp dampening flap-statistics A.B.C.D",
12399        SHOW_STR
12400        IP_STR
12401        BGP_STR
12402        "Display detailed information about dampening\n"
12403        "Display flap statistics of routes\n"
12404        "Network in the BGP routing table to display\n")
12405 
12406 DEFUN (show_ip_bgp_flap_prefix,
12407        show_ip_bgp_flap_prefix_cmd,
12408        "show ip bgp flap-statistics A.B.C.D/M",
12409        SHOW_STR
12410        IP_STR
12411        BGP_STR
12412        "Display flap statistics of routes\n"
12413        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12414 {
12415   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
12416 				 bgp_show_type_flap_prefix);
12417 }
12418 
12419 ALIAS (show_ip_bgp_flap_prefix,
12420        show_ip_bgp_damp_flap_prefix_cmd,
12421        "show ip bgp dampening flap-statistics A.B.C.D/M",
12422        SHOW_STR
12423        IP_STR
12424        BGP_STR
12425        "Display detailed information about dampening\n"
12426        "Display flap statistics of routes\n"
12427        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12428 
12429 DEFUN (show_bgp_prefix_longer,
12430        show_bgp_prefix_longer_cmd,
12431        "show bgp X:X::X:X/M longer-prefixes",
12432        SHOW_STR
12433        BGP_STR
12434        "IPv6 prefix <network>/<length>\n"
12435        "Display route and more specific routes\n")
12436 {
12437   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
12438 				 bgp_show_type_prefix_longer);
12439 }
12440 
12441 /* old command */
12442 DEFUN (show_ipv6_bgp_prefix_longer,
12443        show_ipv6_bgp_prefix_longer_cmd,
12444        "show ipv6 bgp X:X::X:X/M longer-prefixes",
12445        SHOW_STR
12446        IPV6_STR
12447        BGP_STR
12448        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
12449        "Display route and more specific routes\n")
12450 {
12451   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
12452 				 bgp_show_type_prefix_longer);
12453 }
12454 
12455 /* old command */
12456 DEFUN (show_ipv6_mbgp_prefix_longer,
12457        show_ipv6_mbgp_prefix_longer_cmd,
12458        "show ipv6 mbgp X:X::X:X/M longer-prefixes",
12459        SHOW_STR
12460        IPV6_STR
12461        MBGP_STR
12462        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
12463        "Display route and more specific routes\n")
12464 {
12465   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
12466 				 bgp_show_type_prefix_longer);
12467 }
12468 
12469 DEFUN (show_bgp_ipv4_prefix_longer,
12470        show_bgp_ipv4_prefix_longer_cmd,
12471        "show bgp ipv4 A.B.C.D/M longer-prefixes",
12472        SHOW_STR
12473        BGP_STR
12474        IP_STR
12475        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12476        "Display route and more specific routes\n")
12477 {
12478   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
12479 				 bgp_show_type_prefix_longer);
12480 }
12481 
12482 DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
12483        show_bgp_ipv4_safi_flap_prefix_longer_cmd,
12484        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
12485        SHOW_STR
12486        BGP_STR
12487        "Address family\n"
12488        "Address Family modifier\n"
12489        "Address Family modifier\n"
12490        "Address Family modifier\n"
12491        "Address Family modifier\n"
12492        "Display flap statistics of routes\n"
12493        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12494        "Display route and more specific routes\n")
12495 {
12496   safi_t	safi;
12497 
12498   if (bgp_parse_safi(argv[0], &safi)) {
12499     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12500     return CMD_WARNING;
12501   }
12502   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
12503 				 bgp_show_type_flap_prefix_longer);
12504 }
12505 
12506 ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
12507        show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
12508        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
12509        SHOW_STR
12510        BGP_STR
12511        "Address family\n"
12512        "Address Family modifier\n"
12513        "Address Family modifier\n"
12514        "Address Family modifier\n"
12515        "Address Family modifier\n"
12516        "Display detailed information about dampening\n"
12517        "Display flap statistics of routes\n"
12518        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12519        "Display route and more specific routes\n")
12520 
12521 DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
12522        show_bgp_ipv6_safi_flap_prefix_longer_cmd,
12523        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
12524        SHOW_STR
12525        BGP_STR
12526        "Address family\n"
12527        "Address Family modifier\n"
12528        "Address Family modifier\n"
12529        "Address Family modifier\n"
12530        "Address Family modifier\n"
12531        "Display flap statistics of routes\n"
12532        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12533        "Display route and more specific routes\n")
12534 {
12535   safi_t	safi;
12536 
12537   if (bgp_parse_safi(argv[0], &safi)) {
12538     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12539     return CMD_WARNING;
12540   }
12541   return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
12542 				 bgp_show_type_flap_prefix_longer);
12543 }
12544 ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
12545        show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
12546        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
12547        SHOW_STR
12548        BGP_STR
12549        "Address family\n"
12550        "Address Family modifier\n"
12551        "Address Family modifier\n"
12552        "Address Family modifier\n"
12553        "Address Family modifier\n"
12554        "Display detailed information about dampening\n"
12555        "Display flap statistics of routes\n"
12556        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12557        "Display route and more specific routes\n")
12558 
12559 DEFUN (show_bgp_ipv4_safi_prefix_longer,
12560        show_bgp_ipv4_safi_prefix_longer_cmd,
12561        "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
12562        SHOW_STR
12563        BGP_STR
12564        "Address family\n"
12565        "Address Family modifier\n"
12566        "Address Family modifier\n"
12567        "Address Family modifier\n"
12568        "Address Family modifier\n"
12569        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12570        "Display route and more specific routes\n")
12571 {
12572   safi_t	safi;
12573 
12574   if (bgp_parse_safi(argv[0], &safi)) {
12575     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12576     return CMD_WARNING;
12577   }
12578 
12579   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
12580 				   bgp_show_type_prefix_longer);
12581 }
12582 
12583 DEFUN (show_bgp_ipv6_safi_prefix_longer,
12584        show_bgp_ipv6_safi_prefix_longer_cmd,
12585        "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
12586        SHOW_STR
12587        BGP_STR
12588        "Address family\n"
12589        "Address Family modifier\n"
12590        "Address Family modifier\n"
12591        "Address Family modifier\n"
12592        "Address Family modifier\n"
12593        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12594        "Display route and more specific routes\n")
12595 {
12596   safi_t	safi;
12597 
12598   if (bgp_parse_safi(argv[0], &safi)) {
12599     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12600     return CMD_WARNING;
12601   }
12602 
12603   return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
12604 				   bgp_show_type_prefix_longer);
12605 }
12606 
12607 DEFUN (show_bgp_ipv4_safi_flap_address,
12608        show_bgp_ipv4_safi_flap_address_cmd,
12609        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
12610        SHOW_STR
12611        BGP_STR
12612        "Address family\n"
12613        "Address Family modifier\n"
12614        "Address Family modifier\n"
12615        "Address Family modifier\n"
12616        "Address Family modifier\n"
12617        "Display flap statistics of routes\n"
12618        "Network in the BGP routing table to display\n")
12619 {
12620   safi_t	safi;
12621 
12622   if (bgp_parse_safi(argv[0], &safi)) {
12623     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12624     return CMD_WARNING;
12625   }
12626   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
12627 				 bgp_show_type_flap_address);
12628 }
12629 ALIAS (show_bgp_ipv4_safi_flap_address,
12630        show_bgp_ipv4_safi_damp_flap_address_cmd,
12631        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
12632        SHOW_STR
12633        BGP_STR
12634        "Address family\n"
12635        "Address Family modifier\n"
12636        "Address Family modifier\n"
12637        "Address Family modifier\n"
12638        "Address Family modifier\n"
12639        "Display detailed information about dampening\n"
12640        "Display flap statistics of routes\n"
12641        "Network in the BGP routing table to display\n")
12642 
12643 DEFUN (show_bgp_ipv6_flap_address,
12644        show_bgp_ipv6_flap_address_cmd,
12645        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
12646        SHOW_STR
12647        BGP_STR
12648        "Address family\n"
12649        "Address Family modifier\n"
12650        "Address Family modifier\n"
12651        "Address Family modifier\n"
12652        "Address Family modifier\n"
12653        "Display flap statistics of routes\n"
12654        "Network in the BGP routing table to display\n")
12655 {
12656   safi_t	safi;
12657 
12658   if (bgp_parse_safi(argv[0], &safi)) {
12659     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
12660     return CMD_WARNING;
12661   }
12662   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
12663 				 bgp_show_type_flap_address);
12664 }
12665 ALIAS (show_bgp_ipv6_flap_address,
12666        show_bgp_ipv6_damp_flap_address_cmd,
12667        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
12668        SHOW_STR
12669        BGP_STR
12670        "Address family\n"
12671        "Address Family modifier\n"
12672        "Address Family modifier\n"
12673        "Address Family modifier\n"
12674        "Address Family modifier\n"
12675        "Display detailed information about dampening\n"
12676        "Display flap statistics of routes\n"
12677        "Network in the BGP routing table to display\n")
12678 
12679 DEFUN (show_bgp_ipv4_safi_flap_prefix,
12680        show_bgp_ipv4_safi_flap_prefix_cmd,
12681        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
12682        SHOW_STR
12683        BGP_STR
12684        "Address family\n"
12685        "Address Family modifier\n"
12686        "Address Family modifier\n"
12687        "Address Family modifier\n"
12688        "Address Family modifier\n"
12689        "Display flap statistics of routes\n"
12690        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12691 {
12692   safi_t	safi;
12693 
12694   if (bgp_parse_safi(argv[0], &safi)) {
12695     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
12696     return CMD_WARNING;
12697   }
12698   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
12699 				 bgp_show_type_flap_prefix);
12700 }
12701 
12702 ALIAS (show_bgp_ipv4_safi_flap_prefix,
12703        show_bgp_ipv4_safi_damp_flap_prefix_cmd,
12704        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
12705        SHOW_STR
12706        BGP_STR
12707        "Address family\n"
12708        "Address Family modifier\n"
12709        "Address Family modifier\n"
12710        "Address Family modifier\n"
12711        "Address Family modifier\n"
12712        "Display detailed information about dampening\n"
12713        "Display flap statistics of routes\n"
12714        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12715 
12716 DEFUN (show_bgp_ipv6_safi_flap_prefix,
12717        show_bgp_ipv6_safi_flap_prefix_cmd,
12718        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
12719        SHOW_STR
12720        BGP_STR
12721        "Address family\n"
12722        "Address Family modifier\n"
12723        "Address Family modifier\n"
12724        "Address Family modifier\n"
12725        "Address Family modifier\n"
12726        "Display flap statistics of routes\n"
12727        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12728 {
12729   safi_t	safi;
12730 
12731   if (bgp_parse_safi(argv[0], &safi)) {
12732     vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
12733     return CMD_WARNING;
12734   }
12735   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
12736 				 bgp_show_type_flap_prefix);
12737 }
12738 
12739 ALIAS (show_bgp_ipv6_safi_flap_prefix,
12740        show_bgp_ipv6_safi_damp_flap_prefix_cmd,
12741        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
12742        SHOW_STR
12743        BGP_STR
12744        "Address family\n"
12745        "Address Family modifier\n"
12746        "Address Family modifier\n"
12747        "Address Family modifier\n"
12748        "Address Family modifier\n"
12749        "Display detailed information about dampening\n"
12750        "Display flap statistics of routes\n"
12751        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12752 
12753 DEFUN (show_bgp_ipv6_prefix_longer,
12754        show_bgp_ipv6_prefix_longer_cmd,
12755        "show bgp ipv6 X:X::X:X/M longer-prefixes",
12756        SHOW_STR
12757        BGP_STR
12758        "Address family\n"
12759        "IPv6 prefix <network>/<length>\n"
12760        "Display route and more specific routes\n")
12761 {
12762   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
12763 				 bgp_show_type_prefix_longer);
12764 }
12765 
12766 static struct peer *
peer_lookup_in_view(struct vty * vty,const char * view_name,const char * ip_str)12767 peer_lookup_in_view (struct vty *vty, const char *view_name,
12768                      const char *ip_str)
12769 {
12770   int ret;
12771   struct bgp *bgp;
12772   struct peer *peer;
12773   union sockunion su;
12774 
12775   /* BGP structure lookup. */
12776   if (view_name)
12777     {
12778       bgp = bgp_lookup_by_name (view_name);
12779       if (! bgp)
12780         {
12781           vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12782           return NULL;
12783         }
12784     }
12785   else
12786     {
12787       bgp = bgp_get_default ();
12788       if (! bgp)
12789         {
12790           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12791           return NULL;
12792         }
12793     }
12794 
12795   /* Get peer sockunion. */
12796   ret = str2sockunion (ip_str, &su);
12797   if (ret < 0)
12798     {
12799       vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
12800       return NULL;
12801     }
12802 
12803   /* Peer structure lookup. */
12804   peer = peer_lookup (bgp, &su);
12805   if (! peer)
12806     {
12807       vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
12808       return NULL;
12809     }
12810 
12811   return peer;
12812 }
12813 
12814 enum bgp_stats
12815 {
12816   BGP_STATS_MAXBITLEN = 0,
12817   BGP_STATS_RIB,
12818   BGP_STATS_PREFIXES,
12819   BGP_STATS_TOTPLEN,
12820   BGP_STATS_UNAGGREGATEABLE,
12821   BGP_STATS_MAX_AGGREGATEABLE,
12822   BGP_STATS_AGGREGATES,
12823   BGP_STATS_SPACE,
12824   BGP_STATS_ASPATH_COUNT,
12825   BGP_STATS_ASPATH_MAXHOPS,
12826   BGP_STATS_ASPATH_TOTHOPS,
12827   BGP_STATS_ASPATH_MAXSIZE,
12828   BGP_STATS_ASPATH_TOTSIZE,
12829   BGP_STATS_ASN_HIGHEST,
12830   BGP_STATS_MAX,
12831 };
12832 
12833 static const char *table_stats_strs[] =
12834 {
12835   [BGP_STATS_PREFIXES]            = "Total Prefixes",
12836   [BGP_STATS_TOTPLEN]             = "Average prefix length",
12837   [BGP_STATS_RIB]                 = "Total Advertisements",
12838   [BGP_STATS_UNAGGREGATEABLE]     = "Unaggregateable prefixes",
12839   [BGP_STATS_MAX_AGGREGATEABLE]   = "Maximum aggregateable prefixes",
12840   [BGP_STATS_AGGREGATES]          = "BGP Aggregate advertisements",
12841   [BGP_STATS_SPACE]               = "Address space advertised",
12842   [BGP_STATS_ASPATH_COUNT]        = "Advertisements with paths",
12843   [BGP_STATS_ASPATH_MAXHOPS]      = "Longest AS-Path (hops)",
12844   [BGP_STATS_ASPATH_MAXSIZE]      = "Largest AS-Path (bytes)",
12845   [BGP_STATS_ASPATH_TOTHOPS]      = "Average AS-Path length (hops)",
12846   [BGP_STATS_ASPATH_TOTSIZE]      = "Average AS-Path size (bytes)",
12847   [BGP_STATS_ASN_HIGHEST]         = "Highest public ASN",
12848   [BGP_STATS_MAX] = NULL,
12849 };
12850 
12851 struct bgp_table_stats
12852 {
12853   struct bgp_table *table;
12854   unsigned long long counts[BGP_STATS_MAX];
12855 };
12856 
12857 #if 0
12858 #define TALLY_SIGFIG 100000
12859 static unsigned long
12860 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
12861 {
12862   unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
12863   unsigned long res = (newtot * TALLY_SIGFIG) / count;
12864   unsigned long ret = newtot / count;
12865 
12866   if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
12867     return ret + 1;
12868   else
12869     return ret;
12870 }
12871 #endif
12872 
12873 static int
bgp_table_stats_walker(struct thread * t)12874 bgp_table_stats_walker (struct thread *t)
12875 {
12876   struct bgp_node *rn;
12877   struct bgp_node *top;
12878   struct bgp_table_stats *ts = THREAD_ARG (t);
12879   unsigned int space = 0;
12880 
12881   if (!(top = bgp_table_top (ts->table)))
12882     return 0;
12883 
12884   switch (top->p.family)
12885     {
12886       case AF_INET:
12887         space = IPV4_MAX_BITLEN;
12888         break;
12889       case AF_INET6:
12890         space = IPV6_MAX_BITLEN;
12891         break;
12892     }
12893 
12894   ts->counts[BGP_STATS_MAXBITLEN] = space;
12895 
12896   for (rn = top; rn; rn = bgp_route_next (rn))
12897     {
12898       struct bgp_info *ri;
12899       struct bgp_node *prn = bgp_node_parent_nolock (rn);
12900       unsigned int rinum = 0;
12901 
12902       if (rn == top)
12903         continue;
12904 
12905       if (!rn->info)
12906         continue;
12907 
12908       ts->counts[BGP_STATS_PREFIXES]++;
12909       ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
12910 
12911 #if 0
12912       ts->counts[BGP_STATS_AVGPLEN]
12913         = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
12914                       ts->counts[BGP_STATS_AVGPLEN],
12915                       rn->p.prefixlen);
12916 #endif
12917 
12918       /* check if the prefix is included by any other announcements */
12919       while (prn && !prn->info)
12920         prn = bgp_node_parent_nolock (prn);
12921 
12922       if (prn == NULL || prn == top)
12923         {
12924           ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
12925           /* announced address space */
12926           if (space)
12927             ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
12928         }
12929       else if (prn->info)
12930         ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
12931 
12932       for (ri = rn->info; ri; ri = ri->next)
12933         {
12934           rinum++;
12935           ts->counts[BGP_STATS_RIB]++;
12936 
12937           if (ri->attr &&
12938               (CHECK_FLAG (ri->attr->flag,
12939                            ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
12940             ts->counts[BGP_STATS_AGGREGATES]++;
12941 
12942           /* as-path stats */
12943           if (ri->attr && ri->attr->aspath)
12944             {
12945               unsigned int hops = aspath_count_hops (ri->attr->aspath);
12946               unsigned int size = aspath_size (ri->attr->aspath);
12947               as_t highest = aspath_highest (ri->attr->aspath);
12948 
12949               ts->counts[BGP_STATS_ASPATH_COUNT]++;
12950 
12951               if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
12952                 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
12953 
12954               if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
12955                 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
12956 
12957               ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
12958               ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
12959 #if 0
12960               ts->counts[BGP_STATS_ASPATH_AVGHOPS]
12961                 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
12962                               ts->counts[BGP_STATS_ASPATH_AVGHOPS],
12963                               hops);
12964               ts->counts[BGP_STATS_ASPATH_AVGSIZE]
12965                 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
12966                               ts->counts[BGP_STATS_ASPATH_AVGSIZE],
12967                               size);
12968 #endif
12969               if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
12970                 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
12971             }
12972         }
12973     }
12974   return 0;
12975 }
12976 
12977 static int
bgp_table_stats(struct vty * vty,struct bgp * bgp,afi_t afi,safi_t safi)12978 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
12979 {
12980   struct bgp_table_stats ts;
12981   unsigned int i;
12982 
12983   if (!bgp->rib[afi][safi])
12984     {
12985       vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
12986                afi, safi, VTY_NEWLINE);
12987       return CMD_WARNING;
12988     }
12989 
12990   memset (&ts, 0, sizeof (ts));
12991   ts.table = bgp->rib[afi][safi];
12992   thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12993 
12994   vty_out (vty, "BGP %s RIB statistics%s%s",
12995            afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12996 
12997   for (i = 0; i < BGP_STATS_MAX; i++)
12998     {
12999       if (!table_stats_strs[i])
13000         continue;
13001 
13002       switch (i)
13003         {
13004 #if 0
13005           case BGP_STATS_ASPATH_AVGHOPS:
13006           case BGP_STATS_ASPATH_AVGSIZE:
13007           case BGP_STATS_AVGPLEN:
13008             vty_out (vty, "%-30s: ", table_stats_strs[i]);
13009             vty_out (vty, "%12.2f",
13010                      (float)ts.counts[i] / (float)TALLY_SIGFIG);
13011             break;
13012 #endif
13013           case BGP_STATS_ASPATH_TOTHOPS:
13014           case BGP_STATS_ASPATH_TOTSIZE:
13015             vty_out (vty, "%-30s: ", table_stats_strs[i]);
13016             vty_out (vty, "%12.2f",
13017                      ts.counts[i] ?
13018                      (float)ts.counts[i] /
13019                       (float)ts.counts[BGP_STATS_ASPATH_COUNT]
13020                      : 0);
13021             break;
13022           case BGP_STATS_TOTPLEN:
13023             vty_out (vty, "%-30s: ", table_stats_strs[i]);
13024             vty_out (vty, "%12.2f",
13025                      ts.counts[i] ?
13026                      (float)ts.counts[i] /
13027                       (float)ts.counts[BGP_STATS_PREFIXES]
13028                      : 0);
13029             break;
13030           case BGP_STATS_SPACE:
13031             vty_out (vty, "%-30s: ", table_stats_strs[i]);
13032             vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
13033             if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
13034               break;
13035             vty_out (vty, "%30s: ", "%% announced ");
13036             vty_out (vty, "%12.2f%s",
13037                      100 * (float)ts.counts[BGP_STATS_SPACE] /
13038                        (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
13039                        VTY_NEWLINE);
13040             vty_out (vty, "%30s: ", "/8 equivalent ");
13041             vty_out (vty, "%12.2f%s",
13042                      (float)ts.counts[BGP_STATS_SPACE] /
13043                        (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
13044                      VTY_NEWLINE);
13045             if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
13046               break;
13047             vty_out (vty, "%30s: ", "/24 equivalent ");
13048             vty_out (vty, "%12.2f",
13049                      (float)ts.counts[BGP_STATS_SPACE] /
13050                        (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
13051             break;
13052           default:
13053             vty_out (vty, "%-30s: ", table_stats_strs[i]);
13054             vty_out (vty, "%12llu", ts.counts[i]);
13055         }
13056 
13057       vty_out (vty, "%s", VTY_NEWLINE);
13058     }
13059   return CMD_SUCCESS;
13060 }
13061 
13062 static int
bgp_table_stats_vty(struct vty * vty,const char * name,const char * afi_str,const char * safi_str)13063 bgp_table_stats_vty (struct vty *vty, const char *name,
13064                      const char *afi_str, const char *safi_str)
13065 {
13066   struct bgp *bgp;
13067   afi_t afi;
13068   safi_t safi;
13069 
13070  if (name)
13071     bgp = bgp_lookup_by_name (name);
13072   else
13073     bgp = bgp_get_default ();
13074 
13075   if (!bgp)
13076     {
13077       vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
13078       return CMD_WARNING;
13079     }
13080   if (strncmp (afi_str, "ipv", 3) == 0)
13081     {
13082       if (strncmp (afi_str, "ipv4", 4) == 0)
13083         afi = AFI_IP;
13084       else if (strncmp (afi_str, "ipv6", 4) == 0)
13085         afi = AFI_IP6;
13086       else
13087         {
13088           vty_out (vty, "%% Invalid address family %s%s",
13089                    afi_str, VTY_NEWLINE);
13090           return CMD_WARNING;
13091         }
13092       switch (safi_str[0]) {
13093 	case 'm':
13094 	    safi = SAFI_MULTICAST;
13095 	    break;
13096 	case 'u':
13097 	    safi = SAFI_UNICAST;
13098 	    break;
13099 	case 'v':
13100 	    safi =  SAFI_MPLS_VPN;
13101 	    break;
13102 	case 'e':
13103 	    safi = SAFI_ENCAP;
13104 	    break;
13105 	default:
13106 	    vty_out (vty, "%% Invalid subsequent address family %s%s",
13107                    safi_str, VTY_NEWLINE);
13108             return CMD_WARNING;
13109       }
13110     }
13111   else
13112     {
13113       vty_out (vty, "%% Invalid address family \"%s\"%s",
13114                afi_str, VTY_NEWLINE);
13115       return CMD_WARNING;
13116     }
13117 
13118   return bgp_table_stats (vty, bgp, afi, safi);
13119 }
13120 
13121 DEFUN (show_bgp_statistics,
13122        show_bgp_statistics_cmd,
13123        "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
13124        SHOW_STR
13125        BGP_STR
13126        "Address family\n"
13127        "Address family\n"
13128        "Address Family modifier\n"
13129        "Address Family modifier\n"
13130        "Address Family modifier\n"
13131        "Address Family modifier\n"
13132        "BGP RIB advertisement statistics\n")
13133 {
13134   return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
13135 }
13136 
13137 ALIAS (show_bgp_statistics,
13138        show_bgp_statistics_vpnv4_cmd,
13139        "show bgp (ipv4) (vpnv4) statistics",
13140        SHOW_STR
13141        BGP_STR
13142        "Address family\n"
13143        "Address Family modifier\n"
13144        "BGP RIB advertisement statistics\n")
13145 
13146 DEFUN (show_bgp_statistics_view,
13147        show_bgp_statistics_view_cmd,
13148        "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
13149        SHOW_STR
13150        BGP_STR
13151        "BGP view\n"
13152        "Address family\n"
13153        "Address family\n"
13154        "Address Family modifier\n"
13155        "Address Family modifier\n"
13156        "Address Family modifier\n"
13157        "Address Family modifier\n"
13158        "BGP RIB advertisement statistics\n")
13159 {
13160   return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
13161 }
13162 
13163 ALIAS (show_bgp_statistics_view,
13164        show_bgp_statistics_view_vpnv4_cmd,
13165        "show bgp view WORD (ipv4) (vpnv4) statistics",
13166        SHOW_STR
13167        BGP_STR
13168        "BGP view\n"
13169        "Address family\n"
13170        "Address Family modifier\n"
13171        "BGP RIB advertisement statistics\n")
13172 
13173 enum bgp_pcounts
13174 {
13175   PCOUNT_ADJ_IN = 0,
13176   PCOUNT_DAMPED,
13177   PCOUNT_REMOVED,
13178   PCOUNT_HISTORY,
13179   PCOUNT_STALE,
13180   PCOUNT_VALID,
13181   PCOUNT_ALL,
13182   PCOUNT_COUNTED,
13183   PCOUNT_PFCNT, /* the figure we display to users */
13184   PCOUNT_MAX,
13185 };
13186 
13187 static const char *pcount_strs[] =
13188 {
13189   [PCOUNT_ADJ_IN]  = "Adj-in",
13190   [PCOUNT_DAMPED]  = "Damped",
13191   [PCOUNT_REMOVED] = "Removed",
13192   [PCOUNT_HISTORY] = "History",
13193   [PCOUNT_STALE]   = "Stale",
13194   [PCOUNT_VALID]   = "Valid",
13195   [PCOUNT_ALL]     = "All RIB",
13196   [PCOUNT_COUNTED] = "PfxCt counted",
13197   [PCOUNT_PFCNT]   = "Useable",
13198   [PCOUNT_MAX]     = NULL,
13199 };
13200 
13201 struct peer_pcounts
13202 {
13203   unsigned int count[PCOUNT_MAX];
13204   const struct peer *peer;
13205   const struct bgp_table *table;
13206 };
13207 
13208 static int
bgp_peer_count_walker(struct thread * t)13209 bgp_peer_count_walker (struct thread *t)
13210 {
13211   struct bgp_node *rn;
13212   struct peer_pcounts *pc = THREAD_ARG (t);
13213   const struct peer *peer = pc->peer;
13214 
13215   for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
13216     {
13217       struct bgp_adj_in *ain;
13218       struct bgp_info *ri;
13219 
13220       for (ain = rn->adj_in; ain; ain = ain->next)
13221         if (ain->peer == peer)
13222           pc->count[PCOUNT_ADJ_IN]++;
13223 
13224       for (ri = rn->info; ri; ri = ri->next)
13225         {
13226           char buf[SU_ADDRSTRLEN];
13227 
13228           if (ri->peer != peer)
13229             continue;
13230 
13231           pc->count[PCOUNT_ALL]++;
13232 
13233           if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
13234             pc->count[PCOUNT_DAMPED]++;
13235           if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
13236             pc->count[PCOUNT_HISTORY]++;
13237           if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
13238             pc->count[PCOUNT_REMOVED]++;
13239           if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
13240             pc->count[PCOUNT_STALE]++;
13241           if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
13242             pc->count[PCOUNT_VALID]++;
13243           if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
13244             pc->count[PCOUNT_PFCNT]++;
13245 
13246           if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
13247             {
13248               pc->count[PCOUNT_COUNTED]++;
13249               if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
13250                 plog_warn (peer->log,
13251                            "%s [pcount] %s/%d is counted but flags 0x%x",
13252                            peer->host,
13253                            inet_ntop(rn->p.family, &rn->p.u.prefix,
13254                                      buf, SU_ADDRSTRLEN),
13255                            rn->p.prefixlen,
13256                            ri->flags);
13257             }
13258           else
13259             {
13260               if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
13261                 plog_warn (peer->log,
13262                            "%s [pcount] %s/%d not counted but flags 0x%x",
13263                            peer->host,
13264                            inet_ntop(rn->p.family, &rn->p.u.prefix,
13265                                      buf, SU_ADDRSTRLEN),
13266                            rn->p.prefixlen,
13267                            ri->flags);
13268             }
13269         }
13270     }
13271   return 0;
13272 }
13273 
13274 static int
bgp_peer_counts(struct vty * vty,struct peer * peer,afi_t afi,safi_t safi)13275 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
13276 {
13277   struct peer_pcounts pcounts = { .peer = peer };
13278   unsigned int i;
13279 
13280   if (!peer || !peer->bgp || !peer->afc[afi][safi]
13281       || !peer->bgp->rib[afi][safi])
13282     {
13283       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13284       return CMD_WARNING;
13285     }
13286 
13287   memset (&pcounts, 0, sizeof(pcounts));
13288   pcounts.peer = peer;
13289   pcounts.table = peer->bgp->rib[afi][safi];
13290 
13291   /* in-place call via thread subsystem so as to record execution time
13292    * stats for the thread-walk (i.e. ensure this can't be blamed on
13293    * on just vty_read()).
13294    */
13295   thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
13296 
13297   vty_out (vty, "Prefix counts for %s, %s%s",
13298            peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
13299   vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
13300   vty_out (vty, "%sCounts from RIB table walk:%s%s",
13301            VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
13302 
13303   for (i = 0; i < PCOUNT_MAX; i++)
13304       vty_out (vty, "%20s: %-10d%s",
13305                pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
13306 
13307   if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
13308     {
13309       vty_out (vty, "%s [pcount] PfxCt drift!%s",
13310                peer->host, VTY_NEWLINE);
13311       vty_out (vty, "Please report this bug, with the above command output%s",
13312               VTY_NEWLINE);
13313     }
13314 
13315   return CMD_SUCCESS;
13316 }
13317 
13318 DEFUN (show_ip_bgp_neighbor_prefix_counts,
13319        show_ip_bgp_neighbor_prefix_counts_cmd,
13320        "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13321        SHOW_STR
13322        IP_STR
13323        BGP_STR
13324        "Detailed information on TCP and BGP neighbor connections\n"
13325        "Neighbor to display information about\n"
13326        "Neighbor to display information about\n"
13327        "Display detailed prefix count information\n")
13328 {
13329   struct peer *peer;
13330 
13331   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13332   if (! peer)
13333     return CMD_WARNING;
13334 
13335   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
13336 }
13337 
13338 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
13339        show_bgp_ipv6_neighbor_prefix_counts_cmd,
13340        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13341        SHOW_STR
13342        BGP_STR
13343        "Address family\n"
13344        "Detailed information on TCP and BGP neighbor connections\n"
13345        "Neighbor to display information about\n"
13346        "Neighbor to display information about\n"
13347        "Display detailed prefix count information\n")
13348 {
13349   struct peer *peer;
13350 
13351   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13352   if (! peer)
13353     return CMD_WARNING;
13354 
13355   return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
13356 }
13357 
13358 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
13359        show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
13360        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13361        SHOW_STR
13362        IP_STR
13363        BGP_STR
13364        "Address family\n"
13365        "Address Family modifier\n"
13366        "Address Family modifier\n"
13367        "Detailed information on TCP and BGP neighbor connections\n"
13368        "Neighbor to display information about\n"
13369        "Neighbor to display information about\n"
13370        "Display detailed prefix count information\n")
13371 {
13372   struct peer *peer;
13373 
13374   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13375   if (! peer)
13376     return CMD_WARNING;
13377 
13378   if (strncmp (argv[0], "m", 1) == 0)
13379     return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
13380 
13381   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
13382 }
13383 
13384 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
13385        show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
13386        "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13387        SHOW_STR
13388        IP_STR
13389        BGP_STR
13390        "Address family\n"
13391        "Address Family modifier\n"
13392        "Address Family modifier\n"
13393        "Detailed information on TCP and BGP neighbor connections\n"
13394        "Neighbor to display information about\n"
13395        "Neighbor to display information about\n"
13396        "Display detailed prefix count information\n")
13397 {
13398   struct peer *peer;
13399 
13400   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13401   if (! peer)
13402     return CMD_WARNING;
13403 
13404   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
13405 }
13406 
13407 DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
13408        show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
13409        "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13410        SHOW_STR
13411        BGP_STR
13412        "Address family\n"
13413        "Address Family modifier\n"
13414        "Address Family modifier\n"
13415        "Address Family modifier\n"
13416        "Address Family modifier\n"
13417        "Detailed information on TCP and BGP neighbor connections\n"
13418        "Neighbor to display information about\n"
13419        "Neighbor to display information about\n"
13420        "Display detailed prefix count information\n")
13421 {
13422   struct peer *peer;
13423   safi_t	safi;
13424 
13425   if (bgp_parse_safi(argv[0], &safi)) {
13426     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13427     return CMD_WARNING;
13428   }
13429 
13430   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13431   if (! peer)
13432     return CMD_WARNING;
13433 
13434   return bgp_peer_counts (vty, peer, AFI_IP, safi);
13435 }
13436 
13437 DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
13438        show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
13439        "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13440        SHOW_STR
13441        BGP_STR
13442        "Address family\n"
13443        "Address Family modifier\n"
13444        "Address Family modifier\n"
13445        "Address Family modifier\n"
13446        "Address Family modifier\n"
13447        "Detailed information on TCP and BGP neighbor connections\n"
13448        "Neighbor to display information about\n"
13449        "Neighbor to display information about\n"
13450        "Display detailed prefix count information\n")
13451 {
13452   struct peer *peer;
13453   safi_t	safi;
13454 
13455   if (bgp_parse_safi(argv[0], &safi)) {
13456     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13457     return CMD_WARNING;
13458   }
13459 
13460   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13461   if (! peer)
13462     return CMD_WARNING;
13463 
13464   return bgp_peer_counts (vty, peer, AFI_IP6, safi);
13465 }
13466 
13467 DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
13468        show_ip_bgp_encap_neighbor_prefix_counts_cmd,
13469        "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
13470        SHOW_STR
13471        IP_STR
13472        BGP_STR
13473        "Address family\n"
13474        "Address Family modifier\n"
13475        "Address Family modifier\n"
13476        "Detailed information on TCP and BGP neighbor connections\n"
13477        "Neighbor to display information about\n"
13478        "Neighbor to display information about\n"
13479        "Display detailed prefix count information\n")
13480 {
13481   struct peer *peer;
13482 
13483   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13484   if (! peer)
13485     return CMD_WARNING;
13486 
13487   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
13488 }
13489 
13490 
13491 static void
show_adj_route(struct vty * vty,struct peer * peer,afi_t afi,safi_t safi,int in)13492 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
13493 		int in)
13494 {
13495   struct bgp_table *table;
13496   struct bgp_adj_in *ain;
13497   struct bgp_adj_out *adj;
13498   unsigned long output_count;
13499   struct bgp_node *rn;
13500   int header1 = 1;
13501   struct bgp *bgp;
13502   int header2 = 1;
13503 
13504   bgp = peer->bgp;
13505 
13506   if (! bgp)
13507     return;
13508 
13509   table = bgp->rib[afi][safi];
13510 
13511   output_count = 0;
13512 
13513   if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
13514 			  PEER_STATUS_DEFAULT_ORIGINATE))
13515     {
13516       vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
13517       vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13518       vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13519 
13520       vty_out (vty, "Originating default network 0.0.0.0%s%s",
13521 	       VTY_NEWLINE, VTY_NEWLINE);
13522       header1 = 0;
13523     }
13524 
13525   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13526     if (in)
13527       {
13528 	for (ain = rn->adj_in; ain; ain = ain->next)
13529 	  if (ain->peer == peer)
13530 	    {
13531 	      if (header1)
13532 		{
13533 		  vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
13534 		  vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13535 		  vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13536 		  header1 = 0;
13537 		}
13538 	      if (header2)
13539 		{
13540 		  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
13541 		  header2 = 0;
13542 		}
13543 	      if (ain->attr)
13544 		{
13545 		  route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
13546 		  output_count++;
13547 		}
13548 	    }
13549       }
13550     else
13551       {
13552 	for (adj = rn->adj_out; adj; adj = adj->next)
13553 	  if (adj->peer == peer)
13554 	    {
13555 	      if (header1)
13556 		{
13557 		  vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
13558 		  vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13559 		  vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
13560 		  header1 = 0;
13561 		}
13562 	      if (header2)
13563 		{
13564 		  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
13565 		  header2 = 0;
13566 		}
13567 	      if (adj->attr)
13568 		{
13569 		  route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
13570 		  output_count++;
13571 		}
13572 	    }
13573       }
13574 
13575   if (output_count != 0)
13576     vty_out (vty, "%sTotal number of prefixes %ld%s",
13577 	     VTY_NEWLINE, output_count, VTY_NEWLINE);
13578 }
13579 
13580 static int
peer_adj_routes(struct vty * vty,struct peer * peer,afi_t afi,safi_t safi,int in)13581 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
13582 {
13583   if (! peer || ! peer->afc[afi][safi])
13584     {
13585       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13586       return CMD_WARNING;
13587     }
13588 
13589   if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
13590     {
13591       vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
13592 	       VTY_NEWLINE);
13593       return CMD_WARNING;
13594     }
13595 
13596   show_adj_route (vty, peer, afi, safi, in);
13597 
13598   return CMD_SUCCESS;
13599 }
13600 
13601 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
13602        show_ip_bgp_view_neighbor_advertised_route_cmd,
13603        "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13604        SHOW_STR
13605        IP_STR
13606        BGP_STR
13607        "BGP view\n"
13608        "View name\n"
13609        "Detailed information on TCP and BGP neighbor connections\n"
13610        "Neighbor to display information about\n"
13611        "Neighbor to display information about\n"
13612        "Display the routes advertised to a BGP neighbor\n")
13613 {
13614   struct peer *peer;
13615 
13616   if (argc == 2)
13617     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13618   else
13619     peer = peer_lookup_in_view (vty, NULL, argv[0]);
13620 
13621   if (! peer)
13622     return CMD_WARNING;
13623 
13624   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
13625 }
13626 
13627 ALIAS (show_ip_bgp_view_neighbor_advertised_route,
13628        show_ip_bgp_neighbor_advertised_route_cmd,
13629        "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13630        SHOW_STR
13631        IP_STR
13632        BGP_STR
13633        "Detailed information on TCP and BGP neighbor connections\n"
13634        "Neighbor to display information about\n"
13635        "Neighbor to display information about\n"
13636        "Display the routes advertised to a BGP neighbor\n")
13637 
13638 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
13639        show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
13640        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13641        SHOW_STR
13642        IP_STR
13643        BGP_STR
13644        "Address family\n"
13645        "Address Family modifier\n"
13646        "Address Family modifier\n"
13647        "Detailed information on TCP and BGP neighbor connections\n"
13648        "Neighbor to display information about\n"
13649        "Neighbor to display information about\n"
13650        "Display the routes advertised to a BGP neighbor\n")
13651 {
13652   struct peer *peer;
13653 
13654   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13655   if (! peer)
13656     return CMD_WARNING;
13657 
13658   if (strncmp (argv[0], "m", 1) == 0)
13659     return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
13660 
13661   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
13662 }
13663 
13664 DEFUN (show_bgp_view_neighbor_advertised_route,
13665        show_bgp_view_neighbor_advertised_route_cmd,
13666        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13667        SHOW_STR
13668        BGP_STR
13669        "BGP view\n"
13670        "View name\n"
13671        "Detailed information on TCP and BGP neighbor connections\n"
13672        "Neighbor to display information about\n"
13673        "Neighbor to display information about\n"
13674        "Display the routes advertised to a BGP neighbor\n")
13675 {
13676   struct peer *peer;
13677 
13678   if (argc == 2)
13679     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13680   else
13681     peer = peer_lookup_in_view (vty, NULL, argv[0]);
13682 
13683   if (! peer)
13684     return CMD_WARNING;
13685 
13686   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13687 }
13688 
13689 DEFUN (show_bgp_view_neighbor_received_routes,
13690        show_bgp_view_neighbor_received_routes_cmd,
13691        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
13692        SHOW_STR
13693        BGP_STR
13694        "BGP view\n"
13695        "View name\n"
13696        "Detailed information on TCP and BGP neighbor connections\n"
13697        "Neighbor to display information about\n"
13698        "Neighbor to display information about\n"
13699        "Display the received routes from neighbor\n")
13700 {
13701   struct peer *peer;
13702 
13703   if (argc == 2)
13704     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13705   else
13706     peer = peer_lookup_in_view (vty, NULL, argv[0]);
13707 
13708   if (! peer)
13709     return CMD_WARNING;
13710 
13711   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13712 }
13713 
13714 ALIAS (show_bgp_view_neighbor_advertised_route,
13715        show_bgp_neighbor_advertised_route_cmd,
13716        "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13717        SHOW_STR
13718        BGP_STR
13719        "Detailed information on TCP and BGP neighbor connections\n"
13720        "Neighbor to display information about\n"
13721        "Neighbor to display information about\n"
13722        "Display the routes advertised to a BGP neighbor\n")
13723 
13724 ALIAS (show_bgp_view_neighbor_advertised_route,
13725        show_bgp_ipv6_neighbor_advertised_route_cmd,
13726        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13727        SHOW_STR
13728        BGP_STR
13729        "Address family\n"
13730        "Detailed information on TCP and BGP neighbor connections\n"
13731        "Neighbor to display information about\n"
13732        "Neighbor to display information about\n"
13733        "Display the routes advertised to a BGP neighbor\n")
13734 
13735 /* old command */
13736 ALIAS (show_bgp_view_neighbor_advertised_route,
13737        ipv6_bgp_neighbor_advertised_route_cmd,
13738        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13739        SHOW_STR
13740        IPV6_STR
13741        BGP_STR
13742        "Detailed information on TCP and BGP neighbor connections\n"
13743        "Neighbor to display information about\n"
13744        "Neighbor to display information about\n"
13745        "Display the routes advertised to a BGP neighbor\n")
13746 
13747 /* old command */
13748 DEFUN (ipv6_mbgp_neighbor_advertised_route,
13749        ipv6_mbgp_neighbor_advertised_route_cmd,
13750        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13751        SHOW_STR
13752        IPV6_STR
13753        MBGP_STR
13754        "Detailed information on TCP and BGP neighbor connections\n"
13755        "Neighbor to display information about\n"
13756        "Neighbor to display information about\n"
13757        "Display the routes advertised to a BGP neighbor\n")
13758 {
13759   struct peer *peer;
13760 
13761   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13762   if (! peer)
13763     return CMD_WARNING;
13764 
13765   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
13766 }
13767 
13768 DEFUN (show_ip_bgp_view_neighbor_received_routes,
13769        show_ip_bgp_view_neighbor_received_routes_cmd,
13770        "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
13771        SHOW_STR
13772        IP_STR
13773        BGP_STR
13774        "BGP view\n"
13775        "View name\n"
13776        "Detailed information on TCP and BGP neighbor connections\n"
13777        "Neighbor to display information about\n"
13778        "Neighbor to display information about\n"
13779        "Display the received routes from neighbor\n")
13780 {
13781   struct peer *peer;
13782 
13783   if (argc == 2)
13784     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13785   else
13786     peer = peer_lookup_in_view (vty, NULL, argv[0]);
13787 
13788   if (! peer)
13789     return CMD_WARNING;
13790 
13791   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
13792 }
13793 
13794 ALIAS (show_ip_bgp_view_neighbor_received_routes,
13795        show_ip_bgp_neighbor_received_routes_cmd,
13796        "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13797        SHOW_STR
13798        IP_STR
13799        BGP_STR
13800        "Detailed information on TCP and BGP neighbor connections\n"
13801        "Neighbor to display information about\n"
13802        "Neighbor to display information about\n"
13803        "Display the received routes from neighbor\n")
13804 
13805 ALIAS (show_bgp_view_neighbor_received_routes,
13806        show_bgp_ipv6_neighbor_received_routes_cmd,
13807        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
13808        SHOW_STR
13809        BGP_STR
13810        "Address family\n"
13811        "Detailed information on TCP and BGP neighbor connections\n"
13812        "Neighbor to display information about\n"
13813        "Neighbor to display information about\n"
13814        "Display the received routes from neighbor\n")
13815 
13816 DEFUN (show_bgp_neighbor_received_prefix_filter,
13817        show_bgp_neighbor_received_prefix_filter_cmd,
13818        "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13819        SHOW_STR
13820        BGP_STR
13821        "Detailed information on TCP and BGP neighbor connections\n"
13822        "Neighbor to display information about\n"
13823        "Neighbor to display information about\n"
13824        "Display information received from a BGP neighbor\n"
13825        "Display the prefixlist filter\n")
13826 {
13827   char name[BUFSIZ];
13828   union sockunion su;
13829   struct peer *peer;
13830   int count, ret;
13831 
13832   ret = str2sockunion (argv[0], &su);
13833   if (ret < 0)
13834     {
13835       vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13836       return CMD_WARNING;
13837     }
13838 
13839   peer = peer_lookup (NULL, &su);
13840   if (! peer)
13841     return CMD_WARNING;
13842 
13843   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13844   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13845   if (count)
13846     {
13847       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13848       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13849     }
13850 
13851   return CMD_SUCCESS;
13852 }
13853 
13854 /* old command */
13855 ALIAS (show_bgp_view_neighbor_received_routes,
13856        ipv6_bgp_neighbor_received_routes_cmd,
13857        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13858        SHOW_STR
13859        IPV6_STR
13860        BGP_STR
13861        "Detailed information on TCP and BGP neighbor connections\n"
13862        "Neighbor to display information about\n"
13863        "Neighbor to display information about\n"
13864        "Display the received routes from neighbor\n")
13865 
13866 /* old command */
13867 DEFUN (ipv6_mbgp_neighbor_received_routes,
13868        ipv6_mbgp_neighbor_received_routes_cmd,
13869        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13870        SHOW_STR
13871        IPV6_STR
13872        MBGP_STR
13873        "Detailed information on TCP and BGP neighbor connections\n"
13874        "Neighbor to display information about\n"
13875        "Neighbor to display information about\n"
13876        "Display the received routes from neighbor\n")
13877 {
13878   struct peer *peer;
13879 
13880   peer = peer_lookup_in_view (vty, NULL, argv[0]);
13881   if (! peer)
13882     return CMD_WARNING;
13883 
13884   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
13885 }
13886 
13887 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
13888        show_bgp_view_neighbor_received_prefix_filter_cmd,
13889        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13890        SHOW_STR
13891        BGP_STR
13892        "BGP view\n"
13893        "View name\n"
13894        "Detailed information on TCP and BGP neighbor connections\n"
13895        "Neighbor to display information about\n"
13896        "Neighbor to display information about\n"
13897        "Display information received from a BGP neighbor\n"
13898        "Display the prefixlist filter\n")
13899 {
13900   char name[BUFSIZ];
13901   union sockunion su;
13902   struct peer *peer;
13903   struct bgp *bgp;
13904   int count, ret;
13905 
13906   /* BGP structure lookup. */
13907   bgp = bgp_lookup_by_name (argv[0]);
13908   if (bgp == NULL)
13909   {
13910 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13911 	  return CMD_WARNING;
13912 	}
13913 
13914   ret = str2sockunion (argv[1], &su);
13915   if (ret < 0)
13916     {
13917       vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13918       return CMD_WARNING;
13919     }
13920 
13921   peer = peer_lookup (bgp, &su);
13922   if (! peer)
13923     return CMD_WARNING;
13924 
13925   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13926   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13927   if (count)
13928     {
13929       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13930       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13931     }
13932 
13933   return CMD_SUCCESS;
13934 }
13935 
13936 
13937 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
13938        show_ip_bgp_ipv4_neighbor_received_routes_cmd,
13939        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
13940        SHOW_STR
13941        IP_STR
13942        BGP_STR
13943        "Address family\n"
13944        "Address Family modifier\n"
13945        "Address Family modifier\n"
13946        "Detailed information on TCP and BGP neighbor connections\n"
13947        "Neighbor to display information about\n"
13948        "Neighbor to display information about\n"
13949        "Display the received routes from neighbor\n")
13950 {
13951   struct peer *peer;
13952 
13953   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13954   if (! peer)
13955     return CMD_WARNING;
13956 
13957   if (strncmp (argv[0], "m", 1) == 0)
13958     return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
13959 
13960   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
13961 }
13962 
13963 DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
13964        show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
13965        "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13966        SHOW_STR
13967        BGP_STR
13968        "Address Family modifier\n"
13969        "Address Family modifier\n"
13970        "Detailed information on TCP and BGP neighbor connections\n"
13971        "Neighbor to display information about\n"
13972        "Neighbor to display information about\n"
13973        "Display the routes advertised to a BGP neighbor\n")
13974 {
13975   struct peer *peer;
13976   safi_t	safi;
13977 
13978   if (bgp_parse_safi(argv[0], &safi)) {
13979     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13980     return CMD_WARNING;
13981   }
13982 
13983   peer = peer_lookup_in_view (vty, NULL, argv[1]);
13984   if (! peer)
13985     return CMD_WARNING;
13986 
13987   return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13988 }
13989 
13990 DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13991        show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13992        "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13993        SHOW_STR
13994        BGP_STR
13995        "Address Family modifier\n"
13996        "Address Family modifier\n"
13997        "Address Family modifier\n"
13998        "Detailed information on TCP and BGP neighbor connections\n"
13999        "Neighbor to display information about\n"
14000        "Neighbor to display information about\n"
14001        "Display the routes advertised to a BGP neighbor\n")
14002 {
14003   struct peer *peer;
14004   safi_t	safi;
14005 
14006   if (bgp_parse_safi(argv[0], &safi)) {
14007     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14008     return CMD_WARNING;
14009   }
14010 
14011   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14012   if (! peer)
14013     return CMD_WARNING;
14014 
14015   return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
14016 }
14017 
14018 DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
14019        show_bgp_view_ipv6_neighbor_advertised_route_cmd,
14020        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
14021        SHOW_STR
14022        BGP_STR
14023        "BGP view\n"
14024        "View name\n"
14025        "Address family\n"
14026        "Detailed information on TCP and BGP neighbor connections\n"
14027        "Neighbor to display information about\n"
14028        "Neighbor to display information about\n"
14029        "Display the routes advertised to a BGP neighbor\n")
14030 {
14031   struct peer *peer;
14032 
14033   if (argc == 2)
14034     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14035   else
14036     peer = peer_lookup_in_view (vty, NULL, argv[0]);
14037 
14038   if (! peer)
14039     return CMD_WARNING;
14040 
14041   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
14042 }
14043 
14044 DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
14045        show_bgp_view_ipv6_neighbor_received_routes_cmd,
14046        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
14047        SHOW_STR
14048        BGP_STR
14049        "BGP view\n"
14050        "View name\n"
14051        "Address family\n"
14052        "Detailed information on TCP and BGP neighbor connections\n"
14053        "Neighbor to display information about\n"
14054        "Neighbor to display information about\n"
14055        "Display the received routes from neighbor\n")
14056 {
14057   struct peer *peer;
14058 
14059   if (argc == 2)
14060     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14061   else
14062     peer = peer_lookup_in_view (vty, NULL, argv[0]);
14063 
14064   if (! peer)
14065     return CMD_WARNING;
14066 
14067   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
14068 }
14069 
14070 DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
14071        show_bgp_ipv4_safi_neighbor_received_routes_cmd,
14072        "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
14073        SHOW_STR
14074        BGP_STR
14075        "Address family\n"
14076        "Address Family modifier\n"
14077        "Address Family modifier\n"
14078        "Address Family modifier\n"
14079        "Address Family modifier\n"
14080        "Detailed information on TCP and BGP neighbor connections\n"
14081        "Neighbor to display information about\n"
14082        "Neighbor to display information about\n"
14083        "Display the received routes from neighbor\n")
14084 {
14085   struct peer *peer;
14086   safi_t	safi;
14087 
14088   if (bgp_parse_safi(argv[0], &safi)) {
14089     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14090     return CMD_WARNING;
14091   }
14092 
14093   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14094   if (! peer)
14095     return CMD_WARNING;
14096 
14097   return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
14098 }
14099 
14100 DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
14101        show_bgp_ipv6_safi_neighbor_received_routes_cmd,
14102        "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
14103        SHOW_STR
14104        BGP_STR
14105        "Address family\n"
14106        "Address Family modifier\n"
14107        "Address Family modifier\n"
14108        "Address Family modifier\n"
14109        "Address Family modifier\n"
14110        "Detailed information on TCP and BGP neighbor connections\n"
14111        "Neighbor to display information about\n"
14112        "Neighbor to display information about\n"
14113        "Display the received routes from neighbor\n")
14114 {
14115   struct peer *peer;
14116   safi_t	safi;
14117 
14118   if (bgp_parse_safi(argv[0], &safi)) {
14119     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14120     return CMD_WARNING;
14121   }
14122 
14123   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14124   if (! peer)
14125     return CMD_WARNING;
14126 
14127   return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
14128 }
14129 
14130 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
14131        show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
14132        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
14133        SHOW_STR
14134        BGP_STR
14135        "BGP view\n"
14136        "View name\n"
14137        "Address family\n"
14138        "Address family\n"
14139        "Address family modifier\n"
14140        "Address family modifier\n"
14141        "Detailed information on TCP and BGP neighbor connections\n"
14142        "Neighbor to display information about\n"
14143        "Neighbor to display information about\n"
14144        "Display the advertised routes to neighbor\n"
14145        "Display the received routes from neighbor\n")
14146 {
14147   int afi;
14148   int safi;
14149   int in;
14150   struct peer *peer;
14151 
14152   peer = peer_lookup_in_view (vty, argv[0], argv[3]);
14153 
14154   if (! peer)
14155     return CMD_WARNING;
14156 
14157   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
14158   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14159   in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
14160 
14161   return peer_adj_routes (vty, peer, afi, safi, in);
14162 }
14163 
14164 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
14165        show_ip_bgp_neighbor_received_prefix_filter_cmd,
14166        "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14167        SHOW_STR
14168        IP_STR
14169        BGP_STR
14170        "Detailed information on TCP and BGP neighbor connections\n"
14171        "Neighbor to display information about\n"
14172        "Neighbor to display information about\n"
14173        "Display information received from a BGP neighbor\n"
14174        "Display the prefixlist filter\n")
14175 {
14176   char name[BUFSIZ];
14177   union sockunion su;
14178   struct peer *peer;
14179   int count, ret;
14180 
14181   ret = str2sockunion (argv[0], &su);
14182   if (ret < 0)
14183     {
14184       vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
14185       return CMD_WARNING;
14186     }
14187 
14188   peer = peer_lookup (NULL, &su);
14189   if (! peer)
14190     return CMD_WARNING;
14191 
14192   sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
14193   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
14194   if (count)
14195     {
14196       vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
14197       prefix_bgp_show_prefix_list (vty, AFI_IP, name);
14198     }
14199 
14200   return CMD_SUCCESS;
14201 }
14202 
14203 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
14204        show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
14205        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14206        SHOW_STR
14207        IP_STR
14208        BGP_STR
14209        "Address family\n"
14210        "Address Family modifier\n"
14211        "Address Family modifier\n"
14212        "Detailed information on TCP and BGP neighbor connections\n"
14213        "Neighbor to display information about\n"
14214        "Neighbor to display information about\n"
14215        "Display information received from a BGP neighbor\n"
14216        "Display the prefixlist filter\n")
14217 {
14218   char name[BUFSIZ];
14219   union sockunion su;
14220   struct peer *peer;
14221   int count, ret;
14222 
14223   ret = str2sockunion (argv[1], &su);
14224   if (ret < 0)
14225     {
14226       vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
14227       return CMD_WARNING;
14228     }
14229 
14230   peer = peer_lookup (NULL, &su);
14231   if (! peer)
14232     return CMD_WARNING;
14233 
14234   if (strncmp (argv[0], "m", 1) == 0)
14235     {
14236       sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
14237       count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
14238       if (count)
14239 	{
14240 	  vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
14241 	  prefix_bgp_show_prefix_list (vty, AFI_IP, name);
14242 	}
14243     }
14244   else
14245     {
14246       sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
14247       count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
14248       if (count)
14249 	{
14250 	  vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
14251 	  prefix_bgp_show_prefix_list (vty, AFI_IP, name);
14252 	}
14253     }
14254 
14255   return CMD_SUCCESS;
14256 }
14257 
14258 ALIAS (show_bgp_view_neighbor_received_routes,
14259        show_bgp_neighbor_received_routes_cmd,
14260        "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
14261        SHOW_STR
14262        BGP_STR
14263        "Detailed information on TCP and BGP neighbor connections\n"
14264        "Neighbor to display information about\n"
14265        "Neighbor to display information about\n"
14266        "Display the received routes from neighbor\n")
14267 
14268 DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
14269        show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
14270        "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14271        SHOW_STR
14272        BGP_STR
14273        IP_STR
14274        "Address Family modifier\n"
14275        "Address Family modifier\n"
14276        "Address Family modifier\n"
14277        "Address Family modifier\n"
14278        "Detailed information on TCP and BGP neighbor connections\n"
14279        "Neighbor to display information about\n"
14280        "Neighbor to display information about\n"
14281        "Display information received from a BGP neighbor\n"
14282        "Display the prefixlist filter\n")
14283 {
14284   char name[BUFSIZ];
14285   union sockunion su;
14286   struct peer *peer;
14287   int count, ret;
14288   safi_t	safi;
14289 
14290   if (bgp_parse_safi(argv[0], &safi)) {
14291     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14292     return CMD_WARNING;
14293   }
14294 
14295   ret = str2sockunion (argv[1], &su);
14296   if (ret < 0)
14297     {
14298       vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
14299       return CMD_WARNING;
14300     }
14301 
14302   peer = peer_lookup (NULL, &su);
14303   if (! peer)
14304     return CMD_WARNING;
14305 
14306   sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
14307   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
14308   if (count) {
14309       vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
14310       prefix_bgp_show_prefix_list (vty, AFI_IP, name);
14311   }
14312 
14313   return CMD_SUCCESS;
14314 }
14315 
14316 DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
14317        show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
14318        "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14319        SHOW_STR
14320        BGP_STR
14321        IP_STR
14322        "Address Family modifier\n"
14323        "Address Family modifier\n"
14324        "Address Family modifier\n"
14325        "Address Family modifier\n"
14326        "Detailed information on TCP and BGP neighbor connections\n"
14327        "Neighbor to display information about\n"
14328        "Neighbor to display information about\n"
14329        "Display information received from a BGP neighbor\n"
14330        "Display the prefixlist filter\n")
14331 {
14332   char name[BUFSIZ];
14333   union sockunion su;
14334   struct peer *peer;
14335   int count, ret;
14336   safi_t	safi;
14337 
14338   if (bgp_parse_safi(argv[0], &safi)) {
14339     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14340     return CMD_WARNING;
14341   }
14342 
14343   ret = str2sockunion (argv[1], &su);
14344   if (ret < 0)
14345     {
14346       vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
14347       return CMD_WARNING;
14348     }
14349 
14350   peer = peer_lookup (NULL, &su);
14351   if (! peer)
14352     return CMD_WARNING;
14353 
14354   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
14355   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
14356   if (count) {
14357       vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
14358       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
14359   }
14360 
14361   return CMD_SUCCESS;
14362 }
14363 
14364 DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
14365        show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
14366        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14367        SHOW_STR
14368        BGP_STR
14369        "Address family\n"
14370        "Detailed information on TCP and BGP neighbor connections\n"
14371        "Neighbor to display information about\n"
14372        "Neighbor to display information about\n"
14373        "Display information received from a BGP neighbor\n"
14374        "Display the prefixlist filter\n")
14375 {
14376   char name[BUFSIZ];
14377   union sockunion su;
14378   struct peer *peer;
14379   int count, ret;
14380 
14381   ret = str2sockunion (argv[0], &su);
14382   if (ret < 0)
14383     {
14384       vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
14385       return CMD_WARNING;
14386     }
14387 
14388   peer = peer_lookup (NULL, &su);
14389   if (! peer)
14390     return CMD_WARNING;
14391 
14392   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
14393   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
14394   if (count)
14395     {
14396       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
14397       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
14398     }
14399 
14400   return CMD_SUCCESS;
14401 }
14402 
14403 DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
14404        show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
14405        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
14406        SHOW_STR
14407        BGP_STR
14408        "BGP view\n"
14409        "View name\n"
14410        "Address family\n"
14411        "Detailed information on TCP and BGP neighbor connections\n"
14412        "Neighbor to display information about\n"
14413        "Neighbor to display information about\n"
14414        "Display information received from a BGP neighbor\n"
14415        "Display the prefixlist filter\n")
14416 {
14417   char name[BUFSIZ];
14418   union sockunion su;
14419   struct peer *peer;
14420   struct bgp *bgp;
14421   int count, ret;
14422 
14423   /* BGP structure lookup. */
14424   bgp = bgp_lookup_by_name (argv[0]);
14425   if (bgp == NULL)
14426   {
14427 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14428 	  return CMD_WARNING;
14429 	}
14430 
14431   ret = str2sockunion (argv[1], &su);
14432   if (ret < 0)
14433     {
14434       vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
14435       return CMD_WARNING;
14436     }
14437 
14438   peer = peer_lookup (bgp, &su);
14439   if (! peer)
14440     return CMD_WARNING;
14441 
14442   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
14443   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
14444   if (count)
14445     {
14446       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
14447       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
14448     }
14449 
14450   return CMD_SUCCESS;
14451 }
14452 
14453 static int
bgp_show_neighbor_route(struct vty * vty,struct peer * peer,afi_t afi,safi_t safi,enum bgp_show_type type)14454 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
14455 			 safi_t safi, enum bgp_show_type type)
14456 {
14457   if (! peer || ! peer->afc[afi][safi])
14458     {
14459       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
14460       return CMD_WARNING;
14461     }
14462 
14463   return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
14464 }
14465 DEFUN (show_ip_bgp_neighbor_routes,
14466        show_ip_bgp_neighbor_routes_cmd,
14467        "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
14468        SHOW_STR
14469        IP_STR
14470        BGP_STR
14471        "Detailed information on TCP and BGP neighbor connections\n"
14472        "Neighbor to display information about\n"
14473        "Neighbor to display information about\n"
14474        "Display routes learned from neighbor\n")
14475 {
14476   struct peer *peer;
14477 
14478   peer = peer_lookup_in_view (vty, NULL, argv[0]);
14479   if (! peer)
14480     return CMD_WARNING;
14481 
14482   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
14483 				  bgp_show_type_neighbor);
14484 }
14485 
14486 DEFUN (show_ip_bgp_neighbor_flap,
14487        show_ip_bgp_neighbor_flap_cmd,
14488        "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14489        SHOW_STR
14490        IP_STR
14491        BGP_STR
14492        "Detailed information on TCP and BGP neighbor connections\n"
14493        "Neighbor to display information about\n"
14494        "Neighbor to display information about\n"
14495        "Display flap statistics of the routes learned from neighbor\n")
14496 {
14497   struct peer *peer;
14498 
14499   peer = peer_lookup_in_view (vty, NULL, argv[0]);
14500   if (! peer)
14501     return CMD_WARNING;
14502 
14503   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
14504 				  bgp_show_type_flap_neighbor);
14505 }
14506 
14507 DEFUN (show_ip_bgp_neighbor_damp,
14508        show_ip_bgp_neighbor_damp_cmd,
14509        "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14510        SHOW_STR
14511        IP_STR
14512        BGP_STR
14513        "Detailed information on TCP and BGP neighbor connections\n"
14514        "Neighbor to display information about\n"
14515        "Neighbor to display information about\n"
14516        "Display the dampened routes received from neighbor\n")
14517 {
14518   struct peer *peer;
14519 
14520   peer = peer_lookup_in_view (vty, NULL, argv[0]);
14521   if (! peer)
14522     return CMD_WARNING;
14523 
14524   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
14525 				  bgp_show_type_damp_neighbor);
14526 }
14527 
14528 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
14529        show_ip_bgp_ipv4_neighbor_routes_cmd,
14530        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
14531        SHOW_STR
14532        IP_STR
14533        BGP_STR
14534        "Address family\n"
14535        "Address Family modifier\n"
14536        "Address Family modifier\n"
14537        "Detailed information on TCP and BGP neighbor connections\n"
14538        "Neighbor to display information about\n"
14539        "Neighbor to display information about\n"
14540        "Display routes learned from neighbor\n")
14541 {
14542   struct peer *peer;
14543 
14544   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14545   if (! peer)
14546     return CMD_WARNING;
14547 
14548   if (strncmp (argv[0], "m", 1) == 0)
14549     return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
14550 				    bgp_show_type_neighbor);
14551 
14552   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
14553 				  bgp_show_type_neighbor);
14554 }
14555 
14556 DEFUN (show_ip_bgp_view_rsclient,
14557        show_ip_bgp_view_rsclient_cmd,
14558        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14559        SHOW_STR
14560        IP_STR
14561        BGP_STR
14562        "BGP view\n"
14563        "View name\n"
14564        "Information about Route Server Client\n"
14565        NEIGHBOR_ADDR_STR)
14566 {
14567   struct bgp_table *table;
14568   struct peer *peer;
14569 
14570   if (argc == 2)
14571     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14572   else
14573     peer = peer_lookup_in_view (vty, NULL, argv[0]);
14574 
14575   if (! peer)
14576     return CMD_WARNING;
14577 
14578   if (! peer->afc[AFI_IP][SAFI_UNICAST])
14579     {
14580       vty_out (vty, "%% Activate the neighbor for the address family first%s",
14581             VTY_NEWLINE);
14582       return CMD_WARNING;
14583     }
14584 
14585   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14586               PEER_FLAG_RSERVER_CLIENT))
14587     {
14588       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14589             VTY_NEWLINE);
14590       return CMD_WARNING;
14591     }
14592 
14593   table = peer->rib[AFI_IP][SAFI_UNICAST];
14594 
14595   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14596 }
14597 
14598 ALIAS (show_ip_bgp_view_rsclient,
14599        show_ip_bgp_rsclient_cmd,
14600        "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
14601        SHOW_STR
14602        IP_STR
14603        BGP_STR
14604        "Information about Route Server Client\n"
14605        NEIGHBOR_ADDR_STR)
14606 
14607 DEFUN (show_bgp_view_ipv4_safi_rsclient,
14608        show_bgp_view_ipv4_safi_rsclient_cmd,
14609        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14610        SHOW_STR
14611        BGP_STR
14612        "BGP view\n"
14613        "View name\n"
14614        "Address family\n"
14615        "Address Family modifier\n"
14616        "Address Family modifier\n"
14617        "Information about Route Server Client\n"
14618        NEIGHBOR_ADDR_STR)
14619 {
14620   struct bgp_table *table;
14621   struct peer *peer;
14622   safi_t safi;
14623 
14624   if (argc == 3) {
14625     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14626     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14627   } else {
14628     peer = peer_lookup_in_view (vty, NULL, argv[1]);
14629     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14630   }
14631 
14632   if (! peer)
14633     return CMD_WARNING;
14634 
14635   if (! peer->afc[AFI_IP][safi])
14636     {
14637       vty_out (vty, "%% Activate the neighbor for the address family first%s",
14638             VTY_NEWLINE);
14639       return CMD_WARNING;
14640     }
14641 
14642   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14643               PEER_FLAG_RSERVER_CLIENT))
14644     {
14645       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14646             VTY_NEWLINE);
14647       return CMD_WARNING;
14648     }
14649 
14650   table = peer->rib[AFI_IP][safi];
14651 
14652   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14653 }
14654 
14655 ALIAS (show_bgp_view_ipv4_safi_rsclient,
14656        show_bgp_ipv4_safi_rsclient_cmd,
14657        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14658        SHOW_STR
14659        BGP_STR
14660        "Address family\n"
14661        "Address Family modifier\n"
14662        "Address Family modifier\n"
14663        "Information about Route Server Client\n"
14664        NEIGHBOR_ADDR_STR)
14665 
14666 DEFUN (show_ip_bgp_view_rsclient_route,
14667        show_ip_bgp_view_rsclient_route_cmd,
14668        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14669        SHOW_STR
14670        IP_STR
14671        BGP_STR
14672        "BGP view\n"
14673        "View name\n"
14674        "Information about Route Server Client\n"
14675        NEIGHBOR_ADDR_STR
14676        "Network in the BGP routing table to display\n")
14677 {
14678   struct bgp *bgp;
14679   struct peer *peer;
14680 
14681   /* BGP structure lookup. */
14682   if (argc == 3)
14683     {
14684       bgp = bgp_lookup_by_name (argv[0]);
14685       if (bgp == NULL)
14686 	{
14687 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14688 	  return CMD_WARNING;
14689 	}
14690     }
14691   else
14692     {
14693       bgp = bgp_get_default ();
14694       if (bgp == NULL)
14695 	{
14696 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14697 	  return CMD_WARNING;
14698 	}
14699     }
14700 
14701   if (argc == 3)
14702     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14703   else
14704     peer = peer_lookup_in_view (vty, NULL, argv[0]);
14705 
14706   if (! peer)
14707     return CMD_WARNING;
14708 
14709   if (! peer->afc[AFI_IP][SAFI_UNICAST])
14710     {
14711       vty_out (vty, "%% Activate the neighbor for the address family first%s",
14712             VTY_NEWLINE);
14713       return CMD_WARNING;
14714 }
14715 
14716   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14717               PEER_FLAG_RSERVER_CLIENT))
14718     {
14719       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14720             VTY_NEWLINE);
14721       return CMD_WARNING;
14722     }
14723 
14724   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14725                                   (argc == 3) ? argv[2] : argv[1],
14726                                   AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
14727 }
14728 
14729 ALIAS (show_ip_bgp_view_rsclient_route,
14730        show_ip_bgp_rsclient_route_cmd,
14731        "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14732        SHOW_STR
14733        IP_STR
14734        BGP_STR
14735        "Information about Route Server Client\n"
14736        NEIGHBOR_ADDR_STR
14737        "Network in the BGP routing table to display\n")
14738 
14739 DEFUN (show_bgp_ipv4_safi_neighbor_flap,
14740        show_bgp_ipv4_safi_neighbor_flap_cmd,
14741        "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14742        SHOW_STR
14743        BGP_STR
14744        "Address Family Modifier\n"
14745        "Address Family Modifier\n"
14746        "Address Family Modifier\n"
14747        "Address Family Modifier\n"
14748        "Detailed information on TCP and BGP neighbor connections\n"
14749        "Neighbor to display information about\n"
14750        "Neighbor to display information about\n"
14751        "Display flap statistics of the routes learned from neighbor\n")
14752 {
14753   struct peer *peer;
14754   safi_t	safi;
14755 
14756   if (bgp_parse_safi(argv[0], &safi)) {
14757     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14758     return CMD_WARNING;
14759   }
14760 
14761   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14762   if (! peer)
14763     return CMD_WARNING;
14764 
14765   return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
14766 				  bgp_show_type_flap_neighbor);
14767 }
14768 
14769 DEFUN (show_bgp_ipv6_safi_neighbor_flap,
14770        show_bgp_ipv6_safi_neighbor_flap_cmd,
14771        "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14772        SHOW_STR
14773        BGP_STR
14774        "Address Family Modifier\n"
14775        "Address Family Modifier\n"
14776        "Address Family Modifier\n"
14777        "Address Family Modifier\n"
14778        "Detailed information on TCP and BGP neighbor connections\n"
14779        "Neighbor to display information about\n"
14780        "Neighbor to display information about\n"
14781        "Display flap statistics of the routes learned from neighbor\n")
14782 {
14783   struct peer *peer;
14784   safi_t	safi;
14785 
14786   if (bgp_parse_safi(argv[0], &safi)) {
14787     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14788     return CMD_WARNING;
14789   }
14790 
14791   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14792   if (! peer)
14793     return CMD_WARNING;
14794 
14795   return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
14796 				  bgp_show_type_flap_neighbor);
14797 }
14798 
14799 DEFUN (show_bgp_ipv4_safi_neighbor_damp,
14800        show_bgp_ipv4_safi_neighbor_damp_cmd,
14801        "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14802        SHOW_STR
14803        BGP_STR
14804        "Address Family Modifier\n"
14805        "Address Family Modifier\n"
14806        "Address Family Modifier\n"
14807        "Address Family Modifier\n"
14808        "Detailed information on TCP and BGP neighbor connections\n"
14809        "Neighbor to display information about\n"
14810        "Neighbor to display information about\n"
14811        "Display the dampened routes received from neighbor\n")
14812 {
14813   struct peer *peer;
14814   safi_t	safi;
14815 
14816   if (bgp_parse_safi(argv[0], &safi)) {
14817     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14818     return CMD_WARNING;
14819   }
14820 
14821   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14822   if (! peer)
14823     return CMD_WARNING;
14824 
14825   return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
14826 				  bgp_show_type_damp_neighbor);
14827 }
14828 
14829 DEFUN (show_bgp_ipv6_safi_neighbor_damp,
14830        show_bgp_ipv6_safi_neighbor_damp_cmd,
14831        "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14832        SHOW_STR
14833        BGP_STR
14834        "Address Family Modifier\n"
14835        "Address Family Modifier\n"
14836        "Address Family Modifier\n"
14837        "Address Family Modifier\n"
14838        "Detailed information on TCP and BGP neighbor connections\n"
14839        "Neighbor to display information about\n"
14840        "Neighbor to display information about\n"
14841        "Display the dampened routes received from neighbor\n")
14842 {
14843   struct peer *peer;
14844   safi_t	safi;
14845 
14846   if (bgp_parse_safi(argv[0], &safi)) {
14847     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14848     return CMD_WARNING;
14849   }
14850 
14851   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14852   if (! peer)
14853     return CMD_WARNING;
14854 
14855   return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
14856 				  bgp_show_type_damp_neighbor);
14857 }
14858 
14859 DEFUN (show_bgp_ipv4_safi_neighbor_routes,
14860        show_bgp_ipv4_safi_neighbor_routes_cmd,
14861        "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
14862        SHOW_STR
14863        BGP_STR
14864        "Address family\n"
14865        "Address Family modifier\n"
14866        "Address Family modifier\n"
14867        "Detailed information on TCP and BGP neighbor connections\n"
14868        "Neighbor to display information about\n"
14869        "Neighbor to display information about\n"
14870        "Display routes learned from neighbor\n")
14871 {
14872   struct peer *peer;
14873   safi_t	safi;
14874 
14875   if (bgp_parse_safi(argv[0], &safi)) {
14876     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14877     return CMD_WARNING;
14878   }
14879 
14880   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14881   if (! peer)
14882     return CMD_WARNING;
14883 
14884   return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
14885 				  bgp_show_type_neighbor);
14886 }
14887 
14888 DEFUN (show_bgp_ipv6_safi_neighbor_routes,
14889        show_bgp_ipv6_safi_neighbor_routes_cmd,
14890        "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
14891        SHOW_STR
14892        BGP_STR
14893        "Address family\n"
14894        "Address Family modifier\n"
14895        "Address Family modifier\n"
14896        "Detailed information on TCP and BGP neighbor connections\n"
14897        NEIGHBOR_ADDR_STR
14898        NEIGHBOR_ADDR_STR
14899        "Display routes learned from neighbor\n")
14900 {
14901   struct peer *peer;
14902   safi_t	safi;
14903 
14904   if (bgp_parse_safi(argv[0], &safi)) {
14905     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
14906     return CMD_WARNING;
14907   }
14908 
14909   peer = peer_lookup_in_view (vty, NULL, argv[1]);
14910   if (! peer)
14911     return CMD_WARNING;
14912 
14913   return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
14914 				  bgp_show_type_neighbor);
14915 }
14916 
14917 DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
14918        show_bgp_view_ipv4_safi_rsclient_route_cmd,
14919        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14920        SHOW_STR
14921        BGP_STR
14922        "BGP view\n"
14923        "View name\n"
14924        "Address family\n"
14925        "Address Family modifier\n"
14926        "Address Family modifier\n"
14927        "Information about Route Server Client\n"
14928        NEIGHBOR_ADDR_STR
14929        "Network in the BGP routing table to display\n")
14930 {
14931   struct bgp *bgp;
14932   struct peer *peer;
14933   safi_t safi;
14934 
14935   /* BGP structure lookup. */
14936   if (argc == 4)
14937     {
14938       bgp = bgp_lookup_by_name (argv[0]);
14939       if (bgp == NULL)
14940 	{
14941 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14942 	  return CMD_WARNING;
14943 	}
14944     }
14945   else
14946     {
14947       bgp = bgp_get_default ();
14948       if (bgp == NULL)
14949 	{
14950 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14951 	  return CMD_WARNING;
14952 	}
14953     }
14954 
14955   if (argc == 4) {
14956     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14957     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14958   } else {
14959     peer = peer_lookup_in_view (vty, NULL, argv[1]);
14960     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14961   }
14962 
14963   if (! peer)
14964     return CMD_WARNING;
14965 
14966   if (! peer->afc[AFI_IP][safi])
14967     {
14968       vty_out (vty, "%% Activate the neighbor for the address family first%s",
14969             VTY_NEWLINE);
14970       return CMD_WARNING;
14971 }
14972 
14973   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14974               PEER_FLAG_RSERVER_CLIENT))
14975     {
14976       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14977             VTY_NEWLINE);
14978       return CMD_WARNING;
14979     }
14980 
14981   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14982                                   (argc == 4) ? argv[3] : argv[2],
14983                                   AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
14984 }
14985 
14986 ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
14987        show_bgp_ipv4_safi_rsclient_route_cmd,
14988        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14989        SHOW_STR
14990        BGP_STR
14991        "Address family\n"
14992        "Address Family modifier\n"
14993        "Address Family modifier\n"
14994        "Information about Route Server Client\n"
14995        NEIGHBOR_ADDR_STR
14996        "Network in the BGP routing table to display\n")
14997 
14998 
14999 DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
15000        show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
15001        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
15002        SHOW_STR
15003        BGP_STR
15004        "BGP view\n"
15005        "View name\n"
15006        "Address family\n"
15007        "Address Family modifier\n"
15008        "Address Family modifier\n"
15009        "Information about Route Server Client\n"
15010        NEIGHBOR_ADDR_STR
15011        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15012 {
15013   struct bgp *bgp;
15014   struct peer *peer;
15015   safi_t safi;
15016 
15017   /* BGP structure lookup. */
15018   if (argc == 4)
15019     {
15020       bgp = bgp_lookup_by_name (argv[0]);
15021       if (bgp == NULL)
15022 	{
15023 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15024 	  return CMD_WARNING;
15025 	}
15026     }
15027   else
15028     {
15029       bgp = bgp_get_default ();
15030       if (bgp == NULL)
15031 	{
15032 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15033 	  return CMD_WARNING;
15034 	}
15035     }
15036 
15037   if (argc == 4) {
15038     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15039     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15040   } else {
15041     peer = peer_lookup_in_view (vty, NULL, argv[1]);
15042     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15043   }
15044 
15045   if (! peer)
15046     return CMD_WARNING;
15047 
15048   if (! peer->afc[AFI_IP][safi])
15049     {
15050       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15051             VTY_NEWLINE);
15052       return CMD_WARNING;
15053 }
15054 
15055   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
15056               PEER_FLAG_RSERVER_CLIENT))
15057 {
15058       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15059             VTY_NEWLINE);
15060     return CMD_WARNING;
15061     }
15062 
15063   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
15064                                   (argc == 4) ? argv[3] : argv[2],
15065                                   AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
15066 }
15067 
15068 DEFUN (show_ip_bgp_view_rsclient_prefix,
15069        show_ip_bgp_view_rsclient_prefix_cmd,
15070        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
15071        SHOW_STR
15072        IP_STR
15073        BGP_STR
15074        "BGP view\n"
15075        "View name\n"
15076        "Information about Route Server Client\n"
15077        NEIGHBOR_ADDR_STR
15078        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15079 {
15080   struct bgp *bgp;
15081   struct peer *peer;
15082 
15083   /* BGP structure lookup. */
15084   if (argc == 3)
15085     {
15086       bgp = bgp_lookup_by_name (argv[0]);
15087       if (bgp == NULL)
15088 	{
15089 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15090 	  return CMD_WARNING;
15091 	}
15092     }
15093   else
15094     {
15095       bgp = bgp_get_default ();
15096       if (bgp == NULL)
15097 	{
15098 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15099 	  return CMD_WARNING;
15100 	}
15101     }
15102 
15103   if (argc == 3)
15104     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15105   else
15106   peer = peer_lookup_in_view (vty, NULL, argv[0]);
15107 
15108   if (! peer)
15109     return CMD_WARNING;
15110 
15111   if (! peer->afc[AFI_IP][SAFI_UNICAST])
15112     {
15113       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15114             VTY_NEWLINE);
15115       return CMD_WARNING;
15116 }
15117 
15118   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
15119               PEER_FLAG_RSERVER_CLIENT))
15120 {
15121       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15122             VTY_NEWLINE);
15123     return CMD_WARNING;
15124     }
15125 
15126   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
15127                                   (argc == 3) ? argv[2] : argv[1],
15128                                   AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
15129 }
15130 
15131 ALIAS (show_ip_bgp_view_rsclient_prefix,
15132        show_ip_bgp_rsclient_prefix_cmd,
15133        "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
15134        SHOW_STR
15135        IP_STR
15136        BGP_STR
15137        "Information about Route Server Client\n"
15138        NEIGHBOR_ADDR_STR
15139        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15140 
15141 ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
15142        show_bgp_ipv4_safi_rsclient_prefix_cmd,
15143        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
15144        SHOW_STR
15145        BGP_STR
15146        "Address family\n"
15147        "Address Family modifier\n"
15148        "Address Family modifier\n"
15149        "Information about Route Server Client\n"
15150        NEIGHBOR_ADDR_STR
15151        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15152 
15153 DEFUN (show_bgp_view_ipv6_neighbor_routes,
15154        show_bgp_view_ipv6_neighbor_routes_cmd,
15155        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
15156        SHOW_STR
15157        BGP_STR
15158        "BGP view\n"
15159        "View name\n"
15160        "Address family\n"
15161        "Detailed information on TCP and BGP neighbor connections\n"
15162        "Neighbor to display information about\n"
15163        "Neighbor to display information about\n"
15164        "Display routes learned from neighbor\n")
15165 {
15166   struct peer *peer;
15167 
15168   if (argc == 2)
15169     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15170   else
15171     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15172 
15173   if (! peer)
15174     return CMD_WARNING;
15175 
15176   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15177 				  bgp_show_type_neighbor);
15178 }
15179 
15180 DEFUN (show_bgp_view_neighbor_damp,
15181        show_bgp_view_neighbor_damp_cmd,
15182        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
15183        SHOW_STR
15184        BGP_STR
15185        "BGP view\n"
15186        "View name\n"
15187        "Detailed information on TCP and BGP neighbor connections\n"
15188        "Neighbor to display information about\n"
15189        "Neighbor to display information about\n"
15190        "Display the dampened routes received from neighbor\n")
15191 {
15192   struct peer *peer;
15193 
15194   if (argc == 2)
15195     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15196   else
15197     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15198 
15199   if (! peer)
15200     return CMD_WARNING;
15201 
15202   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15203 				  bgp_show_type_damp_neighbor);
15204 }
15205 
15206 DEFUN (show_bgp_view_ipv6_neighbor_damp,
15207        show_bgp_view_ipv6_neighbor_damp_cmd,
15208        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
15209        SHOW_STR
15210        BGP_STR
15211        "BGP view\n"
15212        "View name\n"
15213        "Address family\n"
15214        "Detailed information on TCP and BGP neighbor connections\n"
15215        "Neighbor to display information about\n"
15216        "Neighbor to display information about\n"
15217        "Display the dampened routes received from neighbor\n")
15218 {
15219   struct peer *peer;
15220 
15221   if (argc == 2)
15222     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15223   else
15224     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15225 
15226   if (! peer)
15227     return CMD_WARNING;
15228 
15229   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15230 				  bgp_show_type_damp_neighbor);
15231 }
15232 
15233 DEFUN (show_bgp_view_ipv6_neighbor_flap,
15234        show_bgp_view_ipv6_neighbor_flap_cmd,
15235        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
15236        SHOW_STR
15237        BGP_STR
15238        "BGP view\n"
15239        "View name\n"
15240        "Address family\n"
15241        "Detailed information on TCP and BGP neighbor connections\n"
15242        "Neighbor to display information about\n"
15243        "Neighbor to display information about\n"
15244        "Display the dampened routes received from neighbor\n")
15245 {
15246   struct peer *peer;
15247 
15248   if (argc == 2)
15249     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15250   else
15251     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15252 
15253   if (! peer)
15254     return CMD_WARNING;
15255 
15256   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15257 				  bgp_show_type_flap_neighbor);
15258 }
15259 
15260 DEFUN (show_bgp_view_neighbor_flap,
15261        show_bgp_view_neighbor_flap_cmd,
15262        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
15263        SHOW_STR
15264        BGP_STR
15265        "BGP view\n"
15266        "View name\n"
15267        "Detailed information on TCP and BGP neighbor connections\n"
15268        "Neighbor to display information about\n"
15269        "Neighbor to display information about\n"
15270        "Display flap statistics of the routes learned from neighbor\n")
15271 {
15272   struct peer *peer;
15273 
15274   if (argc == 2)
15275     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15276   else
15277     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15278 
15279   if (! peer)
15280     return CMD_WARNING;
15281 
15282   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15283 				  bgp_show_type_flap_neighbor);
15284 }
15285 
15286 ALIAS (show_bgp_view_neighbor_flap,
15287        show_bgp_neighbor_flap_cmd,
15288        "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
15289        SHOW_STR
15290        BGP_STR
15291        "Detailed information on TCP and BGP neighbor connections\n"
15292        "Neighbor to display information about\n"
15293        "Neighbor to display information about\n"
15294        "Display flap statistics of the routes learned from neighbor\n")
15295 
15296 ALIAS (show_bgp_view_neighbor_damp,
15297        show_bgp_neighbor_damp_cmd,
15298        "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
15299        SHOW_STR
15300        BGP_STR
15301        "Detailed information on TCP and BGP neighbor connections\n"
15302        "Neighbor to display information about\n"
15303        "Neighbor to display information about\n"
15304        "Display the dampened routes received from neighbor\n")
15305 
15306 DEFUN (show_bgp_view_neighbor_routes,
15307        show_bgp_view_neighbor_routes_cmd,
15308        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
15309        SHOW_STR
15310        BGP_STR
15311        "BGP view\n"
15312        "View name\n"
15313        "Detailed information on TCP and BGP neighbor connections\n"
15314        "Neighbor to display information about\n"
15315        "Neighbor to display information about\n"
15316        "Display routes learned from neighbor\n")
15317 {
15318   struct peer *peer;
15319 
15320   if (argc == 2)
15321     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15322   else
15323     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15324 
15325   if (! peer)
15326     return CMD_WARNING;
15327 
15328   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
15329 				  bgp_show_type_neighbor);
15330 }
15331 
15332 ALIAS (show_bgp_view_neighbor_routes,
15333        show_bgp_neighbor_routes_cmd,
15334        "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
15335        SHOW_STR
15336        BGP_STR
15337        "Detailed information on TCP and BGP neighbor connections\n"
15338        "Neighbor to display information about\n"
15339        "Neighbor to display information about\n"
15340        "Display routes learned from neighbor\n")
15341 
15342 ALIAS (show_bgp_view_neighbor_routes,
15343        show_bgp_ipv6_neighbor_routes_cmd,
15344        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
15345        SHOW_STR
15346        BGP_STR
15347        "Address family\n"
15348        "Detailed information on TCP and BGP neighbor connections\n"
15349        "Neighbor to display information about\n"
15350        "Neighbor to display information about\n"
15351        "Display routes learned from neighbor\n")
15352 
15353 /* old command */
15354 ALIAS (show_bgp_view_neighbor_routes,
15355        ipv6_bgp_neighbor_routes_cmd,
15356        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
15357        SHOW_STR
15358        IPV6_STR
15359        BGP_STR
15360        "Detailed information on TCP and BGP neighbor connections\n"
15361        "Neighbor to display information about\n"
15362        "Neighbor to display information about\n"
15363        "Display routes learned from neighbor\n")
15364 
15365 /* old command */
15366 DEFUN (ipv6_mbgp_neighbor_routes,
15367        ipv6_mbgp_neighbor_routes_cmd,
15368        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
15369        SHOW_STR
15370        IPV6_STR
15371        MBGP_STR
15372        "Detailed information on TCP and BGP neighbor connections\n"
15373        "Neighbor to display information about\n"
15374        "Neighbor to display information about\n"
15375        "Display routes learned from neighbor\n")
15376 {
15377   struct peer *peer;
15378 
15379   peer = peer_lookup_in_view (vty, NULL, argv[0]);
15380   if (! peer)
15381     return CMD_WARNING;
15382 
15383   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
15384 				  bgp_show_type_neighbor);
15385 }
15386 
15387 ALIAS (show_bgp_view_neighbor_flap,
15388        show_bgp_ipv6_neighbor_flap_cmd,
15389        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
15390        SHOW_STR
15391        BGP_STR
15392        "Address family\n"
15393        "Detailed information on TCP and BGP neighbor connections\n"
15394        "Neighbor to display information about\n"
15395        "Neighbor to display information about\n"
15396        "Display flap statistics of the routes learned from neighbor\n")
15397 
15398 ALIAS (show_bgp_view_neighbor_damp,
15399        show_bgp_ipv6_neighbor_damp_cmd,
15400        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
15401        SHOW_STR
15402        BGP_STR
15403        "Address family\n"
15404        "Detailed information on TCP and BGP neighbor connections\n"
15405        "Neighbor to display information about\n"
15406        "Neighbor to display information about\n"
15407        "Display the dampened routes received from neighbor\n")
15408 
15409 DEFUN (show_bgp_view_rsclient,
15410        show_bgp_view_rsclient_cmd,
15411        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
15412        SHOW_STR
15413        BGP_STR
15414        "BGP view\n"
15415        "View name\n"
15416        "Information about Route Server Client\n"
15417        NEIGHBOR_ADDR_STR)
15418 {
15419   struct bgp_table *table;
15420   struct peer *peer;
15421 
15422   if (argc == 2)
15423     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15424   else
15425     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15426 
15427   if (! peer)
15428     return CMD_WARNING;
15429 
15430   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15431     {
15432       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15433             VTY_NEWLINE);
15434       return CMD_WARNING;
15435     }
15436 
15437   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15438               PEER_FLAG_RSERVER_CLIENT))
15439     {
15440       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15441             VTY_NEWLINE);
15442       return CMD_WARNING;
15443     }
15444 
15445   table = peer->rib[AFI_IP6][SAFI_UNICAST];
15446 
15447   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
15448 }
15449 
15450 ALIAS (show_bgp_view_rsclient,
15451        show_bgp_rsclient_cmd,
15452        "show bgp rsclient (A.B.C.D|X:X::X:X)",
15453        SHOW_STR
15454        BGP_STR
15455        "Information about Route Server Client\n"
15456        NEIGHBOR_ADDR_STR)
15457 
15458 DEFUN (show_bgp_view_ipv4_rsclient,
15459        show_bgp_view_ipv4_rsclient_cmd,
15460        "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
15461        SHOW_STR
15462        BGP_STR
15463        "BGP view\n"
15464        "View name\n"
15465        "Address Family\n"
15466        "Information about Route Server Client\n"
15467        NEIGHBOR_ADDR_STR2)
15468 {
15469   struct bgp_table	*table;
15470   struct peer		*peer;
15471 
15472   if (argc == 2)
15473     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15474   else
15475     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15476 
15477   if (! peer)
15478     return CMD_WARNING;
15479 
15480   if (! peer->afc[AFI_IP][SAFI_UNICAST])
15481     {
15482       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15483             VTY_NEWLINE);
15484       return CMD_WARNING;
15485     }
15486 
15487   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
15488               PEER_FLAG_RSERVER_CLIENT))
15489     {
15490       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15491             VTY_NEWLINE);
15492       return CMD_WARNING;
15493     }
15494 
15495   table = peer->rib[AFI_IP][SAFI_UNICAST];
15496 
15497   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
15498 }
15499 DEFUN (show_bgp_view_ipv6_rsclient,
15500        show_bgp_view_ipv6_rsclient_cmd,
15501        "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
15502        SHOW_STR
15503        BGP_STR
15504        "BGP view\n"
15505        "BGP view name\n"
15506        "Address Family\n"
15507        "Information about Route Server Client\n"
15508        NEIGHBOR_ADDR_STR2)
15509 {
15510   struct bgp_table	*table;
15511   struct peer		*peer;
15512 
15513   if (argc == 2)
15514     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15515   else
15516     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15517 
15518   if (! peer)
15519     return CMD_WARNING;
15520 
15521   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15522     {
15523       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15524             VTY_NEWLINE);
15525       return CMD_WARNING;
15526     }
15527 
15528   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15529               PEER_FLAG_RSERVER_CLIENT))
15530     {
15531       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15532             VTY_NEWLINE);
15533       return CMD_WARNING;
15534     }
15535 
15536   table = peer->rib[AFI_IP6][SAFI_UNICAST];
15537 
15538   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
15539 }
15540 
15541 ALIAS (show_bgp_view_ipv4_rsclient,
15542        show_bgp_ipv4_rsclient_cmd,
15543        "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
15544        SHOW_STR
15545        BGP_STR
15546        "Address Family\n"
15547        "Information about Route Server Client\n"
15548        NEIGHBOR_ADDR_STR2)
15549 
15550 ALIAS (show_bgp_view_ipv6_rsclient,
15551        show_bgp_ipv6_rsclient_cmd,
15552        "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
15553        SHOW_STR
15554        BGP_STR
15555        "Address Family\n"
15556        "Information about Route Server Client\n"
15557        NEIGHBOR_ADDR_STR2)
15558 
15559 DEFUN (show_bgp_view_ipv6_safi_rsclient,
15560        show_bgp_view_ipv6_safi_rsclient_cmd,
15561        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
15562        SHOW_STR
15563        BGP_STR
15564        "BGP view\n"
15565        "View name\n"
15566        "Address family\n"
15567        "Address Family modifier\n"
15568        "Address Family modifier\n"
15569        "Information about Route Server Client\n"
15570        NEIGHBOR_ADDR_STR)
15571 {
15572   struct bgp_table *table;
15573   struct peer *peer;
15574   safi_t safi;
15575 
15576   if (argc == 3) {
15577     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15578     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15579   } else {
15580     peer = peer_lookup_in_view (vty, NULL, argv[1]);
15581     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15582   }
15583 
15584   if (! peer)
15585     return CMD_WARNING;
15586 
15587   if (! peer->afc[AFI_IP6][safi])
15588     {
15589       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15590             VTY_NEWLINE);
15591       return CMD_WARNING;
15592     }
15593 
15594   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15595               PEER_FLAG_RSERVER_CLIENT))
15596     {
15597       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15598             VTY_NEWLINE);
15599       return CMD_WARNING;
15600     }
15601 
15602   table = peer->rib[AFI_IP6][safi];
15603 
15604   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
15605 }
15606 
15607 ALIAS (show_bgp_view_ipv6_safi_rsclient,
15608        show_bgp_ipv6_safi_rsclient_cmd,
15609        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
15610        SHOW_STR
15611        BGP_STR
15612        "Address family\n"
15613        "Address Family modifier\n"
15614        "Address Family modifier\n"
15615        "Information about Route Server Client\n"
15616        NEIGHBOR_ADDR_STR)
15617 
15618 DEFUN (show_bgp_view_rsclient_route,
15619        show_bgp_view_rsclient_route_cmd,
15620        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15621        SHOW_STR
15622        BGP_STR
15623        "BGP view\n"
15624        "View name\n"
15625        "Information about Route Server Client\n"
15626        NEIGHBOR_ADDR_STR
15627        "Network in the BGP routing table to display\n")
15628 {
15629   struct bgp *bgp;
15630   struct peer *peer;
15631 
15632   /* BGP structure lookup. */
15633   if (argc == 3)
15634     {
15635       bgp = bgp_lookup_by_name (argv[0]);
15636       if (bgp == NULL)
15637         {
15638           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15639           return CMD_WARNING;
15640         }
15641     }
15642   else
15643     {
15644       bgp = bgp_get_default ();
15645       if (bgp == NULL)
15646         {
15647           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15648           return CMD_WARNING;
15649         }
15650     }
15651 
15652   if (argc == 3)
15653     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15654   else
15655     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15656 
15657   if (! peer)
15658     return CMD_WARNING;
15659 
15660   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15661     {
15662       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15663             VTY_NEWLINE);
15664       return CMD_WARNING;
15665     }
15666 
15667   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15668               PEER_FLAG_RSERVER_CLIENT))
15669     {
15670       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15671             VTY_NEWLINE);
15672       return CMD_WARNING;
15673     }
15674 
15675   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
15676                                   (argc == 3) ? argv[2] : argv[1],
15677                                   AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
15678 }
15679 
15680 DEFUN (show_bgp_view_ipv6_rsclient_route,
15681        show_bgp_view_ipv6_rsclient_route_cmd,
15682        "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15683        SHOW_STR
15684        BGP_STR
15685        "BGP view\n"
15686        "BGP view name\n"
15687        "IP6_STR"
15688        "Information about Route Server Client\n"
15689        NEIGHBOR_ADDR_STR
15690        "Network in the BGP routing table to display\n")
15691 {
15692   struct bgp *bgp;
15693   struct peer *peer;
15694 
15695   /* BGP structure lookup. */
15696   if (argc == 3)
15697     {
15698       bgp = bgp_lookup_by_name (argv[0]);
15699       if (bgp == NULL)
15700         {
15701           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15702           return CMD_WARNING;
15703         }
15704     }
15705   else
15706     {
15707       bgp = bgp_get_default ();
15708       if (bgp == NULL)
15709         {
15710           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15711           return CMD_WARNING;
15712         }
15713     }
15714 
15715   if (argc == 3)
15716     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15717   else
15718     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15719 
15720   if (! peer)
15721     return CMD_WARNING;
15722 
15723   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15724     {
15725       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15726             VTY_NEWLINE);
15727       return CMD_WARNING;
15728     }
15729 
15730   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15731               PEER_FLAG_RSERVER_CLIENT))
15732     {
15733       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15734             VTY_NEWLINE);
15735       return CMD_WARNING;
15736     }
15737 
15738   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
15739                                   (argc == 3) ? argv[2] : argv[1],
15740                                   AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
15741 }
15742 
15743 ALIAS (show_bgp_view_ipv6_rsclient_route,
15744        show_bgp_rsclient_route_cmd,
15745        "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15746        SHOW_STR
15747        BGP_STR
15748        "Information about Route Server Client\n"
15749        NEIGHBOR_ADDR_STR
15750        "Network in the BGP routing table to display\n")
15751 
15752 ALIAS (show_bgp_view_ipv6_rsclient_route,
15753        show_bgp_ipv6_rsclient_route_cmd,
15754        "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15755        SHOW_STR
15756        BGP_STR
15757        IP6_STR
15758        "Information about Route Server Client\n"
15759        NEIGHBOR_ADDR_STR
15760        "Network in the BGP routing table to display\n")
15761 
15762 DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
15763        show_bgp_view_ipv6_safi_rsclient_route_cmd,
15764        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15765        SHOW_STR
15766        BGP_STR
15767        "BGP view\n"
15768        "View name\n"
15769        "Address family\n"
15770        "Address Family modifier\n"
15771        "Address Family modifier\n"
15772        "Information about Route Server Client\n"
15773        NEIGHBOR_ADDR_STR
15774        "Network in the BGP routing table to display\n")
15775 {
15776   struct bgp *bgp;
15777   struct peer *peer;
15778   safi_t safi;
15779 
15780   /* BGP structure lookup. */
15781   if (argc == 4)
15782     {
15783       bgp = bgp_lookup_by_name (argv[0]);
15784       if (bgp == NULL)
15785 	{
15786 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15787 	  return CMD_WARNING;
15788 	}
15789     }
15790   else
15791     {
15792       bgp = bgp_get_default ();
15793       if (bgp == NULL)
15794 	{
15795 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15796 	  return CMD_WARNING;
15797 	}
15798     }
15799 
15800   if (argc == 4) {
15801     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15802     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15803   } else {
15804     peer = peer_lookup_in_view (vty, NULL, argv[1]);
15805     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15806   }
15807 
15808   if (! peer)
15809     return CMD_WARNING;
15810 
15811   if (! peer->afc[AFI_IP6][safi])
15812     {
15813       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15814             VTY_NEWLINE);
15815       return CMD_WARNING;
15816 }
15817 
15818   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15819               PEER_FLAG_RSERVER_CLIENT))
15820     {
15821       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15822             VTY_NEWLINE);
15823       return CMD_WARNING;
15824     }
15825 
15826   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15827                                   (argc == 4) ? argv[3] : argv[2],
15828                                   AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
15829 }
15830 
15831 ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
15832        show_bgp_ipv6_safi_rsclient_route_cmd,
15833        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
15834        SHOW_STR
15835        BGP_STR
15836        "Address family\n"
15837        "Address Family modifier\n"
15838        "Address Family modifier\n"
15839        "Information about Route Server Client\n"
15840        NEIGHBOR_ADDR_STR
15841        "Network in the BGP routing table to display\n")
15842 
15843 
15844 DEFUN (show_bgp_view_rsclient_prefix,
15845        show_bgp_view_rsclient_prefix_cmd,
15846        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15847        SHOW_STR
15848        BGP_STR
15849        "BGP view\n"
15850        "View name\n"
15851        "Information about Route Server Client\n"
15852        NEIGHBOR_ADDR_STR
15853        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15854 {
15855   struct bgp *bgp;
15856   struct peer *peer;
15857 
15858   /* BGP structure lookup. */
15859   if (argc == 3)
15860     {
15861       bgp = bgp_lookup_by_name (argv[0]);
15862       if (bgp == NULL)
15863         {
15864           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15865           return CMD_WARNING;
15866         }
15867     }
15868   else
15869     {
15870       bgp = bgp_get_default ();
15871       if (bgp == NULL)
15872         {
15873           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15874           return CMD_WARNING;
15875         }
15876     }
15877 
15878   if (argc == 3)
15879     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15880   else
15881     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15882 
15883   if (! peer)
15884     return CMD_WARNING;
15885 
15886   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15887     {
15888       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15889             VTY_NEWLINE);
15890       return CMD_WARNING;
15891     }
15892 
15893   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15894               PEER_FLAG_RSERVER_CLIENT))
15895     {
15896       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15897             VTY_NEWLINE);
15898       return CMD_WARNING;
15899     }
15900 
15901   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
15902                                   (argc == 3) ? argv[2] : argv[1],
15903                                   AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
15904 }
15905 
15906 DEFUN (show_bgp_view_ipv6_rsclient_prefix,
15907        show_bgp_view_ipv6_rsclient_prefix_cmd,
15908        "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15909        SHOW_STR
15910        BGP_STR
15911        "BGP view\n"
15912        "View name\n"
15913        IP6_STR
15914        "Information about Route Server Client\n"
15915        NEIGHBOR_ADDR_STR
15916        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15917 {
15918   struct bgp *bgp;
15919   struct peer *peer;
15920 
15921   /* BGP structure lookup. */
15922   if (argc == 3)
15923     {
15924       bgp = bgp_lookup_by_name (argv[0]);
15925       if (bgp == NULL)
15926         {
15927           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15928           return CMD_WARNING;
15929         }
15930     }
15931   else
15932     {
15933       bgp = bgp_get_default ();
15934       if (bgp == NULL)
15935         {
15936           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15937           return CMD_WARNING;
15938         }
15939     }
15940 
15941   if (argc == 3)
15942     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
15943   else
15944     peer = peer_lookup_in_view (vty, NULL, argv[0]);
15945 
15946   if (! peer)
15947     return CMD_WARNING;
15948 
15949   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
15950     {
15951       vty_out (vty, "%% Activate the neighbor for the address family first%s",
15952             VTY_NEWLINE);
15953       return CMD_WARNING;
15954     }
15955 
15956   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
15957               PEER_FLAG_RSERVER_CLIENT))
15958     {
15959       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15960             VTY_NEWLINE);
15961       return CMD_WARNING;
15962     }
15963 
15964   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
15965                                   (argc == 3) ? argv[2] : argv[1],
15966                                   AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
15967 }
15968 
15969 ALIAS (show_bgp_view_ipv6_rsclient_prefix,
15970        show_bgp_rsclient_prefix_cmd,
15971        "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15972        SHOW_STR
15973        BGP_STR
15974        "Information about Route Server Client\n"
15975        NEIGHBOR_ADDR_STR
15976        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15977 
15978 ALIAS (show_bgp_view_ipv6_rsclient_prefix,
15979        show_bgp_ipv6_rsclient_prefix_cmd,
15980        "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15981        SHOW_STR
15982        BGP_STR
15983        "Information about Route Server Client\n"
15984        NEIGHBOR_ADDR_STR
15985        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15986 
15987 DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15988        show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15989        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15990        SHOW_STR
15991        BGP_STR
15992        "BGP view\n"
15993        "View name\n"
15994        "Address family\n"
15995        "Address Family modifier\n"
15996        "Address Family modifier\n"
15997        "Information about Route Server Client\n"
15998        NEIGHBOR_ADDR_STR
15999        "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
16000 {
16001   struct bgp *bgp;
16002   struct peer *peer;
16003   safi_t safi;
16004 
16005   /* BGP structure lookup. */
16006   if (argc == 4)
16007     {
16008       bgp = bgp_lookup_by_name (argv[0]);
16009       if (bgp == NULL)
16010 	{
16011 	  vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
16012 	  return CMD_WARNING;
16013 	}
16014     }
16015   else
16016     {
16017       bgp = bgp_get_default ();
16018       if (bgp == NULL)
16019 	{
16020 	  vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
16021 	  return CMD_WARNING;
16022 	}
16023     }
16024 
16025   if (argc == 4) {
16026     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
16027     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
16028   } else {
16029     peer = peer_lookup_in_view (vty, NULL, argv[1]);
16030     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
16031   }
16032 
16033   if (! peer)
16034     return CMD_WARNING;
16035 
16036   if (! peer->afc[AFI_IP6][safi])
16037     {
16038       vty_out (vty, "%% Activate the neighbor for the address family first%s",
16039             VTY_NEWLINE);
16040       return CMD_WARNING;
16041 }
16042 
16043   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
16044               PEER_FLAG_RSERVER_CLIENT))
16045 {
16046       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
16047             VTY_NEWLINE);
16048     return CMD_WARNING;
16049     }
16050 
16051   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
16052                                   (argc == 4) ? argv[3] : argv[2],
16053                                   AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
16054 }
16055 
16056 ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
16057        show_bgp_ipv6_safi_rsclient_prefix_cmd,
16058        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
16059        SHOW_STR
16060        BGP_STR
16061        "Address family\n"
16062        "Address Family modifier\n"
16063        "Address Family modifier\n"
16064        "Information about Route Server Client\n"
16065        NEIGHBOR_ADDR_STR
16066        "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
16067 
16068 struct bgp_table *bgp_distance_table;
16069 
16070 struct bgp_distance
16071 {
16072   /* Distance value for the IP source prefix. */
16073   u_char distance;
16074 
16075   /* Name of the access-list to be matched. */
16076   char *access_list;
16077 };
16078 
16079 static struct bgp_distance *
bgp_distance_new(void)16080 bgp_distance_new (void)
16081 {
16082   return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
16083 }
16084 
16085 static void
bgp_distance_free(struct bgp_distance * bdistance)16086 bgp_distance_free (struct bgp_distance *bdistance)
16087 {
16088   XFREE (MTYPE_BGP_DISTANCE, bdistance);
16089 }
16090 
16091 /* XXX: Ideally, this should re-announce affected routes to zebra.
16092  * See Bugzilla #949
16093  */
16094 static int
bgp_distance_set(struct vty * vty,const char * distance_str,const char * ip_str,const char * access_list_str)16095 bgp_distance_set (struct vty *vty, const char *distance_str,
16096                   const char *ip_str, const char *access_list_str)
16097 {
16098   int ret;
16099   struct prefix p;
16100   u_char distance;
16101   struct bgp_node *rn;
16102   struct bgp_distance *bdistance;
16103 
16104   ret = str2prefix (ip_str, &p);
16105   if (ret == 0)
16106     {
16107       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
16108       return CMD_WARNING;
16109     }
16110 
16111   distance = atoi (distance_str);
16112 
16113   /* Get BGP distance node. */
16114   rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
16115   if (rn->info)
16116     {
16117       bdistance = rn->info;
16118       bgp_unlock_node (rn);
16119     }
16120   else
16121     {
16122       bdistance = bgp_distance_new ();
16123       rn->info = bdistance;
16124     }
16125 
16126   /* Set distance value. */
16127   bdistance->distance = distance;
16128 
16129   /* Reset access-list configuration. */
16130   if (bdistance->access_list)
16131     {
16132       free (bdistance->access_list);
16133       bdistance->access_list = NULL;
16134     }
16135   if (access_list_str)
16136     bdistance->access_list = strdup (access_list_str);
16137 
16138   return CMD_SUCCESS;
16139 }
16140 
16141 static int
bgp_distance_unset(struct vty * vty,const char * distance_str,const char * ip_str,const char * access_list_str)16142 bgp_distance_unset (struct vty *vty, const char *distance_str,
16143                     const char *ip_str, const char *access_list_str)
16144 {
16145   int ret;
16146   struct prefix p;
16147   u_char distance;
16148   struct bgp_node *rn;
16149   struct bgp_distance *bdistance;
16150 
16151   ret = str2prefix (ip_str, &p);
16152   if (ret == 0)
16153     {
16154       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
16155       return CMD_WARNING;
16156     }
16157 
16158   distance = atoi (distance_str);
16159 
16160   rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
16161   if (! rn)
16162     {
16163       vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
16164       return CMD_WARNING;
16165     }
16166 
16167   bdistance = rn->info;
16168 
16169   if (bdistance->distance != distance)
16170     {
16171        vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
16172        return CMD_WARNING;
16173     }
16174 
16175   if (bdistance->access_list)
16176     free (bdistance->access_list);
16177   bgp_distance_free (bdistance);
16178 
16179   rn->info = NULL;
16180   bgp_unlock_node (rn);
16181   bgp_unlock_node (rn);
16182 
16183   return CMD_SUCCESS;
16184 }
16185 
16186 /* Apply BGP information to distance method. */
16187 u_char
bgp_distance_apply(struct prefix * p,struct bgp_info * rinfo,struct bgp * bgp)16188 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
16189 {
16190   struct bgp_node *rn;
16191   struct prefix_ipv4 q;
16192   struct peer *peer;
16193   struct bgp_distance *bdistance;
16194   struct access_list *alist;
16195   struct bgp_static *bgp_static;
16196 
16197   if (! bgp)
16198     return 0;
16199 
16200   if (p->family != AF_INET)
16201     return 0;
16202 
16203   peer = rinfo->peer;
16204 
16205   if (peer->su.sa.sa_family != AF_INET)
16206     return 0;
16207 
16208   memset (&q, 0, sizeof (struct prefix_ipv4));
16209   q.family = AF_INET;
16210   q.prefix = peer->su.sin.sin_addr;
16211   q.prefixlen = IPV4_MAX_BITLEN;
16212 
16213   /* Check source address. */
16214   rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
16215   if (rn)
16216     {
16217       bdistance = rn->info;
16218       bgp_unlock_node (rn);
16219 
16220       if (bdistance->access_list)
16221 	{
16222 	  alist = access_list_lookup (AFI_IP, bdistance->access_list);
16223 	  if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
16224 	    return bdistance->distance;
16225 	}
16226       else
16227 	return bdistance->distance;
16228     }
16229 
16230   /* Backdoor check. */
16231   rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
16232   if (rn)
16233     {
16234       bgp_static = rn->info;
16235       bgp_unlock_node (rn);
16236 
16237       if (bgp_static->backdoor)
16238 	{
16239 	  if (bgp->distance_local)
16240 	    return bgp->distance_local;
16241 	  else
16242 	    return ZEBRA_IBGP_DISTANCE_DEFAULT;
16243 	}
16244     }
16245 
16246   if (peer->sort == BGP_PEER_EBGP)
16247     {
16248       if (bgp->distance_ebgp)
16249 	return bgp->distance_ebgp;
16250       return ZEBRA_EBGP_DISTANCE_DEFAULT;
16251     }
16252   else
16253     {
16254       if (bgp->distance_ibgp)
16255 	return bgp->distance_ibgp;
16256       return ZEBRA_IBGP_DISTANCE_DEFAULT;
16257     }
16258 }
16259 
16260 #ifdef HAVE_IPV6
16261 /* Apply BGP information to ipv6 distance method. */
16262 u_char
ipv6_bgp_distance_apply(struct prefix * p,struct bgp_info * rinfo,struct bgp * bgp)16263 ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
16264 {
16265   struct bgp_node *rn;
16266   struct prefix_ipv6 q;
16267   struct peer *peer;
16268   struct bgp_distance *bdistance;
16269   struct access_list *alist;
16270   struct bgp_static *bgp_static;
16271 
16272   if (! bgp)
16273     return 0;
16274 
16275   if (p->family != AF_INET6)
16276     return 0;
16277 
16278   peer = rinfo->peer;
16279 
16280   if (peer->su.sa.sa_family != AF_INET6)
16281     return 0;
16282 
16283   memset (&q, 0, sizeof (struct prefix_ipv6));
16284   q.family = AF_INET;
16285   q.prefix = peer->su.sin6.sin6_addr;
16286   q.prefixlen = IPV6_MAX_BITLEN;
16287 
16288   /* Check source address. */
16289   rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
16290   if (rn)
16291     {
16292       bdistance = rn->info;
16293       bgp_unlock_node (rn);
16294 
16295       if (bdistance->access_list)
16296         {
16297           alist = access_list_lookup (AFI_IP6, bdistance->access_list);
16298           if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
16299             return bdistance->distance;
16300         }
16301       else
16302         return bdistance->distance;
16303     }
16304   /* Backdoor check. */
16305   rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
16306   if (rn)
16307     {
16308       bgp_static = rn->info;
16309       bgp_unlock_node (rn);
16310 
16311       if (bgp_static->backdoor)
16312         {
16313           if (bgp->ipv6_distance_local)
16314             return bgp->ipv6_distance_local;
16315           else
16316             return ZEBRA_IBGP_DISTANCE_DEFAULT;
16317         }
16318     }
16319 
16320   if (peer_sort (peer) == BGP_PEER_EBGP)
16321     {
16322       if (bgp->ipv6_distance_ebgp)
16323         return bgp->ipv6_distance_ebgp;
16324       return ZEBRA_EBGP_DISTANCE_DEFAULT;
16325     }
16326   else
16327     {
16328       if (bgp->ipv6_distance_ibgp)
16329         return bgp->ipv6_distance_ibgp;
16330       return ZEBRA_IBGP_DISTANCE_DEFAULT;
16331     }
16332 }
16333 #endif /* HAVE_IPV6 */
16334 
16335 DEFUN (bgp_distance,
16336        bgp_distance_cmd,
16337        "distance bgp <1-255> <1-255> <1-255>",
16338        "Define an administrative distance\n"
16339        "BGP distance\n"
16340        "Distance for routes external to the AS\n"
16341        "Distance for routes internal to the AS\n"
16342        "Distance for local routes\n")
16343 {
16344   struct bgp *bgp;
16345 
16346   bgp = vty->index;
16347 
16348   bgp->distance_ebgp = atoi (argv[0]);
16349   bgp->distance_ibgp = atoi (argv[1]);
16350   bgp->distance_local = atoi (argv[2]);
16351   return CMD_SUCCESS;
16352 }
16353 
16354 DEFUN (no_bgp_distance,
16355        no_bgp_distance_cmd,
16356        "no distance bgp <1-255> <1-255> <1-255>",
16357        NO_STR
16358        "Define an administrative distance\n"
16359        "BGP distance\n"
16360        "Distance for routes external to the AS\n"
16361        "Distance for routes internal to the AS\n"
16362        "Distance for local routes\n")
16363 {
16364   struct bgp *bgp;
16365 
16366   bgp = vty->index;
16367 
16368   bgp->distance_ebgp= 0;
16369   bgp->distance_ibgp = 0;
16370   bgp->distance_local = 0;
16371   return CMD_SUCCESS;
16372 }
16373 
16374 ALIAS (no_bgp_distance,
16375        no_bgp_distance2_cmd,
16376        "no distance bgp",
16377        NO_STR
16378        "Define an administrative distance\n"
16379        "BGP distance\n")
16380 
16381 DEFUN (bgp_distance_source,
16382        bgp_distance_source_cmd,
16383        "distance <1-255> A.B.C.D/M",
16384        "Define an administrative distance\n"
16385        "Administrative distance\n"
16386        "IP source prefix\n")
16387 {
16388   bgp_distance_set (vty, argv[0], argv[1], NULL);
16389   return CMD_SUCCESS;
16390 }
16391 
16392 DEFUN (no_bgp_distance_source,
16393        no_bgp_distance_source_cmd,
16394        "no distance <1-255> A.B.C.D/M",
16395        NO_STR
16396        "Define an administrative distance\n"
16397        "Administrative distance\n"
16398        "IP source prefix\n")
16399 {
16400   bgp_distance_unset (vty, argv[0], argv[1], NULL);
16401   return CMD_SUCCESS;
16402 }
16403 
16404 DEFUN (bgp_distance_source_access_list,
16405        bgp_distance_source_access_list_cmd,
16406        "distance <1-255> A.B.C.D/M WORD",
16407        "Define an administrative distance\n"
16408        "Administrative distance\n"
16409        "IP source prefix\n"
16410        "Access list name\n")
16411 {
16412   bgp_distance_set (vty, argv[0], argv[1], argv[2]);
16413   return CMD_SUCCESS;
16414 }
16415 
16416 DEFUN (no_bgp_distance_source_access_list,
16417        no_bgp_distance_source_access_list_cmd,
16418        "no distance <1-255> A.B.C.D/M WORD",
16419        NO_STR
16420        "Define an administrative distance\n"
16421        "Administrative distance\n"
16422        "IP source prefix\n"
16423        "Access list name\n")
16424 {
16425   bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
16426   return CMD_SUCCESS;
16427 }
16428 
16429 #ifdef HAVE_IPV6
16430 DEFUN (ipv6_bgp_distance,
16431        ipv6_bgp_distance_cmd,
16432        "distance bgp <1-255> <1-255> <1-255>",
16433        "Define an administrative distance\n"
16434        "BGP distance\n"
16435        "Distance for routes external to the AS\n"
16436        "Distance for routes internal to the AS\n"
16437        "Distance for local routes\n")
16438 {
16439   struct bgp *bgp;
16440 
16441   bgp = vty->index;
16442 
16443   bgp->ipv6_distance_ebgp = atoi (argv[0]);
16444   bgp->ipv6_distance_ibgp = atoi (argv[1]);
16445   bgp->ipv6_distance_local = atoi (argv[2]);
16446   return CMD_SUCCESS;
16447 }
16448 
16449 DEFUN (no_ipv6_bgp_distance,
16450        no_ipv6_bgp_distance_cmd,
16451        "no distance bgp <1-255> <1-255> <1-255>",
16452        NO_STR
16453        "Define an administrative distance\n"
16454        "BGP distance\n"
16455        "Distance for routes external to the AS\n"
16456        "Distance for routes internal to the AS\n"
16457        "Distance for local routes\n")
16458 {
16459   struct bgp *bgp;
16460 
16461   bgp = vty->index;
16462 
16463   bgp->ipv6_distance_ebgp= 0;
16464   bgp->ipv6_distance_ibgp = 0;
16465   bgp->ipv6_distance_local = 0;
16466   return CMD_SUCCESS;
16467 }
16468 
16469 ALIAS (no_ipv6_bgp_distance,
16470        no_ipv6_bgp_distance2_cmd,
16471        "no distance bgp",
16472        NO_STR
16473        "Define an administrative distance\n"
16474        "BGP distance\n")
16475 
16476 DEFUN (ipv6_bgp_distance_source,
16477        ipv6_bgp_distance_source_cmd,
16478        "distance <1-255> X:X::X:X/M",
16479        "Define an administrative distance\n"
16480        "Administrative distance\n"
16481        "IP source prefix\n")
16482 {
16483   bgp_distance_set (vty, argv[0], argv[1], NULL);
16484   return CMD_SUCCESS;
16485 }
16486 
16487 DEFUN (no_ipv6_bgp_distance_source,
16488        no_ipv6_bgp_distance_source_cmd,
16489        "no distance <1-255> X:X::X:X/M",
16490        NO_STR
16491        "Define an administrative distance\n"
16492        "Administrative distance\n"
16493        "IP source prefix\n")
16494 {
16495   bgp_distance_unset (vty, argv[0], argv[1], NULL);
16496   return CMD_SUCCESS;
16497 }
16498 
16499 DEFUN (ipv6_bgp_distance_source_access_list,
16500        ipv6_bgp_distance_source_access_list_cmd,
16501        "distance <1-255> X:X::X:X/M WORD",
16502        "Define an administrative distance\n"
16503        "Administrative distance\n"
16504        "IP source prefix\n"
16505        "Access list name\n")
16506 {
16507   bgp_distance_set (vty, argv[0], argv[1], argv[2]);
16508   return CMD_SUCCESS;
16509 }
16510 
16511 DEFUN (no_ipv6_bgp_distance_source_access_list,
16512        no_ipv6_bgp_distance_source_access_list_cmd,
16513        "no distance <1-255> X:X::X:X/M WORD",
16514        NO_STR
16515        "Define an administrative distance\n"
16516        "Administrative distance\n"
16517        "IP source prefix\n"
16518        "Access list name\n")
16519 {
16520   bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
16521   return CMD_SUCCESS;
16522 }
16523 #endif
16524 
16525 DEFUN (bgp_damp_set,
16526        bgp_damp_set_cmd,
16527        "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
16528        "BGP Specific commands\n"
16529        "Enable route-flap dampening\n"
16530        "Half-life time for the penalty\n"
16531        "Value to start reusing a route\n"
16532        "Value to start suppressing a route\n"
16533        "Maximum duration to suppress a stable route\n")
16534 {
16535   struct bgp *bgp;
16536   int half = DEFAULT_HALF_LIFE * 60;
16537   int reuse = DEFAULT_REUSE;
16538   int suppress = DEFAULT_SUPPRESS;
16539   int max = 4 * half;
16540 
16541   if (argc == 4)
16542     {
16543       half = atoi (argv[0]) * 60;
16544       reuse = atoi (argv[1]);
16545       suppress = atoi (argv[2]);
16546       max = atoi (argv[3]) * 60;
16547     }
16548   else if (argc == 1)
16549     {
16550       half = atoi (argv[0]) * 60;
16551       max = 4 * half;
16552     }
16553 
16554   bgp = vty->index;
16555 
16556   if (suppress < reuse)
16557     {
16558       vty_out (vty, "Suppress value cannot be less than reuse value %s",
16559                     VTY_NEWLINE);
16560       return 0;
16561     }
16562 
16563   return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
16564 			  half, reuse, suppress, max);
16565 }
16566 
16567 ALIAS (bgp_damp_set,
16568        bgp_damp_set2_cmd,
16569        "bgp dampening <1-45>",
16570        "BGP Specific commands\n"
16571        "Enable route-flap dampening\n"
16572        "Half-life time for the penalty\n")
16573 
16574 ALIAS (bgp_damp_set,
16575        bgp_damp_set3_cmd,
16576        "bgp dampening",
16577        "BGP Specific commands\n"
16578        "Enable route-flap dampening\n")
16579 
16580 DEFUN (bgp_damp_unset,
16581        bgp_damp_unset_cmd,
16582        "no bgp dampening",
16583        NO_STR
16584        "BGP Specific commands\n"
16585        "Enable route-flap dampening\n")
16586 {
16587   struct bgp *bgp;
16588 
16589   bgp = vty->index;
16590   return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
16591 }
16592 
16593 ALIAS (bgp_damp_unset,
16594        bgp_damp_unset2_cmd,
16595        "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
16596        NO_STR
16597        "BGP Specific commands\n"
16598        "Enable route-flap dampening\n"
16599        "Half-life time for the penalty\n"
16600        "Value to start reusing a route\n"
16601        "Value to start suppressing a route\n"
16602        "Maximum duration to suppress a stable route\n")
16603 
16604 DEFUN (show_ip_bgp_dampened_paths,
16605        show_ip_bgp_dampened_paths_cmd,
16606        "show ip bgp dampened-paths",
16607        SHOW_STR
16608        IP_STR
16609        BGP_STR
16610        "Display paths suppressed due to dampening\n")
16611 {
16612   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
16613                    NULL);
16614 }
16615 
16616 ALIAS (show_ip_bgp_dampened_paths,
16617        show_ip_bgp_damp_dampened_paths_cmd,
16618        "show ip bgp dampening dampened-paths",
16619        SHOW_STR
16620        IP_STR
16621        BGP_STR
16622        "Display detailed information about dampening\n"
16623        "Display paths suppressed due to dampening\n")
16624 
16625 DEFUN (show_ip_bgp_flap_statistics,
16626        show_ip_bgp_flap_statistics_cmd,
16627        "show ip bgp flap-statistics",
16628        SHOW_STR
16629        IP_STR
16630        BGP_STR
16631        "Display flap statistics of routes\n")
16632 {
16633   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
16634                    bgp_show_type_flap_statistics, NULL);
16635 }
16636 
16637 ALIAS (show_ip_bgp_flap_statistics,
16638        show_ip_bgp_damp_flap_statistics_cmd,
16639        "show ip bgp dampening flap-statistics",
16640        SHOW_STR
16641        IP_STR
16642        BGP_STR
16643        "Display detailed information about dampening\n"
16644        "Display flap statistics of routes\n")
16645 
16646 DEFUN (show_bgp_ipv4_safi_dampened_paths,
16647        show_bgp_ipv4_safi_dampened_paths_cmd,
16648        "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
16649        SHOW_STR
16650        BGP_STR
16651        IP_STR
16652        "Address Family modifier\n"
16653        "Address Family modifier\n"
16654        "Address Family modifier\n"
16655        "Address Family modifier\n"
16656        "Display paths suppressed due to dampening\n")
16657 {
16658   safi_t	safi;
16659 
16660   if (bgp_parse_safi(argv[0], &safi)) {
16661     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
16662     return CMD_WARNING;
16663   }
16664 
16665   return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
16666 }
16667 ALIAS (show_bgp_ipv4_safi_dampened_paths,
16668        show_bgp_ipv4_safi_damp_dampened_paths_cmd,
16669        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
16670        SHOW_STR
16671        BGP_STR
16672        IP_STR
16673        "Address Family modifier\n"
16674        "Address Family modifier\n"
16675        "Address Family modifier\n"
16676        "Address Family modifier\n"
16677        "Display detailed information about dampening\n"
16678        "Display paths suppressed due to dampening\n")
16679 
16680 DEFUN (show_bgp_ipv6_safi_dampened_paths,
16681        show_bgp_ipv6_safi_dampened_paths_cmd,
16682        "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
16683        SHOW_STR
16684        BGP_STR
16685        IPV6_STR
16686        "Address Family modifier\n"
16687        "Address Family modifier\n"
16688        "Address Family modifier\n"
16689        "Address Family modifier\n"
16690        "Display paths suppressed due to dampening\n")
16691 {
16692   safi_t	safi;
16693 
16694   if (bgp_parse_safi(argv[0], &safi)) {
16695     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
16696     return CMD_WARNING;
16697   }
16698 
16699   return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
16700 }
16701 ALIAS (show_bgp_ipv6_safi_dampened_paths,
16702        show_bgp_ipv6_safi_damp_dampened_paths_cmd,
16703        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
16704        SHOW_STR
16705        BGP_STR
16706        IPV6_STR
16707        "Address Family modifier\n"
16708        "Address Family modifier\n"
16709        "Address Family modifier\n"
16710        "Address Family modifier\n"
16711        "Display detailed information about dampening\n"
16712        "Display paths suppressed due to dampening\n")
16713 
16714 DEFUN (show_bgp_ipv4_safi_flap_statistics,
16715        show_bgp_ipv4_safi_flap_statistics_cmd,
16716        "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
16717        SHOW_STR
16718        BGP_STR
16719        "Address Family\n"
16720        "Address Family modifier\n"
16721        "Address Family modifier\n"
16722        "Address Family modifier\n"
16723        "Address Family modifier\n"
16724        "Display flap statistics of routes\n")
16725 {
16726   safi_t	safi;
16727 
16728   if (bgp_parse_safi(argv[0], &safi)) {
16729     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
16730     return CMD_WARNING;
16731   }
16732 
16733   return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
16734 }
16735 ALIAS (show_bgp_ipv4_safi_flap_statistics,
16736        show_bgp_ipv4_safi_damp_flap_statistics_cmd,
16737        "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
16738        SHOW_STR
16739        BGP_STR
16740        "Address Family\n"
16741        "Address Family modifier\n"
16742        "Address Family modifier\n"
16743        "Address Family modifier\n"
16744        "Address Family modifier\n"
16745        "Display detailed information about dampening\n"
16746        "Display flap statistics of routes\n")
16747 
16748 DEFUN (show_bgp_ipv6_safi_flap_statistics,
16749        show_bgp_ipv6_safi_flap_statistics_cmd,
16750        "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
16751        SHOW_STR
16752        BGP_STR
16753        "Address Family\n"
16754        "Address Family modifier\n"
16755        "Address Family modifier\n"
16756        "Address Family modifier\n"
16757        "Address Family modifier\n"
16758        "Display flap statistics of routes\n")
16759 {
16760   safi_t	safi;
16761 
16762   if (bgp_parse_safi(argv[0], &safi)) {
16763     vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
16764     return CMD_WARNING;
16765   }
16766 
16767   return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
16768 }
16769 ALIAS (show_bgp_ipv6_safi_flap_statistics,
16770        show_bgp_ipv6_safi_damp_flap_statistics_cmd,
16771        "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
16772        SHOW_STR
16773        BGP_STR
16774        "Address Family\n"
16775        "Address Family modifier\n"
16776        "Address Family modifier\n"
16777        "Address Family modifier\n"
16778        "Address Family modifier\n"
16779        "Display detailed information about dampening\n"
16780        "Display flap statistics of routes\n")
16781 
16782 /* Display specified route of BGP table. */
16783 static int
bgp_clear_damp_route(struct vty * vty,const char * view_name,const char * ip_str,afi_t afi,safi_t safi,struct prefix_rd * prd,int prefix_check)16784 bgp_clear_damp_route (struct vty *vty, const char *view_name,
16785                       const char *ip_str, afi_t afi, safi_t safi,
16786                       struct prefix_rd *prd, int prefix_check)
16787 {
16788   int ret;
16789   struct prefix match;
16790   struct bgp_node *rn;
16791   struct bgp_node *rm;
16792   struct bgp_info *ri;
16793   struct bgp_info *ri_temp;
16794   struct bgp *bgp;
16795   struct bgp_table *table;
16796 
16797   /* BGP structure lookup. */
16798   if (view_name)
16799     {
16800       bgp = bgp_lookup_by_name (view_name);
16801       if (bgp == NULL)
16802 	{
16803 	  vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
16804 	  return CMD_WARNING;
16805 	}
16806     }
16807   else
16808     {
16809       bgp = bgp_get_default ();
16810       if (bgp == NULL)
16811 	{
16812 	  vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
16813 	  return CMD_WARNING;
16814 	}
16815     }
16816 
16817   /* Check IP address argument. */
16818   ret = str2prefix (ip_str, &match);
16819   if (! ret)
16820     {
16821       vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
16822       return CMD_WARNING;
16823     }
16824 
16825   match.family = afi2family (afi);
16826 
16827   if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
16828     {
16829       for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
16830         {
16831           if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
16832             continue;
16833 
16834 	  if ((table = rn->info) != NULL)
16835 	    if ((rm = bgp_node_match (table, &match)) != NULL)
16836               {
16837                 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
16838                   {
16839                     ri = rm->info;
16840                     while (ri)
16841                       {
16842                         if (ri->extra && ri->extra->damp_info)
16843                           {
16844                             ri_temp = ri->next;
16845                             bgp_damp_info_free (ri->extra->damp_info, 1);
16846                             ri = ri_temp;
16847                           }
16848                         else
16849                           ri = ri->next;
16850                       }
16851                   }
16852 
16853                 bgp_unlock_node (rm);
16854               }
16855         }
16856     }
16857   else
16858     {
16859       if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
16860         {
16861           if (! prefix_check || rn->p.prefixlen == match.prefixlen)
16862             {
16863               ri = rn->info;
16864               while (ri)
16865                 {
16866                   if (ri->extra && ri->extra->damp_info)
16867                     {
16868                       ri_temp = ri->next;
16869                       bgp_damp_info_free (ri->extra->damp_info, 1);
16870                       ri = ri_temp;
16871                     }
16872                   else
16873                     ri = ri->next;
16874                 }
16875             }
16876 
16877           bgp_unlock_node (rn);
16878         }
16879     }
16880 
16881   return CMD_SUCCESS;
16882 }
16883 
16884 DEFUN (clear_ip_bgp_dampening,
16885        clear_ip_bgp_dampening_cmd,
16886        "clear ip bgp dampening",
16887        CLEAR_STR
16888        IP_STR
16889        BGP_STR
16890        "Clear route flap dampening information\n")
16891 {
16892   bgp_damp_info_clean ();
16893   return CMD_SUCCESS;
16894 }
16895 
16896 DEFUN (clear_ip_bgp_dampening_prefix,
16897        clear_ip_bgp_dampening_prefix_cmd,
16898        "clear ip bgp dampening A.B.C.D/M",
16899        CLEAR_STR
16900        IP_STR
16901        BGP_STR
16902        "Clear route flap dampening information\n"
16903        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
16904 {
16905   return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
16906 			       SAFI_UNICAST, NULL, 1);
16907 }
16908 
16909 DEFUN (clear_ip_bgp_dampening_address,
16910        clear_ip_bgp_dampening_address_cmd,
16911        "clear ip bgp dampening A.B.C.D",
16912        CLEAR_STR
16913        IP_STR
16914        BGP_STR
16915        "Clear route flap dampening information\n"
16916        "Network to clear damping information\n")
16917 {
16918   return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
16919 			       SAFI_UNICAST, NULL, 0);
16920 }
16921 
16922 DEFUN (clear_ip_bgp_dampening_address_mask,
16923        clear_ip_bgp_dampening_address_mask_cmd,
16924        "clear ip bgp dampening A.B.C.D A.B.C.D",
16925        CLEAR_STR
16926        IP_STR
16927        BGP_STR
16928        "Clear route flap dampening information\n"
16929        "Network to clear damping information\n"
16930        "Network mask\n")
16931 {
16932   int ret;
16933   char prefix_str[BUFSIZ];
16934 
16935   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
16936   if (! ret)
16937     {
16938       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
16939       return CMD_WARNING;
16940     }
16941 
16942   return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
16943 			       SAFI_UNICAST, NULL, 0);
16944 }
16945 
16946 /* also used for encap safi */
16947 static int
bgp_config_write_network_vpnv4(struct vty * vty,struct bgp * bgp,afi_t afi,safi_t safi,int * write)16948 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
16949 				afi_t afi, safi_t safi, int *write)
16950 {
16951   struct bgp_node *prn;
16952   struct bgp_node *rn;
16953   struct bgp_table *table;
16954   struct prefix *p;
16955   struct prefix_rd *prd;
16956   struct bgp_static *bgp_static;
16957   u_int32_t label;
16958   char buf[SU_ADDRSTRLEN];
16959   char rdbuf[RD_ADDRSTRLEN];
16960 
16961   /* Network configuration. */
16962   for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
16963     if ((table = prn->info) != NULL)
16964       for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
16965 	if ((bgp_static = rn->info) != NULL)
16966 	  {
16967 	    p = &rn->p;
16968 	    prd = (struct prefix_rd *) &prn->p;
16969 
16970 	    /* "address-family" display.  */
16971 	    bgp_config_write_family_header (vty, afi, safi, write);
16972 
16973 	    /* "network" configuration display.  */
16974 	    prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
16975 	    label = decode_label (bgp_static->tag);
16976 
16977 	    vty_out (vty, " network %s/%d rd %s tag %d",
16978 		     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16979 		     p->prefixlen,
16980 		     rdbuf, label);
16981 	    vty_out (vty, "%s", VTY_NEWLINE);
16982 	  }
16983   return 0;
16984 }
16985 
16986 /* Configuration of static route announcement and aggregate
16987    information. */
16988 int
bgp_config_write_network(struct vty * vty,struct bgp * bgp,afi_t afi,safi_t safi,int * write)16989 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
16990 			  afi_t afi, safi_t safi, int *write)
16991 {
16992   struct bgp_node *rn;
16993   struct prefix *p;
16994   struct bgp_static *bgp_static;
16995   struct bgp_aggregate *bgp_aggregate;
16996   char buf[SU_ADDRSTRLEN];
16997 
16998   if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
16999     return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
17000 
17001   /* Network configuration. */
17002   for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
17003     if ((bgp_static = rn->info) != NULL)
17004       {
17005 	p = &rn->p;
17006 
17007 	/* "address-family" display.  */
17008 	bgp_config_write_family_header (vty, afi, safi, write);
17009 
17010 	/* "network" configuration display.  */
17011 	if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
17012 	  {
17013 	    u_int32_t destination;
17014 	    struct in_addr netmask;
17015 
17016 	    destination = ntohl (p->u.prefix4.s_addr);
17017 	    masklen2ip (p->prefixlen, &netmask);
17018 	    vty_out (vty, " network %s",
17019 		     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
17020 
17021 	    if ((IN_CLASSC (destination) && p->prefixlen == 24)
17022 		|| (IN_CLASSB (destination) && p->prefixlen == 16)
17023 		|| (IN_CLASSA (destination) && p->prefixlen == 8)
17024 		|| p->u.prefix4.s_addr == 0)
17025 	      {
17026 		/* Natural mask is not display. */
17027 	      }
17028 	    else
17029 	      vty_out (vty, " mask %s", inet_ntoa (netmask));
17030 	  }
17031 	else
17032 	  {
17033 	    vty_out (vty, " network %s/%d",
17034 		     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
17035 		     p->prefixlen);
17036 	  }
17037 
17038 	if (bgp_static->rmap.name)
17039 	  vty_out (vty, " route-map %s", bgp_static->rmap.name);
17040 	else
17041 	  {
17042 	    if (bgp_static->backdoor)
17043 	      vty_out (vty, " backdoor");
17044           }
17045 
17046 	vty_out (vty, "%s", VTY_NEWLINE);
17047       }
17048 
17049   /* Aggregate-address configuration. */
17050   for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
17051     if ((bgp_aggregate = rn->info) != NULL)
17052       {
17053 	p = &rn->p;
17054 
17055 	/* "address-family" display.  */
17056 	bgp_config_write_family_header (vty, afi, safi, write);
17057 
17058 	if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
17059 	  {
17060 	    struct in_addr netmask;
17061 
17062 	    masklen2ip (p->prefixlen, &netmask);
17063 	    vty_out (vty, " aggregate-address %s %s",
17064 		     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
17065 		     inet_ntoa (netmask));
17066 	  }
17067 	else
17068 	  {
17069 	    vty_out (vty, " aggregate-address %s/%d",
17070 		     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
17071 		     p->prefixlen);
17072 	  }
17073 
17074 	if (bgp_aggregate->as_set)
17075 	  vty_out (vty, " as-set");
17076 
17077 	if (bgp_aggregate->summary_only)
17078 	  vty_out (vty, " summary-only");
17079 
17080 	vty_out (vty, "%s", VTY_NEWLINE);
17081       }
17082 
17083   return 0;
17084 }
17085 
17086 int
bgp_config_write_distance(struct vty * vty,struct bgp * bgp,afi_t afi,safi_t safi,int * write)17087 bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
17088                            afi_t afi, safi_t safi, int *write)
17089 {
17090   struct bgp_node *rn;
17091   struct bgp_distance *bdistance;
17092 
17093   if (afi == AFI_IP && safi == SAFI_UNICAST)
17094     {
17095       /* Distance configuration. */
17096       if (bgp->distance_ebgp
17097           && bgp->distance_ibgp
17098           && bgp->distance_local
17099           && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
17100               || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
17101               || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
17102         vty_out (vty, " distance bgp %d %d %d%s",
17103                  bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
17104                  VTY_NEWLINE);
17105 
17106       for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
17107         if ((bdistance = rn->info) != NULL)
17108           {
17109             vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
17110                      inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
17111                      bdistance->access_list ? bdistance->access_list : "",
17112                      VTY_NEWLINE);
17113           }
17114     }
17115 
17116 #ifdef HAVE_IPV6
17117   else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
17118     {
17119       bgp_config_write_family_header (vty, afi, safi, write);
17120       if (bgp->ipv6_distance_ebgp
17121           && bgp->ipv6_distance_ibgp
17122           && bgp->ipv6_distance_local
17123           && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
17124               || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
17125               || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
17126         vty_out (vty, " distance bgp %d %d %d%s",
17127                  bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
17128                  VTY_NEWLINE);
17129 
17130       for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
17131         if ((bdistance = rn->info) != NULL)
17132           {
17133             vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
17134                      inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
17135                      bdistance->access_list ? bdistance->access_list : "",
17136                      VTY_NEWLINE);
17137           }
17138     }
17139 #endif /* HAVE_IPV6 */
17140 
17141   return 0;
17142 }
17143 
17144 /* Allocate routing table structure and install commands. */
17145 void
bgp_route_init(void)17146 bgp_route_init (void)
17147 {
17148   /* Init BGP distance table. */
17149   bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
17150 
17151   /* IPv4 BGP commands. */
17152   install_element (BGP_NODE, &bgp_network_cmd);
17153   install_element (BGP_NODE, &bgp_network_mask_cmd);
17154   install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
17155   install_element (BGP_NODE, &bgp_network_route_map_cmd);
17156   install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
17157   install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
17158   install_element (BGP_NODE, &bgp_network_backdoor_cmd);
17159   install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
17160   install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
17161   install_element (BGP_NODE, &no_bgp_network_cmd);
17162   install_element (BGP_NODE, &no_bgp_network_mask_cmd);
17163   install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
17164   install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
17165   install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
17166   install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
17167   install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
17168   install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
17169   install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
17170 
17171   install_element (BGP_NODE, &aggregate_address_cmd);
17172   install_element (BGP_NODE, &aggregate_address_mask_cmd);
17173   install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
17174   install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
17175   install_element (BGP_NODE, &aggregate_address_as_set_cmd);
17176   install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
17177   install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
17178   install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
17179   install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
17180   install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
17181   install_element (BGP_NODE, &no_aggregate_address_cmd);
17182   install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
17183   install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
17184   install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
17185   install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
17186   install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
17187   install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
17188   install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
17189   install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
17190   install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
17191 
17192   /* IPv4 unicast configuration.  */
17193   install_element (BGP_IPV4_NODE, &bgp_network_cmd);
17194   install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
17195   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
17196   install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
17197   install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
17198   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
17199   install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
17200   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
17201   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
17202   install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
17203   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
17204   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
17205 
17206   install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
17207   install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
17208   install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
17209   install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
17210   install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
17211   install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
17212   install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
17213   install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
17214   install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
17215   install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
17216   install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
17217   install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
17218   install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
17219   install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
17220   install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
17221   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
17222   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
17223   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
17224   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
17225   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
17226 
17227   /* IPv4 multicast configuration.  */
17228   install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
17229   install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
17230   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
17231   install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
17232   install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
17233   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
17234   install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
17235   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
17236   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
17237   install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
17238   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
17239   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
17240   install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
17241   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
17242   install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
17243   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
17244   install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
17245   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
17246   install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
17247   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
17248   install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
17249   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
17250   install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
17251   install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
17252   install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
17253   install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
17254   install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
17255   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
17256   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
17257   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
17258   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
17259   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
17260 
17261   install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
17262   install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
17263   install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
17264   install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
17265   install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
17266   install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
17267   install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
17268   install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
17269   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
17270   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
17271   install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
17272   install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
17273   install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
17274   install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
17275   install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
17276   install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
17277   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
17278   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
17279   install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
17280   install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
17281   install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
17282   install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
17283   install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
17284   install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
17285   install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
17286   install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
17287   install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
17288   install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
17289   install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
17290   install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
17291   install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
17292   install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
17293   install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
17294   install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
17295   install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
17296   install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
17297   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
17298   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
17299   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
17300   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
17301   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
17302   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
17303   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
17304   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
17305   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
17306   install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
17307   install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
17308   install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
17309   install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
17310   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
17311   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
17312   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
17313   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
17314   install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
17315   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
17316   install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
17317   install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
17318 
17319   /* large-communities */
17320   install_element (VIEW_NODE, &show_bgp_ipv4_lcommunity_cmd);
17321   install_element (VIEW_NODE, &show_bgp_ipv4_lcommunity2_cmd);
17322   install_element (VIEW_NODE, &show_bgp_ipv4_lcommunity3_cmd);
17323   install_element (VIEW_NODE, &show_bgp_ipv4_lcommunity4_cmd);
17324   install_element (VIEW_NODE, &show_bgp_ipv4_safi_lcommunity_cmd);
17325   install_element (VIEW_NODE, &show_bgp_ipv4_safi_lcommunity2_cmd);
17326   install_element (VIEW_NODE, &show_bgp_ipv4_safi_lcommunity3_cmd);
17327   install_element (VIEW_NODE, &show_bgp_ipv4_safi_lcommunity4_cmd);
17328   install_element (VIEW_NODE, &show_bgp_view_afi_safi_lcommunity_all_cmd);
17329   install_element (VIEW_NODE, &show_bgp_view_afi_safi_lcommunity_cmd);
17330   install_element (VIEW_NODE, &show_bgp_view_afi_safi_lcommunity2_cmd);
17331   install_element (VIEW_NODE, &show_bgp_view_afi_safi_lcommunity3_cmd);
17332   install_element (VIEW_NODE, &show_bgp_view_afi_safi_lcommunity4_cmd);
17333   install_element (VIEW_NODE, &show_bgp_ipv4_lcommunity_list_cmd);
17334   install_element (VIEW_NODE, &show_bgp_ipv4_safi_lcommunity_list_cmd);
17335 
17336   install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
17337   install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
17338   install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
17339   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
17340   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
17341   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
17342   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
17343   install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
17344   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
17345   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
17346   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
17347   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
17348   install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
17349   install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
17350   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
17351   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
17352   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
17353   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
17354   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
17355   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
17356   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
17357   install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
17358   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
17359   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
17360   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
17361   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
17362   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
17363   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
17364   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
17365   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
17366   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
17367   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
17368   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
17369   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
17370   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
17371   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
17372   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
17373   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
17374   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
17375   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
17376   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
17377   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
17378   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
17379   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
17380   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
17381   install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
17382   install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
17383   install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
17384   install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
17385   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
17386   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
17387   install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
17388   install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
17389   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
17390   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
17391   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
17392   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
17393   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
17394   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
17395 
17396   /* Restricted node: VIEW_NODE - (set of dangerous commands) */
17397   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
17398   install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
17399   install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
17400   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
17401   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
17402   install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
17403   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
17404   install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
17405   install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
17406   install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
17407   install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
17408   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
17409   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
17410   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
17411   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
17412   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
17413   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
17414   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
17415   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
17416   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
17417   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
17418   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
17419   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
17420   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
17421   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
17422   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
17423   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
17424   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
17425   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
17426   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
17427   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
17428   install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
17429   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
17430   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
17431   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
17432   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
17433 
17434   /* large-community */
17435   install_element (RESTRICTED_NODE, &show_bgp_ipv4_lcommunity_cmd);
17436   install_element (RESTRICTED_NODE, &show_bgp_ipv4_lcommunity2_cmd);
17437   install_element (RESTRICTED_NODE, &show_bgp_ipv4_lcommunity3_cmd);
17438   install_element (RESTRICTED_NODE, &show_bgp_ipv4_lcommunity4_cmd);
17439   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_lcommunity_cmd);
17440   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_lcommunity2_cmd);
17441   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_lcommunity3_cmd);
17442   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_lcommunity4_cmd);
17443   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_lcommunity_all_cmd);
17444   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_lcommunity_cmd);
17445   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_lcommunity2_cmd);
17446   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_lcommunity3_cmd);
17447   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_lcommunity4_cmd);
17448 
17449   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
17450   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
17451   install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
17452   install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
17453 
17454   /* BGP dampening clear commands */
17455   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
17456   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
17457 
17458   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
17459   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
17460 
17461   /* New config IPv6 BGP commands.  */
17462   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
17463   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
17464   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
17465   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
17466 
17467   install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
17468   install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
17469   install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
17470   install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
17471 
17472   install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
17473   install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
17474 
17475   /* Old config IPv6 BGP commands.  */
17476   install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
17477   install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
17478 
17479   install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
17480   install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
17481   install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
17482   install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
17483 
17484   install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
17485   install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
17486   install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
17487   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
17488   install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
17489   install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
17490   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
17491   install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
17492   install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
17493   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
17494   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
17495   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
17496   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
17497   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
17498   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
17499   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
17500   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
17501   install_element (VIEW_NODE, &show_bgp_community_list_cmd);
17502 
17503   /* large-community */
17504   install_element (VIEW_NODE, &show_bgp_ipv6_safi_lcommunity_cmd);
17505   install_element (VIEW_NODE, &show_bgp_ipv6_safi_lcommunity2_cmd);
17506   install_element (VIEW_NODE, &show_bgp_ipv6_safi_lcommunity3_cmd);
17507   install_element (VIEW_NODE, &show_bgp_ipv6_safi_lcommunity4_cmd);
17508   install_element (VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17509 
17510   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
17511   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
17512   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
17513   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
17514   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
17515   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
17516   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
17517   install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
17518   install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
17519   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
17520   install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
17521   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
17522   install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
17523   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
17524   install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
17525   install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
17526   install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
17527   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
17528   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
17529   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
17530   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
17531   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
17532   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
17533   install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
17534   install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
17535   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
17536   install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
17537   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
17538   install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
17539   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
17540 
17541   /* Restricted:
17542    * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
17543    */
17544   install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
17545   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
17546   install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
17547   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
17548   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
17549   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
17550   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
17551   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
17552   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
17553   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
17554   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
17555   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
17556   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_lcommunity_cmd);
17557   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_lcommunity2_cmd);
17558   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_lcommunity3_cmd);
17559   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_lcommunity4_cmd);
17560   install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
17561   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
17562   install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
17563   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
17564   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
17565   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
17566   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
17567   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
17568   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
17569   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
17570   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
17571 
17572   /* Statistics */
17573   install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
17574   install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
17575 
17576   install_element (BGP_NODE, &bgp_distance_cmd);
17577   install_element (BGP_NODE, &no_bgp_distance_cmd);
17578   install_element (BGP_NODE, &no_bgp_distance2_cmd);
17579   install_element (BGP_NODE, &bgp_distance_source_cmd);
17580   install_element (BGP_NODE, &no_bgp_distance_source_cmd);
17581   install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
17582   install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
17583 #ifdef HAVE_IPV6
17584   install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
17585   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
17586   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
17587   install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
17588   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
17589   install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
17590   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
17591 #endif /* HAVE_IPV6 */
17592 
17593   install_element (BGP_NODE, &bgp_damp_set_cmd);
17594   install_element (BGP_NODE, &bgp_damp_set2_cmd);
17595   install_element (BGP_NODE, &bgp_damp_set3_cmd);
17596   install_element (BGP_NODE, &bgp_damp_unset_cmd);
17597   install_element (BGP_NODE, &bgp_damp_unset2_cmd);
17598   install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
17599   install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
17600   install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
17601   install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
17602   install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
17603 
17604   /* IPv4 Multicast Mode */
17605   install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
17606   install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
17607   install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
17608   install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
17609   install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
17610 
17611 
17612   /* Deprecated AS-Pathlimit commands */
17613   install_element (BGP_NODE, &bgp_network_ttl_cmd);
17614   install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
17615   install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
17616   install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
17617   install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
17618   install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
17619 
17620   install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
17621   install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
17622   install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
17623   install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
17624   install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
17625   install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
17626 
17627   install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
17628   install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
17629   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
17630   install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
17631   install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
17632   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
17633 
17634   install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
17635   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
17636   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
17637   install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
17638   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
17639   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
17640 
17641   install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
17642   install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
17643   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
17644   install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
17645   install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
17646   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
17647 
17648   install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
17649   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
17650   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
17651   install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
17652   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
17653   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
17654 
17655   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
17656   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
17657 
17658   /* old style commands */
17659   install_element (VIEW_NODE, &show_ip_bgp_cmd);
17660   install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
17661   install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
17662   install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
17663   install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
17664   install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
17665   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
17666   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
17667   install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
17668   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
17669   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
17670   install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
17671   install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
17672   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
17673   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
17674   install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
17675   install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
17676   install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
17677   install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
17678   install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
17679   install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
17680   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
17681   install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
17682   install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
17683   install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
17684   install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
17685   install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
17686   install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
17687   install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
17688   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
17689   install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
17690   install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
17691   install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
17692   install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
17693   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
17694   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
17695   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
17696   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
17697   install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
17698   install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
17699   install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
17700   install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
17701   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
17702   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
17703   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
17704   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
17705   install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
17706   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
17707   install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
17708   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
17709   install_element (VIEW_NODE, &show_ip_bgp_lcommunity_all_cmd);
17710   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity_all_cmd);
17711   install_element (VIEW_NODE, &show_ip_bgp_lcommunity_cmd);
17712   install_element (VIEW_NODE, &show_ip_bgp_lcommunity2_cmd);
17713   install_element (VIEW_NODE, &show_ip_bgp_lcommunity3_cmd);
17714   install_element (VIEW_NODE, &show_ip_bgp_lcommunity4_cmd);
17715   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity_cmd);
17716   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity2_cmd);
17717   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity3_cmd);
17718   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity4_cmd);
17719   install_element (VIEW_NODE, &show_ip_bgp_lcommunity_list_cmd);
17720   install_element (VIEW_NODE, &show_ip_bgp_ipv4_lcommunity_list_cmd);
17721   install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
17722   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
17723   install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
17724   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
17725   install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
17726   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
17727   install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
17728   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
17729   install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
17730   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
17731   install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
17732   install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
17733   install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
17734   install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
17735   install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
17736   install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
17737   install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
17738   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
17739   install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
17740   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
17741   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
17742   install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
17743   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
17744   install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
17745   install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
17746   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
17747   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
17748   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
17749   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
17750   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
17751   install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
17752   install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
17753   install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
17754   install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
17755   install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
17756   install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
17757   install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
17758   install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
17759   install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
17760   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
17761   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
17762   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
17763 
17764   install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
17765   install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
17766   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
17767   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
17768   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
17769   install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
17770   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
17771   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
17772   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
17773   install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
17774   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
17775   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
17776   install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
17777   install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
17778   install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
17779   install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
17780   install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
17781   install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
17782   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
17783   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
17784   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
17785   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
17786   install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
17787   install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
17788   install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
17789   install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
17790   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
17791   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
17792   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
17793   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
17794   install_element (RESTRICTED_NODE, &show_ip_bgp_lcommunity_cmd);
17795   install_element (RESTRICTED_NODE, &show_ip_bgp_lcommunity2_cmd);
17796   install_element (RESTRICTED_NODE, &show_ip_bgp_lcommunity3_cmd);
17797   install_element (RESTRICTED_NODE, &show_ip_bgp_lcommunity4_cmd);
17798   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_lcommunity_cmd);
17799   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_lcommunity2_cmd);
17800   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_lcommunity3_cmd);
17801   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_lcommunity4_cmd);
17802   install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
17803   install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
17804   install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
17805   install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
17806 
17807   install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
17808   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
17809   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
17810 
17811   install_element (VIEW_NODE, &show_bgp_cmd);
17812   install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
17813   install_element (VIEW_NODE, &show_bgp_route_cmd);
17814   install_element (VIEW_NODE, &show_bgp_prefix_cmd);
17815   install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
17816   install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
17817   install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
17818   install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
17819   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
17820   install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
17821   install_element (VIEW_NODE, &show_bgp_regexp_cmd);
17822   install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
17823   install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
17824   install_element (VIEW_NODE, &show_bgp_route_map_cmd);
17825   install_element (VIEW_NODE, &show_bgp_community_all_cmd);
17826   install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
17827   install_element (VIEW_NODE, &show_bgp_community_cmd);
17828   install_element (VIEW_NODE, &show_bgp_community2_cmd);
17829   install_element (VIEW_NODE, &show_bgp_community3_cmd);
17830   install_element (VIEW_NODE, &show_bgp_community4_cmd);
17831   install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
17832   install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
17833   install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
17834   install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
17835   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
17836   install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
17837   install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
17838   install_element (VIEW_NODE, &show_bgp_lcommunity_all_cmd);
17839   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity_all_cmd);
17840   install_element (VIEW_NODE, &show_bgp_lcommunity_cmd);
17841   install_element (VIEW_NODE, &show_bgp_lcommunity2_cmd);
17842   install_element (VIEW_NODE, &show_bgp_lcommunity3_cmd);
17843   install_element (VIEW_NODE, &show_bgp_lcommunity4_cmd);
17844   install_element (VIEW_NODE, &show_bgp_ipv6_safi_lcommunity_list_cmd);
17845   install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
17846   install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
17847   install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
17848   install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
17849   install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
17850   install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
17851   install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
17852   install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
17853   install_element (VIEW_NODE, &show_bgp_view_cmd);
17854   install_element (VIEW_NODE, &show_bgp_view_route_cmd);
17855   install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
17856   install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
17857   install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
17858   install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
17859   install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
17860   install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
17861   install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
17862   install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
17863 
17864   install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
17865   install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
17866   install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
17867   install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
17868   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
17869   install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
17870   install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
17871   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
17872   install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
17873   install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
17874   install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
17875   install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
17876   install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
17877   install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
17878   install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
17879   install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
17880   install_element (RESTRICTED_NODE, &show_bgp_lcommunity_cmd);
17881   install_element (RESTRICTED_NODE, &show_bgp_lcommunity2_cmd);
17882   install_element (RESTRICTED_NODE, &show_bgp_lcommunity3_cmd);
17883   install_element (RESTRICTED_NODE, &show_bgp_lcommunity4_cmd);
17884   install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
17885   install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
17886   install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
17887 
17888   install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
17889   install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
17890 
17891   install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
17892   install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
17893   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
17894   install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
17895   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
17896   install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
17897   install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
17898   install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
17899   install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
17900   install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
17901   install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
17902   install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
17903   install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
17904   install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
17905   install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
17906   install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
17907   install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
17908   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity_all_cmd);
17909   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity_cmd);
17910   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity2_cmd);
17911   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity3_cmd);
17912   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity4_cmd);
17913   install_element (VIEW_NODE, &show_ipv6_bgp_lcommunity_list_cmd);
17914   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
17915   install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
17916   install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
17917   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
17918   install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
17919   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
17920   install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
17921   install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
17922   install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
17923   install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
17924   install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
17925   install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
17926   install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
17927   install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
17928   install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
17929   install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
17930   install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
17931   install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
17932   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity_all_cmd);
17933   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity_cmd);
17934   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity2_cmd);
17935   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity3_cmd);
17936   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity4_cmd);
17937   install_element (VIEW_NODE, &show_ipv6_mbgp_lcommunity_list_cmd);
17938   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
17939   install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
17940   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
17941   install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
17942   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
17943   install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
17944   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
17945   /* old with name safi collision */
17946   install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
17947   install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
17948   install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
17949   install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
17950   install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
17951   install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
17952   install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
17953   install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
17954   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
17955   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
17956   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
17957   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
17958   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
17959   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
17960   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
17961   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
17962 
17963   install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
17964   install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
17965 
17966   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity_cmd);
17967   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity2_cmd);
17968   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity3_cmd);
17969   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity4_cmd);
17970   install_element (RESTRICTED_NODE, &show_bgp_ipv6_lcommunity_cmd);
17971   install_element (RESTRICTED_NODE, &show_bgp_ipv6_lcommunity2_cmd);
17972   install_element (RESTRICTED_NODE, &show_bgp_ipv6_lcommunity3_cmd);
17973   install_element (RESTRICTED_NODE, &show_bgp_ipv6_lcommunity4_cmd);
17974   install_element (VIEW_NODE, &show_bgp_ipv6_lcommunity_list_cmd);
17975 
17976   install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
17977   install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
17978   install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
17979   install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
17980 
17981   install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
17982   install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
17983   install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
17984   install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
17985 }
17986 
17987 void
bgp_route_finish(void)17988 bgp_route_finish (void)
17989 {
17990   bgp_table_unlock (bgp_distance_table);
17991   bgp_distance_table = NULL;
17992 }
17993