1 /* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3 Copyright (C) 2016 Job Snijders <job@instituut.net>
5 This file is part of GNU Zebra.
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
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.
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
33 #include "sockunion.h"
36 #include "workqueue.h"
42 #include "bgpd/bgpd.h"
43 #include "bgpd/bgp_table.h"
44 #include "bgpd/bgp_route.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_debug.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_regex.h"
49 #include "bgpd/bgp_community.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_clist.h"
53 #include "bgpd/bgp_packet.h"
54 #include "bgpd/bgp_filter.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_encap.h"
58 #include "bgpd/bgp_nexthop.h"
59 #include "bgpd/bgp_damp.h"
60 #include "bgpd/bgp_advertise.h"
61 #include "bgpd/bgp_zebra.h"
62 #include "bgpd/bgp_vty.h"
63 #include "bgpd/bgp_mpath.h"
64 #include "bgpd/bgp_nht.h"
65 #include "bgpd/bgp_updgrp.h"
66 #include "bgpd/bgp_label.h"
69 #include "bgpd/rfapi/rfapi_backend.h"
70 #include "bgpd/rfapi/vnc_import_bgp.h"
71 #include "bgpd/rfapi/vnc_export_bgp.h"
73 #include "bgpd/bgp_encap_types.h"
74 #include "bgpd/bgp_encap_tlv.h"
75 #include "bgpd/bgp_evpn.h"
76 #include "bgpd/bgp_evpn_vty.h"
79 /* Extern from bgp_dump.c */
80 extern const char *bgp_origin_str
[];
81 extern const char *bgp_origin_long_str
[];
84 bgp_afi_node_get (struct bgp_table
*table
, afi_t afi
, safi_t safi
, struct prefix
*p
,
85 struct prefix_rd
*prd
)
88 struct bgp_node
*prn
= NULL
;
94 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) ||
97 prn
= bgp_node_get (table
, (struct prefix
*) prd
);
99 if (prn
->info
== NULL
)
100 prn
->info
= bgp_table_init (afi
, safi
);
102 bgp_unlock_node (prn
);
106 rn
= bgp_node_get (table
, p
);
108 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) ||
115 /* Allocate bgp_info_extra */
116 static struct bgp_info_extra
*
117 bgp_info_extra_new (void)
119 struct bgp_info_extra
*new;
120 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA
, sizeof (struct bgp_info_extra
));
125 bgp_info_extra_free (struct bgp_info_extra
**extra
)
129 if ((*extra
)->damp_info
)
130 bgp_damp_info_free ((*extra
)->damp_info
, 0);
132 (*extra
)->damp_info
= NULL
;
134 XFREE (MTYPE_BGP_ROUTE_EXTRA
, *extra
);
140 /* Get bgp_info extra information for the given bgp_info, lazy allocated
143 struct bgp_info_extra
*
144 bgp_info_extra_get (struct bgp_info
*ri
)
147 ri
->extra
= bgp_info_extra_new();
151 /* Allocate new bgp info structure. */
155 return XCALLOC (MTYPE_BGP_ROUTE
, sizeof (struct bgp_info
));
158 /* Free bgp route information. */
160 bgp_info_free (struct bgp_info
*binfo
)
163 bgp_attr_unintern (&binfo
->attr
);
165 bgp_unlink_nexthop(binfo
);
166 bgp_info_extra_free (&binfo
->extra
);
167 bgp_info_mpath_free (&binfo
->mpath
);
169 peer_unlock (binfo
->peer
); /* bgp_info peer reference */
171 XFREE (MTYPE_BGP_ROUTE
, binfo
);
175 bgp_info_lock (struct bgp_info
*binfo
)
182 bgp_info_unlock (struct bgp_info
*binfo
)
184 assert (binfo
&& binfo
->lock
> 0);
187 if (binfo
->lock
== 0)
190 zlog_debug ("%s: unlocked and freeing", __func__
);
191 zlog_backtrace (LOG_DEBUG
);
193 bgp_info_free (binfo
);
198 if (binfo
->lock
== 1)
200 zlog_debug ("%s: unlocked to 1", __func__
);
201 zlog_backtrace (LOG_DEBUG
);
209 bgp_info_add (struct bgp_node
*rn
, struct bgp_info
*ri
)
211 struct bgp_info
*top
;
223 peer_lock (ri
->peer
); /* bgp_info peer reference */
226 /* Do the actual removal of info from RIB, for use by bgp_process
227 completion callback *only* */
229 bgp_info_reap (struct bgp_node
*rn
, struct bgp_info
*ri
)
232 ri
->next
->prev
= ri
->prev
;
234 ri
->prev
->next
= ri
->next
;
238 bgp_info_mpath_dequeue (ri
);
239 bgp_info_unlock (ri
);
240 bgp_unlock_node (rn
);
244 bgp_info_delete (struct bgp_node
*rn
, struct bgp_info
*ri
)
246 bgp_info_set_flag (rn
, ri
, BGP_INFO_REMOVED
);
247 /* set of previous already took care of pcount */
248 UNSET_FLAG (ri
->flags
, BGP_INFO_VALID
);
251 /* undo the effects of a previous call to bgp_info_delete; typically
252 called when a route is deleted and then quickly re-added before the
253 deletion has been processed */
255 bgp_info_restore (struct bgp_node
*rn
, struct bgp_info
*ri
)
257 bgp_info_unset_flag (rn
, ri
, BGP_INFO_REMOVED
);
258 /* unset of previous already took care of pcount */
259 SET_FLAG (ri
->flags
, BGP_INFO_VALID
);
262 /* Adjust pcount as required */
264 bgp_pcount_adjust (struct bgp_node
*rn
, struct bgp_info
*ri
)
266 struct bgp_table
*table
;
268 assert (rn
&& bgp_node_table (rn
));
269 assert (ri
&& ri
->peer
&& ri
->peer
->bgp
);
271 table
= bgp_node_table (rn
);
273 if (ri
->peer
== ri
->peer
->bgp
->peer_self
)
276 if (!BGP_INFO_COUNTABLE (ri
)
277 && CHECK_FLAG (ri
->flags
, BGP_INFO_COUNTED
))
280 UNSET_FLAG (ri
->flags
, BGP_INFO_COUNTED
);
282 /* slight hack, but more robust against errors. */
283 if (ri
->peer
->pcount
[table
->afi
][table
->safi
])
284 ri
->peer
->pcount
[table
->afi
][table
->safi
]--;
287 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
288 __func__
, ri
->peer
->host
);
289 zlog_backtrace (LOG_WARNING
);
290 zlog_warn ("%s: Please report to Quagga bugzilla", __func__
);
293 else if (BGP_INFO_COUNTABLE (ri
)
294 && !CHECK_FLAG (ri
->flags
, BGP_INFO_COUNTED
))
296 SET_FLAG (ri
->flags
, BGP_INFO_COUNTED
);
297 ri
->peer
->pcount
[table
->afi
][table
->safi
]++;
302 bgp_label_index_differs (struct bgp_info
*ri1
, struct bgp_info
*ri2
)
304 return (!(ri1
->attr
->extra
->label_index
== ri2
->attr
->extra
->label_index
));
307 /* Set/unset bgp_info flags, adjusting any other state as needed.
308 * This is here primarily to keep prefix-count in check.
311 bgp_info_set_flag (struct bgp_node
*rn
, struct bgp_info
*ri
, u_int32_t flag
)
313 SET_FLAG (ri
->flags
, flag
);
315 /* early bath if we know it's not a flag that changes countability state */
316 if (!CHECK_FLAG (flag
, BGP_INFO_VALID
|BGP_INFO_HISTORY
|BGP_INFO_REMOVED
))
319 bgp_pcount_adjust (rn
, ri
);
323 bgp_info_unset_flag (struct bgp_node
*rn
, struct bgp_info
*ri
, u_int32_t flag
)
325 UNSET_FLAG (ri
->flags
, flag
);
327 /* early bath if we know it's not a flag that changes countability state */
328 if (!CHECK_FLAG (flag
, BGP_INFO_VALID
|BGP_INFO_HISTORY
|BGP_INFO_REMOVED
))
331 bgp_pcount_adjust (rn
, ri
);
334 /* Get MED value. If MED value is missing and "bgp bestpath
335 missing-as-worst" is specified, treat it as the worst value. */
337 bgp_med_value (struct attr
*attr
, struct bgp
*bgp
)
339 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
343 if (bgp_flag_check (bgp
, BGP_FLAG_MED_MISSING_AS_WORST
))
351 bgp_info_path_with_addpath_rx_str (struct bgp_info
*ri
, char *buf
)
353 if (ri
->addpath_rx_id
)
354 sprintf(buf
, "path %s (addpath rxid %d)", ri
->peer
->host
, ri
->addpath_rx_id
);
356 sprintf(buf
, "path %s", ri
->peer
->host
);
359 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
361 bgp_info_cmp (struct bgp
*bgp
, struct bgp_info
*new, struct bgp_info
*exist
,
362 int *paths_eq
, struct bgp_maxpaths_cfg
*mpath_cfg
, int debug
,
365 struct attr
*newattr
, *existattr
;
366 struct attr_extra
*newattre
, *existattre
;
367 bgp_peer_sort_t new_sort
;
368 bgp_peer_sort_t exist_sort
;
370 u_int32_t exist_pref
;
373 u_int32_t new_weight
;
374 u_int32_t exist_weight
;
375 uint32_t newm
, existm
;
376 struct in_addr new_id
;
377 struct in_addr exist_id
;
380 int internal_as_route
;
383 char new_buf
[PATH_ADDPATH_STR_BUFFER
];
384 char exist_buf
[PATH_ADDPATH_STR_BUFFER
];
392 zlog_debug("%s: new is NULL", pfx_buf
);
397 bgp_info_path_with_addpath_rx_str (new, new_buf
);
402 zlog_debug("%s: %s is the initial bestpath", pfx_buf
, new_buf
);
408 bgp_info_path_with_addpath_rx_str (exist
, exist_buf
);
409 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
410 pfx_buf
, new_buf
, new->flags
, exist_buf
, exist
->flags
);
414 existattr
= exist
->attr
;
415 newattre
= newattr
->extra
;
416 existattre
= existattr
->extra
;
418 /* 1. Weight check. */
419 new_weight
= exist_weight
= 0;
422 new_weight
= newattre
->weight
;
424 exist_weight
= existattre
->weight
;
426 if (new_weight
> exist_weight
)
429 zlog_debug("%s: %s wins over %s due to weight %d > %d",
430 pfx_buf
, new_buf
, exist_buf
, new_weight
, exist_weight
);
434 if (new_weight
< exist_weight
)
437 zlog_debug("%s: %s loses to %s due to weight %d < %d",
438 pfx_buf
, new_buf
, exist_buf
, new_weight
, exist_weight
);
442 /* 2. Local preference check. */
443 new_pref
= exist_pref
= bgp
->default_local_pref
;
445 if (newattr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
446 new_pref
= newattr
->local_pref
;
447 if (existattr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
448 exist_pref
= existattr
->local_pref
;
450 if (new_pref
> exist_pref
)
453 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
454 pfx_buf
, new_buf
, exist_buf
, new_pref
, exist_pref
);
458 if (new_pref
< exist_pref
)
461 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
462 pfx_buf
, new_buf
, exist_buf
, new_pref
, exist_pref
);
466 /* 3. Local route check. We prefer:
468 * - BGP_ROUTE_AGGREGATE
469 * - BGP_ROUTE_REDISTRIBUTE
471 if (! (new->sub_type
== BGP_ROUTE_NORMAL
))
474 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
475 pfx_buf
, new_buf
, exist_buf
);
479 if (! (exist
->sub_type
== BGP_ROUTE_NORMAL
))
482 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
483 pfx_buf
, new_buf
, exist_buf
);
487 /* 4. AS path length check. */
488 if (! bgp_flag_check (bgp
, BGP_FLAG_ASPATH_IGNORE
))
490 int exist_hops
= aspath_count_hops (existattr
->aspath
);
491 int exist_confeds
= aspath_count_confeds (existattr
->aspath
);
493 if (bgp_flag_check (bgp
, BGP_FLAG_ASPATH_CONFED
))
497 aspath_hops
= aspath_count_hops (newattr
->aspath
);
498 aspath_hops
+= aspath_count_confeds (newattr
->aspath
);
500 if ( aspath_hops
< (exist_hops
+ exist_confeds
))
503 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
504 pfx_buf
, new_buf
, exist_buf
,
505 aspath_hops
, (exist_hops
+ exist_confeds
));
509 if ( aspath_hops
> (exist_hops
+ exist_confeds
))
512 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
513 pfx_buf
, new_buf
, exist_buf
,
514 aspath_hops
, (exist_hops
+ exist_confeds
));
520 int newhops
= aspath_count_hops (newattr
->aspath
);
522 if (newhops
< exist_hops
)
525 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
526 pfx_buf
, new_buf
, exist_buf
, newhops
, exist_hops
);
530 if (newhops
> exist_hops
)
533 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
534 pfx_buf
, new_buf
, exist_buf
, newhops
, exist_hops
);
540 /* 5. Origin check. */
541 if (newattr
->origin
< existattr
->origin
)
544 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
545 pfx_buf
, new_buf
, exist_buf
,
546 bgp_origin_long_str
[newattr
->origin
],
547 bgp_origin_long_str
[existattr
->origin
]);
551 if (newattr
->origin
> existattr
->origin
)
554 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
555 pfx_buf
, new_buf
, exist_buf
,
556 bgp_origin_long_str
[newattr
->origin
],
557 bgp_origin_long_str
[existattr
->origin
]);
562 internal_as_route
= (aspath_count_hops (newattr
->aspath
) == 0
563 && aspath_count_hops (existattr
->aspath
) == 0);
564 confed_as_route
= (aspath_count_confeds (newattr
->aspath
) > 0
565 && aspath_count_confeds (existattr
->aspath
) > 0
566 && aspath_count_hops (newattr
->aspath
) == 0
567 && aspath_count_hops (existattr
->aspath
) == 0);
569 if (bgp_flag_check (bgp
, BGP_FLAG_ALWAYS_COMPARE_MED
)
570 || (bgp_flag_check (bgp
, BGP_FLAG_MED_CONFED
)
572 || aspath_cmp_left (newattr
->aspath
, existattr
->aspath
)
573 || aspath_cmp_left_confed (newattr
->aspath
, existattr
->aspath
)
574 || internal_as_route
)
576 new_med
= bgp_med_value (new->attr
, bgp
);
577 exist_med
= bgp_med_value (exist
->attr
, bgp
);
579 if (new_med
< exist_med
)
582 zlog_debug("%s: %s wins over %s due to MED %d < %d",
583 pfx_buf
, new_buf
, exist_buf
, new_med
, exist_med
);
587 if (new_med
> exist_med
)
590 zlog_debug("%s: %s loses to %s due to MED %d > %d",
591 pfx_buf
, new_buf
, exist_buf
, new_med
, exist_med
);
596 /* 7. Peer type check. */
597 new_sort
= new->peer
->sort
;
598 exist_sort
= exist
->peer
->sort
;
600 if (new_sort
== BGP_PEER_EBGP
601 && (exist_sort
== BGP_PEER_IBGP
|| exist_sort
== BGP_PEER_CONFED
))
604 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
605 pfx_buf
, new_buf
, exist_buf
);
609 if (exist_sort
== BGP_PEER_EBGP
610 && (new_sort
== BGP_PEER_IBGP
|| new_sort
== BGP_PEER_CONFED
))
613 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
614 pfx_buf
, new_buf
, exist_buf
);
618 /* 8. IGP metric check. */
622 newm
= new->extra
->igpmetric
;
624 existm
= exist
->extra
->igpmetric
;
629 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
630 pfx_buf
, new_buf
, exist_buf
, newm
, existm
);
637 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
638 pfx_buf
, new_buf
, exist_buf
, newm
, existm
);
642 /* 9. Same IGP metric. Compare the cluster list length as
643 representative of IGP hops metric. Rewrite the metric value
644 pair (newm, existm) with the cluster list length. Prefer the
645 path with smaller cluster list length. */
648 if (peer_sort (new->peer
) == BGP_PEER_IBGP
649 && peer_sort (exist
->peer
) == BGP_PEER_IBGP
650 && (mpath_cfg
== NULL
||
651 CHECK_FLAG (mpath_cfg
->ibgp_flags
,
652 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN
)))
654 newm
= BGP_CLUSTER_LIST_LENGTH(new->attr
);
655 existm
= BGP_CLUSTER_LIST_LENGTH(exist
->attr
);
660 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
661 pfx_buf
, new_buf
, exist_buf
, newm
, existm
);
668 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
669 pfx_buf
, new_buf
, exist_buf
, newm
, existm
);
675 /* 10. confed-external vs. confed-internal */
676 if (CHECK_FLAG(bgp
->config
, BGP_CONFIG_CONFEDERATION
))
678 if (new_sort
== BGP_PEER_CONFED
&& exist_sort
== BGP_PEER_IBGP
)
681 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
682 pfx_buf
, new_buf
, exist_buf
);
686 if (exist_sort
== BGP_PEER_CONFED
&& new_sort
== BGP_PEER_IBGP
)
689 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
690 pfx_buf
, new_buf
, exist_buf
);
695 /* 11. Maximum path check. */
698 if (bgp_flag_check(bgp
, BGP_FLAG_ASPATH_MULTIPATH_RELAX
))
702 * For the two paths, all comparison steps till IGP metric
703 * have succeeded - including AS_PATH hop count. Since 'bgp
704 * bestpath as-path multipath-relax' knob is on, we don't need
705 * an exact match of AS_PATH. Thus, mark the paths are equal.
706 * That will trigger both these paths to get into the multipath
712 zlog_debug("%s: %s and %s are equal via multipath-relax",
713 pfx_buf
, new_buf
, exist_buf
);
715 else if (new->peer
->sort
== BGP_PEER_IBGP
)
717 if (aspath_cmp (new->attr
->aspath
, exist
->attr
->aspath
))
722 zlog_debug("%s: %s and %s are equal via matching aspaths",
723 pfx_buf
, new_buf
, exist_buf
);
726 else if (new->peer
->as
== exist
->peer
->as
)
731 zlog_debug("%s: %s and %s are equal via same remote-as",
732 pfx_buf
, new_buf
, exist_buf
);
738 * TODO: If unequal cost ibgp multipath is enabled we can
739 * mark the paths as equal here instead of returning
744 zlog_debug("%s: %s wins over %s after IGP metric comparison",
745 pfx_buf
, new_buf
, exist_buf
);
747 zlog_debug("%s: %s loses to %s after IGP metric comparison",
748 pfx_buf
, new_buf
, exist_buf
);
753 /* 12. If both paths are external, prefer the path that was received
754 first (the oldest one). This step minimizes route-flap, since a
755 newer path won't displace an older one, even if it was the
756 preferred route based on the additional decision criteria below. */
757 if (! bgp_flag_check (bgp
, BGP_FLAG_COMPARE_ROUTER_ID
)
758 && new_sort
== BGP_PEER_EBGP
759 && exist_sort
== BGP_PEER_EBGP
)
761 if (CHECK_FLAG (new->flags
, BGP_INFO_SELECTED
))
764 zlog_debug("%s: %s wins over %s due to oldest external",
765 pfx_buf
, new_buf
, exist_buf
);
769 if (CHECK_FLAG (exist
->flags
, BGP_INFO_SELECTED
))
772 zlog_debug("%s: %s loses to %s due to oldest external",
773 pfx_buf
, new_buf
, exist_buf
);
778 /* 13. Router-ID comparision. */
779 /* If one of the paths is "stale", the corresponding peer router-id will
780 * be 0 and would always win over the other path. If originator id is
781 * used for the comparision, it will decide which path is better.
783 if (newattr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
))
784 new_id
.s_addr
= newattre
->originator_id
.s_addr
;
786 new_id
.s_addr
= new->peer
->remote_id
.s_addr
;
787 if (existattr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
))
788 exist_id
.s_addr
= existattre
->originator_id
.s_addr
;
790 exist_id
.s_addr
= exist
->peer
->remote_id
.s_addr
;
792 if (ntohl (new_id
.s_addr
) < ntohl (exist_id
.s_addr
))
795 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
796 pfx_buf
, new_buf
, exist_buf
);
800 if (ntohl (new_id
.s_addr
) > ntohl (exist_id
.s_addr
))
803 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
804 pfx_buf
, new_buf
, exist_buf
);
808 /* 14. Cluster length comparision. */
809 new_cluster
= BGP_CLUSTER_LIST_LENGTH(new->attr
);
810 exist_cluster
= BGP_CLUSTER_LIST_LENGTH(exist
->attr
);
812 if (new_cluster
< exist_cluster
)
815 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
816 pfx_buf
, new_buf
, exist_buf
, new_cluster
, exist_cluster
);
820 if (new_cluster
> exist_cluster
)
823 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
824 pfx_buf
, new_buf
, exist_buf
, new_cluster
, exist_cluster
);
828 /* 15. Neighbor address comparision. */
829 /* Do this only if neither path is "stale" as stale paths do not have
830 * valid peer information (as the connection may or may not be up).
832 if (CHECK_FLAG (exist
->flags
, BGP_INFO_STALE
))
835 zlog_debug("%s: %s wins over %s due to latter path being STALE",
836 pfx_buf
, new_buf
, exist_buf
);
840 if (CHECK_FLAG (new->flags
, BGP_INFO_STALE
))
843 zlog_debug("%s: %s loses to %s due to former path being STALE",
844 pfx_buf
, new_buf
, exist_buf
);
848 /* locally configured routes to advertise do not have su_remote */
849 if (new->peer
->su_remote
== NULL
)
851 if (exist
->peer
->su_remote
== NULL
)
854 ret
= sockunion_cmp (new->peer
->su_remote
, exist
->peer
->su_remote
);
859 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
860 pfx_buf
, new_buf
, exist_buf
);
867 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
868 pfx_buf
, new_buf
, exist_buf
);
873 zlog_debug("%s: %s wins over %s due to nothing left to compare",
874 pfx_buf
, new_buf
, exist_buf
);
879 /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
880 * is preferred, or 0 if they are the same (usually will only occur if
881 * multipath is enabled
882 * This version is compatible with */
884 bgp_info_cmp_compatible (struct bgp
*bgp
, struct bgp_info
*new, struct bgp_info
*exist
,
885 afi_t afi
, safi_t safi
)
889 ret
= bgp_info_cmp (bgp
, new, exist
, &paths_eq
, NULL
, 0, __func__
);
903 static enum filter_type
904 bgp_input_filter (struct peer
*peer
, struct prefix
*p
, struct attr
*attr
,
905 afi_t afi
, safi_t safi
)
907 struct bgp_filter
*filter
;
909 filter
= &peer
->filter
[afi
][safi
];
911 #define FILTER_EXIST_WARN(F,f,filter) \
912 if (BGP_DEBUG (update, UPDATE_IN) \
913 && !(F ## _IN (filter))) \
914 zlog_warn ("%s: Could not find configured input %s-list %s!", \
915 peer->host, #f, F ## _IN_NAME(filter));
917 if (DISTRIBUTE_IN_NAME (filter
)) {
918 FILTER_EXIST_WARN(DISTRIBUTE
, distribute
, filter
);
920 if (access_list_apply (DISTRIBUTE_IN (filter
), p
) == FILTER_DENY
)
924 if (PREFIX_LIST_IN_NAME (filter
)) {
925 FILTER_EXIST_WARN(PREFIX_LIST
, prefix
, filter
);
927 if (prefix_list_apply (PREFIX_LIST_IN (filter
), p
) == PREFIX_DENY
)
931 if (FILTER_LIST_IN_NAME (filter
)) {
932 FILTER_EXIST_WARN(FILTER_LIST
, as
, filter
);
934 if (as_list_apply (FILTER_LIST_IN (filter
), attr
->aspath
)== AS_FILTER_DENY
)
938 return FILTER_PERMIT
;
939 #undef FILTER_EXIST_WARN
942 static enum filter_type
943 bgp_output_filter (struct peer
*peer
, struct prefix
*p
, struct attr
*attr
,
944 afi_t afi
, safi_t safi
)
946 struct bgp_filter
*filter
;
948 filter
= &peer
->filter
[afi
][safi
];
950 #define FILTER_EXIST_WARN(F,f,filter) \
951 if (BGP_DEBUG (update, UPDATE_OUT) \
952 && !(F ## _OUT (filter))) \
953 zlog_warn ("%s: Could not find configured output %s-list %s!", \
954 peer->host, #f, F ## _OUT_NAME(filter));
956 if (DISTRIBUTE_OUT_NAME (filter
)) {
957 FILTER_EXIST_WARN(DISTRIBUTE
, distribute
, filter
);
959 if (access_list_apply (DISTRIBUTE_OUT (filter
), p
) == FILTER_DENY
)
963 if (PREFIX_LIST_OUT_NAME (filter
)) {
964 FILTER_EXIST_WARN(PREFIX_LIST
, prefix
, filter
);
966 if (prefix_list_apply (PREFIX_LIST_OUT (filter
), p
) == PREFIX_DENY
)
970 if (FILTER_LIST_OUT_NAME (filter
)) {
971 FILTER_EXIST_WARN(FILTER_LIST
, as
, filter
);
973 if (as_list_apply (FILTER_LIST_OUT (filter
), attr
->aspath
) == AS_FILTER_DENY
)
977 return FILTER_PERMIT
;
978 #undef FILTER_EXIST_WARN
981 /* If community attribute includes no_export then return 1. */
983 bgp_community_filter (struct peer
*peer
, struct attr
*attr
)
987 /* NO_ADVERTISE check. */
988 if (community_include (attr
->community
, COMMUNITY_NO_ADVERTISE
))
991 /* NO_EXPORT check. */
992 if (peer
->sort
== BGP_PEER_EBGP
&&
993 community_include (attr
->community
, COMMUNITY_NO_EXPORT
))
996 /* NO_EXPORT_SUBCONFED check. */
997 if (peer
->sort
== BGP_PEER_EBGP
998 || peer
->sort
== BGP_PEER_CONFED
)
999 if (community_include (attr
->community
, COMMUNITY_NO_EXPORT_SUBCONFED
))
1005 /* Route reflection loop check. */
1007 bgp_cluster_filter (struct peer
*peer
, struct attr
*attr
)
1009 struct in_addr cluster_id
;
1011 if (attr
->extra
&& attr
->extra
->cluster
)
1013 if (peer
->bgp
->config
& BGP_CONFIG_CLUSTER_ID
)
1014 cluster_id
= peer
->bgp
->cluster_id
;
1016 cluster_id
= peer
->bgp
->router_id
;
1018 if (cluster_loop_check (attr
->extra
->cluster
, cluster_id
))
1025 bgp_input_modifier (struct peer
*peer
, struct prefix
*p
, struct attr
*attr
,
1026 afi_t afi
, safi_t safi
, const char *rmap_name
)
1028 struct bgp_filter
*filter
;
1029 struct bgp_info info
;
1030 route_map_result_t ret
;
1031 struct route_map
*rmap
= NULL
;
1033 filter
= &peer
->filter
[afi
][safi
];
1035 /* Apply default weight value. */
1036 if (peer
->weight
[afi
][safi
])
1037 (bgp_attr_extra_get (attr
))->weight
= peer
->weight
[afi
][safi
];
1041 rmap
= route_map_lookup_by_name(rmap_name
);
1048 if (ROUTE_MAP_IN_NAME(filter
))
1050 rmap
= ROUTE_MAP_IN (filter
);
1057 /* Route map apply. */
1060 /* Duplicate current value to new strucutre for modification. */
1064 SET_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
);
1066 /* Apply BGP route map to the attribute. */
1067 ret
= route_map_apply (rmap
, p
, RMAP_BGP
, &info
);
1069 peer
->rmap_type
= 0;
1071 if (ret
== RMAP_DENYMATCH
)
1073 /* Free newly generated AS path and community by route-map. */
1074 bgp_attr_flush (attr
);
1082 bgp_output_modifier (struct peer
*peer
, struct prefix
*p
, struct attr
*attr
,
1083 afi_t afi
, safi_t safi
, const char *rmap_name
)
1085 struct bgp_filter
*filter
;
1086 struct bgp_info info
;
1087 route_map_result_t ret
;
1088 struct route_map
*rmap
= NULL
;
1090 filter
= &peer
->filter
[afi
][safi
];
1092 /* Apply default weight value. */
1093 if (peer
->weight
[afi
][safi
])
1094 (bgp_attr_extra_get (attr
))->weight
= peer
->weight
[afi
][safi
];
1098 rmap
= route_map_lookup_by_name(rmap_name
);
1105 if (ROUTE_MAP_OUT_NAME(filter
))
1107 rmap
= ROUTE_MAP_OUT (filter
);
1114 /* Route map apply. */
1117 /* Duplicate current value to new strucutre for modification. */
1121 SET_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
);
1123 /* Apply BGP route map to the attribute. */
1124 ret
= route_map_apply (rmap
, p
, RMAP_BGP
, &info
);
1126 peer
->rmap_type
= 0;
1128 if (ret
== RMAP_DENYMATCH
)
1129 /* caller has multiple error paths with bgp_attr_flush() */
1135 /* If this is an EBGP peer with remove-private-AS */
1137 bgp_peer_remove_private_as(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
1138 struct peer
*peer
, struct attr
*attr
)
1140 if (peer
->sort
== BGP_PEER_EBGP
&&
1141 (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE
) ||
1142 peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE
) ||
1143 peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_ALL
) ||
1144 peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS
)))
1146 // Take action on the entire aspath
1147 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE
) ||
1148 peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_ALL
))
1150 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE
))
1151 attr
->aspath
= aspath_replace_private_asns (attr
->aspath
, bgp
->as
);
1153 // The entire aspath consists of private ASNs so create an empty aspath
1154 else if (aspath_private_as_check (attr
->aspath
))
1155 attr
->aspath
= aspath_empty_get ();
1157 // There are some public and some private ASNs, remove the private ASNs
1159 attr
->aspath
= aspath_remove_private_asns (attr
->aspath
);
1162 // 'all' was not specified so the entire aspath must be private ASNs
1163 // for us to do anything
1164 else if (aspath_private_as_check (attr
->aspath
))
1166 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE
))
1167 attr
->aspath
= aspath_replace_private_asns (attr
->aspath
, bgp
->as
);
1169 attr
->aspath
= aspath_empty_get ();
1174 /* If this is an EBGP peer with as-override */
1176 bgp_peer_as_override(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
1177 struct peer
*peer
, struct attr
*attr
)
1179 if (peer
->sort
== BGP_PEER_EBGP
&&
1180 peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_AS_OVERRIDE
))
1182 if (aspath_single_asn_check (attr
->aspath
, peer
->as
))
1183 attr
->aspath
= aspath_replace_specific_asn (attr
->aspath
, peer
->as
, bgp
->as
);
1188 subgroup_announce_reset_nhop (u_char family
, struct attr
*attr
)
1190 if (family
== AF_INET
)
1191 attr
->nexthop
.s_addr
= 0;
1192 if (family
== AF_INET6
)
1193 memset (&attr
->extra
->mp_nexthop_global
, 0, IPV6_MAX_BYTELEN
);
1197 subgroup_announce_check (struct bgp_node
*rn
, struct bgp_info
*ri
,
1198 struct update_subgroup
*subgrp
,
1199 struct prefix
*p
, struct attr
*attr
)
1201 struct bgp_filter
*filter
;
1204 struct peer
*onlypeer
;
1206 struct attr
*riattr
;
1207 struct peer_af
*paf
;
1208 char buf
[PREFIX_STRLEN
];
1214 int samepeer_safe
= 0; /* for synthetic mplsvpns routes */
1216 if (DISABLE_BGP_ANNOUNCE
)
1219 afi
= SUBGRP_AFI(subgrp
);
1220 safi
= SUBGRP_SAFI(subgrp
);
1221 peer
= SUBGRP_PEER(subgrp
);
1223 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_LONESOUL
))
1224 onlypeer
= SUBGRP_PFIRST(subgrp
)->peer
;
1227 filter
= &peer
->filter
[afi
][safi
];
1228 bgp
= SUBGRP_INST(subgrp
);
1229 riattr
= bgp_info_mpath_count (ri
) ? bgp_info_mpath_attr (ri
) : ri
->attr
;
1232 if (((afi
== AFI_IP
) || (afi
== AFI_IP6
)) && (safi
== SAFI_MPLS_VPN
) &&
1233 ((ri
->type
== ZEBRA_ROUTE_BGP_DIRECT
) ||
1234 (ri
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
))) {
1237 * direct and direct_ext type routes originate internally even
1238 * though they can have peer pointers that reference other systems
1240 prefix2str(p
, buf
, PREFIX_STRLEN
);
1241 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__
, buf
);
1246 /* With addpath we may be asked to TX all kinds of paths so make sure
1248 if (!CHECK_FLAG (ri
->flags
, BGP_INFO_VALID
) ||
1249 CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
) ||
1250 CHECK_FLAG (ri
->flags
, BGP_INFO_REMOVED
))
1255 /* If this is not the bestpath then check to see if there is an enabled addpath
1256 * feature that requires us to advertise it */
1257 if (! CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))
1259 if (! bgp_addpath_tx_path(peer
, afi
, safi
, ri
))
1265 /* Aggregate-address suppress check. */
1266 if (ri
->extra
&& ri
->extra
->suppress
)
1267 if (! UNSUPPRESS_MAP_NAME (filter
))
1272 /* If it's labeled safi, make sure the route has a valid label. */
1273 if (bgp_labeled_safi(safi
))
1275 u_char
*tag
= bgp_adv_label(rn
, ri
, peer
, afi
, safi
);
1276 if (!bgp_is_valid_label(tag
))
1278 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1279 zlog_debug ("u%" PRIu64
":s%" PRIu64
" %s/%d is filtered - no label (%p)",
1280 subgrp
->update_group
->id
, subgrp
->id
,
1281 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
),
1287 /* Do not send back route to sender. */
1288 if (onlypeer
&& from
== onlypeer
)
1293 /* Do not send the default route in the BGP table if the neighbor is
1294 * configured for default-originate */
1295 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
))
1297 if (p
->family
== AF_INET
&& p
->u
.prefix4
.s_addr
== INADDR_ANY
)
1299 else if (p
->family
== AF_INET6
&& p
->prefixlen
== 0)
1303 /* Transparency check. */
1304 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
)
1305 && CHECK_FLAG (from
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
1310 /* If community is not disabled check the no-export and local. */
1311 if (! transparent
&& bgp_community_filter (peer
, riattr
))
1313 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1314 zlog_debug ("subgrpannouncecheck: community filter check fail");
1318 /* If the attribute has originator-id and it is same as remote
1321 riattr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
) &&
1322 (IPV4_ADDR_SAME (&onlypeer
->remote_id
, &riattr
->extra
->originator_id
)))
1324 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1325 zlog_debug ("%s [Update:SEND] %s originator-id is same as "
1327 onlypeer
->host
, prefix2str (p
, buf
, sizeof (buf
)));
1331 /* ORF prefix-list filter check */
1332 if (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_ADV
)
1333 && (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_RCV
)
1334 || CHECK_FLAG (peer
->af_cap
[afi
][safi
],
1335 PEER_CAP_ORF_PREFIX_SM_OLD_RCV
)))
1336 if (peer
->orf_plist
[afi
][safi
])
1338 if (prefix_list_apply (peer
->orf_plist
[afi
][safi
], p
) == PREFIX_DENY
)
1340 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1341 zlog_debug ("%s [Update:SEND] %s is filtered via ORF",
1342 peer
->host
, prefix2str (p
, buf
, sizeof (buf
)));
1347 /* Output filter check. */
1348 if (bgp_output_filter (peer
, p
, riattr
, afi
, safi
) == FILTER_DENY
)
1350 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1351 zlog_debug ("%s [Update:SEND] %s is filtered",
1352 peer
->host
, prefix2str (p
, buf
, sizeof (buf
)));
1356 #ifdef BGP_SEND_ASPATH_CHECK
1357 /* AS path loop check. */
1358 if (onlypeer
&& aspath_loop_check (riattr
->aspath
, onlypeer
->as
))
1360 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1361 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1362 "that is part of AS path.",
1363 onlypeer
->host
, onlypeer
->as
);
1366 #endif /* BGP_SEND_ASPATH_CHECK */
1368 /* If we're a CONFED we need to loop check the CONFED ID too */
1369 if (CHECK_FLAG(bgp
->config
, BGP_CONFIG_CONFEDERATION
))
1371 if (aspath_loop_check(riattr
->aspath
, bgp
->confed_id
))
1373 if (bgp_debug_update(NULL
, p
, subgrp
->update_group
, 0))
1374 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1382 /* Route-Reflect check. */
1383 if (from
->sort
== BGP_PEER_IBGP
&& peer
->sort
== BGP_PEER_IBGP
)
1388 /* IBGP reflection check. */
1389 if (reflect
&& !samepeer_safe
)
1391 /* A route from a Client peer. */
1392 if (CHECK_FLAG (from
->af_flags
[afi
][safi
], PEER_FLAG_REFLECTOR_CLIENT
))
1394 /* Reflect to all the Non-Client peers and also to the
1395 Client peers other than the originator. Originator check
1396 is already done. So there is noting to do. */
1397 /* no bgp client-to-client reflection check. */
1398 if (bgp_flag_check (bgp
, BGP_FLAG_NO_CLIENT_TO_CLIENT
))
1399 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
1400 PEER_FLAG_REFLECTOR_CLIENT
))
1405 /* A route from a Non-client peer. Reflect to all other
1407 if (! CHECK_FLAG (peer
->af_flags
[afi
][safi
],
1408 PEER_FLAG_REFLECTOR_CLIENT
))
1413 /* For modify attribute, copy it to temporary structure. */
1414 bgp_attr_dup (attr
, riattr
);
1416 /* If local-preference is not set. */
1417 if ((peer
->sort
== BGP_PEER_IBGP
1418 || peer
->sort
== BGP_PEER_CONFED
)
1419 && (! (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))))
1421 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1422 attr
->local_pref
= bgp
->default_local_pref
;
1425 /* If originator-id is not set and the route is to be reflected,
1426 set the originator id */
1427 if (reflect
&& (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
))))
1429 attr
->extra
= bgp_attr_extra_get(attr
);
1430 IPV4_ADDR_COPY(&(attr
->extra
->originator_id
), &(from
->remote_id
));
1431 SET_FLAG(attr
->flag
, BGP_ATTR_ORIGINATOR_ID
);
1434 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1435 if (peer
->sort
== BGP_PEER_EBGP
1436 && attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
1438 if (from
!= bgp
->peer_self
&& ! transparent
1439 && ! CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
))
1440 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
));
1443 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1444 * in announce check, only certain flags and length (or number of nexthops
1445 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1446 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1447 * Typically, the source nexthop in the attribute is preserved but in the
1448 * scenarios where we know it will always be overwritten, we reset the
1449 * nexthop to "0" in an attempt to achieve better Update packing. An
1450 * example of this is when a prefix from each of 2 IBGP peers needs to be
1451 * announced to an EBGP peer (and they have the same attributes barring
1455 SET_FLAG(attr
->rmap_change_flags
, BATTR_REFLECTED
);
1457 #define NEXTHOP_IS_V6 (\
1458 (safi != SAFI_ENCAP && safi != SAFI_MPLS_VPN &&\
1459 (p->family == AF_INET6 || peer_cap_enhe(peer, AFI_IP6, safi))) || \
1460 ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
1461 attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
1463 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1464 * the peer (group) is configured to receive link-local nexthop unchanged
1465 * and it is available in the prefix OR we're not reflecting the route and
1466 * the peer (group) to whom we're going to announce is on a shared network
1467 * and this is either a self-originated route or the peer is EBGP.
1471 attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
1472 if ((CHECK_FLAG (peer
->af_flags
[afi
][safi
],
1473 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED
) &&
1474 IN6_IS_ADDR_LINKLOCAL (&attr
->extra
->mp_nexthop_local
)) ||
1475 (!reflect
&& peer
->shared_network
&&
1476 (from
== bgp
->peer_self
|| peer
->sort
== BGP_PEER_EBGP
)))
1478 attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
1481 /* Clear off link-local nexthop in source, whenever it is not needed to
1482 * ensure more prefixes share the same attribute for announcement.
1484 if (!(CHECK_FLAG (peer
->af_flags
[afi
][safi
],
1485 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED
)))
1486 memset (&attr
->extra
->mp_nexthop_local
, 0, IPV6_MAX_BYTELEN
);
1489 bgp_peer_remove_private_as(bgp
, afi
, safi
, peer
, attr
);
1490 bgp_peer_as_override(bgp
, afi
, safi
, peer
, attr
);
1492 /* Route map & unsuppress-map apply. */
1493 if (ROUTE_MAP_OUT_NAME (filter
)
1494 || (ri
->extra
&& ri
->extra
->suppress
) )
1496 struct bgp_info info
;
1497 struct attr dummy_attr
;
1498 struct attr_extra dummy_extra
;
1500 dummy_attr
.extra
= &dummy_extra
;
1504 /* don't confuse inbound and outbound setting */
1505 RESET_FLAG(attr
->rmap_change_flags
);
1508 * The route reflector is not allowed to modify the attributes
1509 * of the reflected IBGP routes unless explicitly allowed.
1511 if ((from
->sort
== BGP_PEER_IBGP
&& peer
->sort
== BGP_PEER_IBGP
)
1512 && !bgp_flag_check(bgp
, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY
))
1514 bgp_attr_dup (&dummy_attr
, attr
);
1515 info
.attr
= &dummy_attr
;
1518 SET_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
);
1520 if (ri
->extra
&& ri
->extra
->suppress
)
1521 ret
= route_map_apply (UNSUPPRESS_MAP (filter
), p
, RMAP_BGP
, &info
);
1523 ret
= route_map_apply (ROUTE_MAP_OUT (filter
), p
, RMAP_BGP
, &info
);
1525 peer
->rmap_type
= 0;
1527 if (ret
== RMAP_DENYMATCH
)
1529 bgp_attr_flush (attr
);
1534 /* After route-map has been applied, we check to see if the nexthop to
1535 * be carried in the attribute (that is used for the announcement) can
1536 * be cleared off or not. We do this in all cases where we would be
1537 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1538 * the global nexthop here; the link-local nexthop would have been cleared
1539 * already, and if not, it is required by the update formation code.
1540 * Also see earlier comments in this function.
1543 * If route-map has performed some operation on the nexthop or the peer
1544 * configuration says to pass it unchanged, we cannot reset the nexthop
1545 * here, so only attempt to do it if these aren't true. Note that the
1546 * route-map handler itself might have cleared the nexthop, if for example,
1547 * it is configured as 'peer-address'.
1549 if (!bgp_rmap_nhop_changed(attr
->rmap_change_flags
,
1550 riattr
->rmap_change_flags
) &&
1552 !CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
))
1554 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1555 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_SELF
) ||
1556 CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_FORCE_NEXTHOP_SELF
))
1559 CHECK_FLAG (peer
->af_flags
[afi
][safi
],
1560 PEER_FLAG_FORCE_NEXTHOP_SELF
))
1561 subgroup_announce_reset_nhop ((peer_cap_enhe(peer
, afi
, safi
) ?
1562 AF_INET6
: p
->family
), attr
);
1564 else if (peer
->sort
== BGP_PEER_EBGP
)
1566 /* Can also reset the nexthop if announcing to EBGP, but only if
1567 * no peer in the subgroup is on a shared subnet.
1568 * Note: 3rd party nexthop currently implemented for IPv4 only.
1570 SUBGRP_FOREACH_PEER (subgrp
, paf
)
1572 if (bgp_multiaccess_check_v4 (riattr
->nexthop
, paf
->peer
))
1576 subgroup_announce_reset_nhop ((peer_cap_enhe(peer
, afi
, safi
) ? AF_INET6
: p
->family
), attr
);
1578 /* If IPv6/MP and nexthop does not have any override and happens to
1579 * be a link-local address, reset it so that we don't pass along the
1580 * source's link-local IPv6 address to recipients who may not be on
1581 * the same interface.
1583 if (p
->family
== AF_INET6
|| peer_cap_enhe(peer
, afi
, safi
))
1585 if (IN6_IS_ADDR_LINKLOCAL (&attr
->extra
->mp_nexthop_global
))
1586 subgroup_announce_reset_nhop (AF_INET6
, attr
);
1593 struct bgp_info_pair
1595 struct bgp_info
*old
;
1596 struct bgp_info
*new;
1600 bgp_best_selection (struct bgp
*bgp
, struct bgp_node
*rn
,
1601 struct bgp_maxpaths_cfg
*mpath_cfg
,
1602 struct bgp_info_pair
*result
)
1604 struct bgp_info
*new_select
;
1605 struct bgp_info
*old_select
;
1606 struct bgp_info
*ri
;
1607 struct bgp_info
*ri1
;
1608 struct bgp_info
*ri2
;
1609 struct bgp_info
*nextri
= NULL
;
1610 int paths_eq
, do_mpath
, debug
;
1611 struct list mp_list
;
1612 char pfx_buf
[PREFIX2STR_BUFFER
];
1613 char path_buf
[PATH_ADDPATH_STR_BUFFER
];
1615 bgp_mp_list_init (&mp_list
);
1616 do_mpath
= (mpath_cfg
->maxpaths_ebgp
> 1 || mpath_cfg
->maxpaths_ibgp
> 1);
1618 debug
= bgp_debug_bestpath(&rn
->p
);
1621 prefix2str (&rn
->p
, pfx_buf
, sizeof (pfx_buf
));
1623 /* bgp deterministic-med */
1625 if (bgp_flag_check (bgp
, BGP_FLAG_DETERMINISTIC_MED
))
1628 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1629 for (ri1
= rn
->info
; ri1
; ri1
= ri1
->next
)
1630 bgp_info_unset_flag (rn
, ri1
, BGP_INFO_DMED_SELECTED
);
1632 for (ri1
= rn
->info
; ri1
; ri1
= ri1
->next
)
1634 if (CHECK_FLAG (ri1
->flags
, BGP_INFO_DMED_CHECK
))
1636 if (BGP_INFO_HOLDDOWN (ri1
))
1638 if (ri1
->peer
&& ri1
->peer
!= bgp
->peer_self
)
1639 if (ri1
->peer
->status
!= Established
)
1645 for (ri2
= ri1
->next
; ri2
; ri2
= ri2
->next
)
1647 if (CHECK_FLAG (ri2
->flags
, BGP_INFO_DMED_CHECK
))
1649 if (BGP_INFO_HOLDDOWN (ri2
))
1652 ri2
->peer
!= bgp
->peer_self
&&
1653 !CHECK_FLAG (ri2
->peer
->sflags
, PEER_STATUS_NSF_WAIT
))
1654 if (ri2
->peer
->status
!= Established
)
1657 if (aspath_cmp_left (ri1
->attr
->aspath
, ri2
->attr
->aspath
)
1658 || aspath_cmp_left_confed (ri1
->attr
->aspath
,
1661 if (bgp_info_cmp (bgp
, ri2
, new_select
, &paths_eq
,
1662 mpath_cfg
, debug
, pfx_buf
))
1664 bgp_info_unset_flag (rn
, new_select
, BGP_INFO_DMED_SELECTED
);
1668 bgp_info_set_flag (rn
, ri2
, BGP_INFO_DMED_CHECK
);
1672 bgp_info_set_flag (rn
, new_select
, BGP_INFO_DMED_CHECK
);
1673 bgp_info_set_flag (rn
, new_select
, BGP_INFO_DMED_SELECTED
);
1677 bgp_info_path_with_addpath_rx_str (new_select
, path_buf
);
1678 zlog_debug("%s: %s is the bestpath from AS %d",
1679 pfx_buf
, path_buf
, aspath_get_first_as(new_select
->attr
->aspath
));
1684 /* Check old selected route and new selected route. */
1687 for (ri
= rn
->info
; (ri
!= NULL
) && (nextri
= ri
->next
, 1); ri
= nextri
)
1689 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))
1692 if (BGP_INFO_HOLDDOWN (ri
))
1694 /* reap REMOVED routes, if needs be
1695 * selected route must stay for a while longer though
1697 if (CHECK_FLAG (ri
->flags
, BGP_INFO_REMOVED
)
1698 && (ri
!= old_select
))
1699 bgp_info_reap (rn
, ri
);
1705 ri
->peer
!= bgp
->peer_self
&&
1706 !CHECK_FLAG (ri
->peer
->sflags
, PEER_STATUS_NSF_WAIT
))
1707 if (ri
->peer
->status
!= Established
)
1710 if (bgp_flag_check (bgp
, BGP_FLAG_DETERMINISTIC_MED
)
1711 && (! CHECK_FLAG (ri
->flags
, BGP_INFO_DMED_SELECTED
)))
1713 bgp_info_unset_flag (rn
, ri
, BGP_INFO_DMED_CHECK
);
1717 bgp_info_unset_flag (rn
, ri
, BGP_INFO_DMED_CHECK
);
1719 if (bgp_info_cmp (bgp
, ri
, new_select
, &paths_eq
, mpath_cfg
, debug
, pfx_buf
))
1725 /* Now that we know which path is the bestpath see if any of the other paths
1726 * qualify as multipaths
1731 bgp_info_path_with_addpath_rx_str (new_select
, path_buf
);
1733 sprintf (path_buf
, "NONE");
1734 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1736 old_select
? old_select
->peer
->host
: "NONE");
1739 if (do_mpath
&& new_select
)
1741 for (ri
= rn
->info
; (ri
!= NULL
) && (nextri
= ri
->next
, 1); ri
= nextri
)
1745 bgp_info_path_with_addpath_rx_str (ri
, path_buf
);
1747 if (ri
== new_select
)
1750 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1752 bgp_mp_list_add (&mp_list
, ri
);
1756 if (BGP_INFO_HOLDDOWN (ri
))
1760 ri
->peer
!= bgp
->peer_self
&&
1761 !CHECK_FLAG (ri
->peer
->sflags
, PEER_STATUS_NSF_WAIT
))
1762 if (ri
->peer
->status
!= Established
)
1765 if (!bgp_info_nexthop_cmp (ri
, new_select
))
1768 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1773 bgp_info_cmp (bgp
, ri
, new_select
, &paths_eq
, mpath_cfg
, debug
, pfx_buf
);
1778 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1780 bgp_mp_list_add (&mp_list
, ri
);
1785 bgp_info_mpath_update (rn
, new_select
, old_select
, &mp_list
, mpath_cfg
);
1786 bgp_info_mpath_aggregate_update (new_select
, old_select
);
1787 bgp_mp_list_clear (&mp_list
);
1789 result
->old
= old_select
;
1790 result
->new = new_select
;
1796 * A new route/change in bestpath of an existing route. Evaluate the path
1797 * for advertisement to the subgroup.
1800 subgroup_process_announce_selected (struct update_subgroup
*subgrp
,
1801 struct bgp_info
*selected
,
1802 struct bgp_node
*rn
,
1803 u_int32_t addpath_tx_id
)
1806 struct peer
*onlypeer
;
1808 struct attr_extra extra
;
1813 afi
= SUBGRP_AFI(subgrp
);
1814 safi
= SUBGRP_SAFI(subgrp
);
1815 onlypeer
= ((SUBGRP_PCOUNT(subgrp
) == 1) ?
1816 (SUBGRP_PFIRST(subgrp
))->peer
: NULL
);
1818 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1819 if (onlypeer
&& CHECK_FLAG (onlypeer
->af_sflags
[afi
][safi
],
1820 PEER_STATUS_ORF_WAIT_REFRESH
))
1823 memset(&extra
, 0, sizeof(struct attr_extra
));
1824 /* It's initialized in bgp_announce_check() */
1825 attr
.extra
= &extra
;
1827 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1830 if (subgroup_announce_check(rn
, selected
, subgrp
, p
, &attr
))
1831 bgp_adj_out_set_subgroup(rn
, subgrp
, &attr
, selected
);
1833 bgp_adj_out_unset_subgroup(rn
, subgrp
, 1, selected
->addpath_tx_id
);
1836 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1839 bgp_adj_out_unset_subgroup(rn
, subgrp
, 1, addpath_tx_id
);
1846 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1847 * This is called at the end of route processing.
1850 bgp_zebra_clear_route_change_flags (struct bgp_node
*rn
)
1852 struct bgp_info
*ri
;
1854 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
1856 if (BGP_INFO_HOLDDOWN (ri
))
1858 UNSET_FLAG (ri
->flags
, BGP_INFO_IGP_CHANGED
);
1859 UNSET_FLAG (ri
->flags
, BGP_INFO_ATTR_CHANGED
);
1864 * Has the route changed from the RIB's perspective? This is invoked only
1865 * if the route selection returns the same best route as earlier - to
1866 * determine if we need to update zebra or not.
1869 bgp_zebra_has_route_changed (struct bgp_node
*rn
, struct bgp_info
*selected
)
1871 struct bgp_info
*mpinfo
;
1873 /* If this is multipath, check all selected paths for any nexthop change or
1874 * attribute change. Some attribute changes (e.g., community) aren't of
1875 * relevance to the RIB, but we'll update zebra to ensure we handle the
1876 * case of BGP nexthop change. This is the behavior when the best path has
1877 * an attribute change anyway.
1879 if (CHECK_FLAG (selected
->flags
, BGP_INFO_IGP_CHANGED
) ||
1880 CHECK_FLAG (selected
->flags
, BGP_INFO_MULTIPATH_CHG
))
1883 /* If this is multipath, check all selected paths for any nexthop change */
1884 for (mpinfo
= bgp_info_mpath_first (selected
); mpinfo
;
1885 mpinfo
= bgp_info_mpath_next (mpinfo
))
1887 if (CHECK_FLAG (mpinfo
->flags
, BGP_INFO_IGP_CHANGED
)
1888 || CHECK_FLAG (mpinfo
->flags
, BGP_INFO_ATTR_CHANGED
))
1892 /* Nothing has changed from the RIB's perspective. */
1896 struct bgp_process_queue
1899 struct bgp_node
*rn
;
1904 static wq_item_status
1905 bgp_process_main (struct work_queue
*wq
, void *data
)
1907 struct bgp_process_queue
*pq
= data
;
1908 struct bgp
*bgp
= pq
->bgp
;
1909 struct bgp_node
*rn
= pq
->rn
;
1910 afi_t afi
= pq
->afi
;
1911 safi_t safi
= pq
->safi
;
1912 struct prefix
*p
= &rn
->p
;
1913 struct bgp_info
*new_select
;
1914 struct bgp_info
*old_select
;
1915 struct bgp_info_pair old_and_new
;
1917 /* Is it end of initial update? (after startup) */
1920 quagga_timestamp(3, bgp
->update_delay_zebra_resume_time
,
1921 sizeof(bgp
->update_delay_zebra_resume_time
));
1923 bgp
->main_zebra_update_hold
= 0;
1924 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1925 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1927 bgp_zebra_announce_table(bgp
, afi
, safi
);
1929 bgp
->main_peers_update_hold
= 0;
1931 bgp_start_routeadv(bgp
);
1935 /* Best path selection. */
1936 bgp_best_selection (bgp
, rn
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
);
1937 old_select
= old_and_new
.old
;
1938 new_select
= old_and_new
.new;
1940 /* Do we need to allocate or free labels?
1941 * Right now, since we only deal with per-prefix labels, it is not necessary
1942 * to do this upon changes to best path except of the label index changes.
1944 bgp_table_lock (bgp_node_table (rn
));
1945 if (bgp_labeled_safi (safi
))
1950 bgp_label_index_differs (new_select
, old_select
) ||
1951 new_select
->sub_type
!= old_select
->sub_type
)
1953 if (new_select
->sub_type
== BGP_ROUTE_STATIC
&&
1954 new_select
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
) &&
1955 new_select
->attr
->extra
->label_index
!= BGP_INVALID_LABEL_INDEX
)
1957 if (CHECK_FLAG (rn
->flags
, BGP_NODE_REGISTERED_FOR_LABEL
))
1958 bgp_unregister_for_label (rn
);
1959 label_ntop (MPLS_IMP_NULL_LABEL
, 1, rn
->local_label
);
1960 bgp_set_valid_label(rn
->local_label
);
1963 bgp_register_for_label (rn
, new_select
);
1966 else if (CHECK_FLAG (rn
->flags
, BGP_NODE_REGISTERED_FOR_LABEL
))
1967 bgp_unregister_for_label (rn
);
1970 /* If best route remains the same and this is not due to user-initiated
1971 * clear, see exactly what needs to be done.
1974 if (old_select
&& old_select
== new_select
&&
1975 !CHECK_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
) &&
1976 !CHECK_FLAG(old_select
->flags
, BGP_INFO_ATTR_CHANGED
) &&
1977 !bgp
->addpath_tx_used
[afi
][safi
])
1979 if (bgp_zebra_has_route_changed (rn
, old_select
))
1982 vnc_import_bgp_add_route(bgp
, p
, old_select
);
1983 vnc_import_bgp_exterior_add_route(bgp
, p
, old_select
);
1985 if (bgp_fibupd_safi(safi
) &&
1987 !bgp_option_check (BGP_OPT_NO_FIB
) &&
1988 new_select
->type
== ZEBRA_ROUTE_BGP
&&
1989 new_select
->sub_type
== BGP_ROUTE_NORMAL
)
1990 bgp_zebra_announce (rn
, p
, old_select
, bgp
, afi
, safi
);
1992 UNSET_FLAG (old_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
1993 bgp_zebra_clear_route_change_flags (rn
);
1995 /* If there is a change of interest to peers, reannounce the route. */
1996 if (CHECK_FLAG (old_select
->flags
, BGP_INFO_ATTR_CHANGED
) ||
1997 CHECK_FLAG (rn
->flags
, BGP_NODE_LABEL_CHANGED
))
1999 group_announce_route(bgp
, afi
, safi
, rn
, new_select
);
2001 UNSET_FLAG (old_select
->flags
, BGP_INFO_ATTR_CHANGED
);
2002 UNSET_FLAG (rn
->flags
, BGP_NODE_LABEL_CHANGED
);
2005 UNSET_FLAG (rn
->flags
, BGP_NODE_PROCESS_SCHEDULED
);
2009 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2010 UNSET_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
);
2012 /* bestpath has changed; bump version */
2013 if (old_select
|| new_select
)
2015 bgp_bump_version(rn
);
2017 if (!bgp
->t_rmap_def_originate_eval
)
2020 thread_add_timer(bm
->master
,
2021 update_group_refresh_default_originate_route_map
,
2022 bgp
, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER
,
2023 &bgp
->t_rmap_def_originate_eval
);
2028 bgp_info_unset_flag (rn
, old_select
, BGP_INFO_SELECTED
);
2031 bgp_info_set_flag (rn
, new_select
, BGP_INFO_SELECTED
);
2032 bgp_info_unset_flag (rn
, new_select
, BGP_INFO_ATTR_CHANGED
);
2033 UNSET_FLAG (new_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
2037 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
)) {
2038 if (old_select
!= new_select
) {
2040 vnc_import_bgp_exterior_del_route(bgp
, p
, old_select
);
2041 vnc_import_bgp_del_route(bgp
, p
, old_select
);
2044 vnc_import_bgp_exterior_add_route(bgp
, p
, new_select
);
2045 vnc_import_bgp_add_route(bgp
, p
, new_select
);
2051 group_announce_route(bgp
, afi
, safi
, rn
, new_select
);
2054 if (bgp_fibupd_safi(safi
) &&
2055 (bgp
->inst_type
!= BGP_INSTANCE_TYPE_VIEW
) &&
2056 !bgp_option_check (BGP_OPT_NO_FIB
))
2059 && new_select
->type
== ZEBRA_ROUTE_BGP
2060 && (new_select
->sub_type
== BGP_ROUTE_NORMAL
||
2061 new_select
->sub_type
== BGP_ROUTE_AGGREGATE
))
2062 bgp_zebra_announce (rn
, p
, new_select
, bgp
, afi
, safi
);
2065 /* Withdraw the route from the kernel. */
2067 && old_select
->type
== ZEBRA_ROUTE_BGP
2068 && (old_select
->sub_type
== BGP_ROUTE_NORMAL
||
2069 old_select
->sub_type
== BGP_ROUTE_AGGREGATE
))
2070 bgp_zebra_withdraw (p
, old_select
, safi
);
2074 /* Clear any route change flags. */
2075 bgp_zebra_clear_route_change_flags (rn
);
2077 /* Reap old select bgp_info, if it has been removed */
2078 if (old_select
&& CHECK_FLAG (old_select
->flags
, BGP_INFO_REMOVED
))
2079 bgp_info_reap (rn
, old_select
);
2081 UNSET_FLAG (rn
->flags
, BGP_NODE_PROCESS_SCHEDULED
);
2086 bgp_processq_del (struct work_queue
*wq
, void *data
)
2088 struct bgp_process_queue
*pq
= data
;
2089 struct bgp_table
*table
;
2091 bgp_unlock (pq
->bgp
);
2094 table
= bgp_node_table (pq
->rn
);
2095 bgp_unlock_node (pq
->rn
);
2096 bgp_table_unlock (table
);
2098 XFREE (MTYPE_BGP_PROCESS_QUEUE
, pq
);
2102 bgp_process_queue_init (void)
2104 if (!bm
->process_main_queue
)
2106 bm
->process_main_queue
2107 = work_queue_new (bm
->master
, "process_main_queue");
2109 if ( !bm
->process_main_queue
)
2111 zlog_err ("%s: Failed to allocate work queue", __func__
);
2116 bm
->process_main_queue
->spec
.workfunc
= &bgp_process_main
;
2117 bm
->process_main_queue
->spec
.del_item_data
= &bgp_processq_del
;
2118 bm
->process_main_queue
->spec
.max_retries
= 0;
2119 bm
->process_main_queue
->spec
.hold
= 50;
2120 /* Use a higher yield value of 50ms for main queue processing */
2121 bm
->process_main_queue
->spec
.yield
= 50 * 1000L;
2125 bgp_process (struct bgp
*bgp
, struct bgp_node
*rn
, afi_t afi
, safi_t safi
)
2127 struct bgp_process_queue
*pqnode
;
2129 /* already scheduled for processing? */
2130 if (CHECK_FLAG (rn
->flags
, BGP_NODE_PROCESS_SCHEDULED
))
2133 if (bm
->process_main_queue
== NULL
)
2136 pqnode
= XCALLOC (MTYPE_BGP_PROCESS_QUEUE
,
2137 sizeof (struct bgp_process_queue
));
2141 /* all unlocked in bgp_processq_del */
2142 bgp_table_lock (bgp_node_table (rn
));
2143 pqnode
->rn
= bgp_lock_node (rn
);
2147 pqnode
->safi
= safi
;
2148 work_queue_add (bm
->process_main_queue
, pqnode
);
2149 SET_FLAG (rn
->flags
, BGP_NODE_PROCESS_SCHEDULED
);
2154 bgp_add_eoiu_mark (struct bgp
*bgp
)
2156 struct bgp_process_queue
*pqnode
;
2158 if (bm
->process_main_queue
== NULL
)
2161 pqnode
= XCALLOC (MTYPE_BGP_PROCESS_QUEUE
,
2162 sizeof (struct bgp_process_queue
));
2169 work_queue_add (bm
->process_main_queue
, pqnode
);
2173 bgp_maximum_prefix_restart_timer (struct thread
*thread
)
2177 peer
= THREAD_ARG (thread
);
2178 peer
->t_pmax_restart
= NULL
;
2180 if (bgp_debug_neighbor_events(peer
))
2181 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2184 peer_clear (peer
, NULL
);
2190 bgp_maximum_prefix_overflow (struct peer
*peer
, afi_t afi
,
2191 safi_t safi
, int always
)
2196 if (!CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
))
2199 if (peer
->pcount
[afi
][safi
] > peer
->pmax
[afi
][safi
])
2201 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_LIMIT
)
2205 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2206 "limit %ld", afi_safi_print (afi
, safi
), peer
->host
,
2207 peer
->pcount
[afi
][safi
], peer
->pmax
[afi
][safi
]);
2208 SET_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_LIMIT
);
2210 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
))
2213 /* Convert AFI, SAFI to values for packet. */
2214 pkt_afi
= afi_int2iana (afi
);
2215 pkt_safi
= safi_int2iana (safi
);
2219 ndata
[0] = (pkt_afi
>> 8);
2221 ndata
[2] = pkt_safi
;
2222 ndata
[3] = (peer
->pmax
[afi
][safi
] >> 24);
2223 ndata
[4] = (peer
->pmax
[afi
][safi
] >> 16);
2224 ndata
[5] = (peer
->pmax
[afi
][safi
] >> 8);
2225 ndata
[6] = (peer
->pmax
[afi
][safi
]);
2227 SET_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
);
2228 bgp_notify_send_with_data (peer
, BGP_NOTIFY_CEASE
,
2229 BGP_NOTIFY_CEASE_MAX_PREFIX
, ndata
, 7);
2232 /* Dynamic peers will just close their connection. */
2233 if (peer_dynamic_neighbor (peer
))
2236 /* restart timer start */
2237 if (peer
->pmax_restart
[afi
][safi
])
2239 peer
->v_pmax_restart
= peer
->pmax_restart
[afi
][safi
] * 60;
2241 if (bgp_debug_neighbor_events(peer
))
2242 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2243 peer
->host
, peer
->v_pmax_restart
);
2245 BGP_TIMER_ON (peer
->t_pmax_restart
, bgp_maximum_prefix_restart_timer
,
2246 peer
->v_pmax_restart
);
2252 UNSET_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_LIMIT
);
2254 if (peer
->pcount
[afi
][safi
] > (peer
->pmax
[afi
][safi
] * peer
->pmax_threshold
[afi
][safi
] / 100))
2256 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_THRESHOLD
)
2260 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2261 afi_safi_print (afi
, safi
), peer
->host
, peer
->pcount
[afi
][safi
],
2262 peer
->pmax
[afi
][safi
]);
2263 SET_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_THRESHOLD
);
2266 UNSET_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_PREFIX_THRESHOLD
);
2270 /* Unconditionally remove the route from the RIB, without taking
2271 * damping into consideration (eg, because the session went down)
2274 bgp_rib_remove (struct bgp_node
*rn
, struct bgp_info
*ri
, struct peer
*peer
,
2275 afi_t afi
, safi_t safi
)
2277 bgp_aggregate_decrement (peer
->bgp
, &rn
->p
, ri
, afi
, safi
);
2279 if (!CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
2280 bgp_info_delete (rn
, ri
); /* keep historical info */
2282 bgp_process (peer
->bgp
, rn
, afi
, safi
);
2286 bgp_rib_withdraw (struct bgp_node
*rn
, struct bgp_info
*ri
, struct peer
*peer
,
2287 afi_t afi
, safi_t safi
, struct prefix_rd
*prd
)
2289 int status
= BGP_DAMP_NONE
;
2291 /* apply dampening, if result is suppressed, we'll be retaining
2292 * the bgp_info in the RIB for historical reference.
2294 if (CHECK_FLAG (peer
->bgp
->af_flags
[afi
][safi
], BGP_CONFIG_DAMPENING
)
2295 && peer
->sort
== BGP_PEER_EBGP
)
2296 if ( (status
= bgp_damp_withdraw (ri
, rn
, afi
, safi
, 0))
2297 == BGP_DAMP_SUPPRESSED
)
2299 bgp_aggregate_decrement (peer
->bgp
, &rn
->p
, ri
, afi
, safi
);
2304 if (safi
== SAFI_MPLS_VPN
) {
2305 struct bgp_node
*prn
= NULL
;
2306 struct bgp_table
*table
= NULL
;
2308 prn
= bgp_node_get(peer
->bgp
->rib
[afi
][safi
], (struct prefix
*) prd
);
2310 table
= (struct bgp_table
*)(prn
->info
);
2312 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2319 bgp_unlock_node(prn
);
2321 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
)) {
2322 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)) {
2324 vnc_import_bgp_del_route(peer
->bgp
, &rn
->p
, ri
);
2325 vnc_import_bgp_exterior_del_route(peer
->bgp
, &rn
->p
, ri
);
2329 bgp_rib_remove (rn
, ri
, peer
, afi
, safi
);
2332 static struct bgp_info
*
2333 info_make (int type
, int sub_type
, u_short instance
, struct peer
*peer
, struct attr
*attr
,
2334 struct bgp_node
*rn
)
2336 struct bgp_info
*new;
2338 /* Make new BGP info. */
2339 new = XCALLOC (MTYPE_BGP_ROUTE
, sizeof (struct bgp_info
));
2341 new->instance
= instance
;
2342 new->sub_type
= sub_type
;
2345 new->uptime
= bgp_clock ();
2347 new->addpath_tx_id
= ++peer
->bgp
->addpath_tx_id
;
2352 overlay_index_update(struct attr
*attr
, struct eth_segment_id
*eth_s_id
, union gw_addr
*gw_ip
)
2354 struct attr_extra
*extra
;
2358 extra
= bgp_attr_extra_get(attr
);
2360 if(eth_s_id
== NULL
)
2362 memset(&(extra
->evpn_overlay
.eth_s_id
),0, sizeof(struct eth_segment_id
));
2366 memcpy(&(extra
->evpn_overlay
.eth_s_id
), eth_s_id
, sizeof(struct eth_segment_id
));
2370 memset(&(extra
->evpn_overlay
.gw_ip
), 0, sizeof(union gw_addr
));
2374 memcpy(&(extra
->evpn_overlay
.gw_ip
),gw_ip
, sizeof(union gw_addr
));
2379 overlay_index_equal(afi_t afi
, struct bgp_info
*info
, struct eth_segment_id
*eth_s_id
, union gw_addr
*gw_ip
)
2381 struct eth_segment_id
*info_eth_s_id
, *info_eth_s_id_remote
;
2382 union gw_addr
*info_gw_ip
, *info_gw_ip_remote
;
2385 if(afi
!= AFI_L2VPN
)
2387 if (!info
->attr
|| !info
->attr
->extra
)
2389 memset(&temp
, 0, 16);
2390 info_eth_s_id
= (struct eth_segment_id
*)&temp
;
2391 info_gw_ip
= (union gw_addr
*)&temp
;
2392 if(eth_s_id
== NULL
&& gw_ip
== NULL
)
2397 info_eth_s_id
= &(info
->attr
->extra
->evpn_overlay
.eth_s_id
);
2398 info_gw_ip
= &(info
->attr
->extra
->evpn_overlay
.gw_ip
);
2401 info_gw_ip_remote
= (union gw_addr
*)&temp
;
2403 info_gw_ip_remote
= gw_ip
;
2404 if(eth_s_id
== NULL
)
2405 info_eth_s_id_remote
= (struct eth_segment_id
*)&temp
;
2407 info_eth_s_id_remote
= eth_s_id
;
2408 if(!memcmp(info_gw_ip
, info_gw_ip_remote
, sizeof(union gw_addr
)))
2410 return !memcmp(info_eth_s_id
, info_eth_s_id_remote
, sizeof(struct eth_segment_id
));
2413 /* Check if received nexthop is valid or not. */
2415 bgp_update_martian_nexthop (struct bgp
*bgp
, afi_t afi
, safi_t safi
, struct attr
*attr
)
2417 struct attr_extra
*attre
= attr
->extra
;
2420 /* Only validated for unicast and multicast currently. */
2421 if (safi
!= SAFI_UNICAST
&& safi
!= SAFI_MULTICAST
)
2424 /* If NEXT_HOP is present, validate it. */
2425 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
))
2427 if (attr
->nexthop
.s_addr
== 0 ||
2428 IPV4_CLASS_DE (ntohl (attr
->nexthop
.s_addr
)) ||
2429 bgp_nexthop_self (bgp
, attr
))
2433 /* If MP_NEXTHOP is present, validate it. */
2434 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2435 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2436 * it is not an IPv6 link-local address.
2438 if (attre
&& attre
->mp_nexthop_len
)
2440 switch (attre
->mp_nexthop_len
)
2442 case BGP_ATTR_NHLEN_IPV4
:
2443 case BGP_ATTR_NHLEN_VPNV4
:
2444 ret
= (attre
->mp_nexthop_global_in
.s_addr
== 0 ||
2445 IPV4_CLASS_DE (ntohl (attre
->mp_nexthop_global_in
.s_addr
)));
2448 case BGP_ATTR_NHLEN_IPV6_GLOBAL
:
2449 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
:
2450 case BGP_ATTR_NHLEN_VPNV6_GLOBAL
:
2451 ret
= (IN6_IS_ADDR_UNSPECIFIED(&attre
->mp_nexthop_global
) ||
2452 IN6_IS_ADDR_LOOPBACK(&attre
->mp_nexthop_global
) ||
2453 IN6_IS_ADDR_MULTICAST(&attre
->mp_nexthop_global
));
2466 bgp_update (struct peer
*peer
, struct prefix
*p
, u_int32_t addpath_id
,
2467 struct attr
*attr
, afi_t afi
, safi_t safi
, int type
,
2468 int sub_type
, struct prefix_rd
*prd
, u_char
*tag
,
2469 int soft_reconfig
, struct bgp_route_evpn
* evpn
)
2472 int aspath_loop_count
= 0;
2473 struct bgp_node
*rn
;
2475 struct attr new_attr
;
2476 struct attr_extra new_extra
;
2477 struct attr
*attr_new
;
2478 struct bgp_info
*ri
;
2479 struct bgp_info
*new;
2481 char pfx_buf
[BGP_PRD_PATH_STRLEN
];
2484 int do_loop_check
= 1;
2486 int vnc_implicit_withdraw
= 0;
2489 memset (&new_attr
, 0, sizeof(struct attr
));
2490 memset (&new_extra
, 0, sizeof(struct attr_extra
));
2493 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
2494 label_buf
[0] = '\0';
2495 if (bgp_labeled_safi(safi
))
2496 sprintf (label_buf
, "label %u", label_pton(tag
));
2498 /* When peer's soft reconfiguration enabled. Record input packet in
2500 if (! soft_reconfig
&& CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
)
2501 && peer
!= bgp
->peer_self
)
2502 bgp_adj_in_set (rn
, peer
, attr
, addpath_id
);
2504 /* Check previously received route. */
2505 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2506 if (ri
->peer
== peer
&& ri
->type
== type
&& ri
->sub_type
== sub_type
&&
2507 ri
->addpath_rx_id
== addpath_id
)
2510 /* AS path local-as loop check. */
2511 if (peer
->change_local_as
)
2513 if (! CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
))
2514 aspath_loop_count
= 1;
2516 if (aspath_loop_check (attr
->aspath
, peer
->change_local_as
) > aspath_loop_count
)
2518 reason
= "as-path contains our own AS;";
2523 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2524 * as-path is our ASN then we do not need to call aspath_loop_check
2526 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN_ORIGIN
))
2527 if (aspath_get_last_as(attr
->aspath
) == bgp
->as
)
2530 /* AS path loop check. */
2533 if (aspath_loop_check (attr
->aspath
, bgp
->as
) > peer
->allowas_in
[afi
][safi
]
2534 || (CHECK_FLAG(bgp
->config
, BGP_CONFIG_CONFEDERATION
)
2535 && aspath_loop_check(attr
->aspath
, bgp
->confed_id
) > peer
->allowas_in
[afi
][safi
]))
2537 reason
= "as-path contains our own AS;";
2542 /* Route reflector originator ID check. */
2543 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
)
2544 && IPV4_ADDR_SAME (&bgp
->router_id
, &attr
->extra
->originator_id
))
2546 reason
= "originator is us;";
2550 /* Route reflector cluster ID check. */
2551 if (bgp_cluster_filter (peer
, attr
))
2553 reason
= "reflected from the same cluster;";
2557 /* Apply incoming filter. */
2558 if (bgp_input_filter (peer
, p
, attr
, afi
, safi
) == FILTER_DENY
)
2564 new_attr
.extra
= &new_extra
;
2565 bgp_attr_dup (&new_attr
, attr
);
2567 /* Apply incoming route-map.
2568 * NB: new_attr may now contain newly allocated values from route-map "set"
2569 * commands, so we need bgp_attr_flush in the error paths, until we intern
2570 * the attr (which takes over the memory references) */
2571 if (bgp_input_modifier (peer
, p
, &new_attr
, afi
, safi
, NULL
) == RMAP_DENY
)
2573 reason
= "route-map;";
2574 bgp_attr_flush (&new_attr
);
2578 /* next hop check. */
2579 if (bgp_update_martian_nexthop (bgp
, afi
, safi
, &new_attr
))
2581 reason
= "martian or self next-hop;";
2582 bgp_attr_flush (&new_attr
);
2586 attr_new
= bgp_attr_intern (&new_attr
);
2588 /* If the update is implicit withdraw. */
2591 ri
->uptime
= bgp_clock ();
2593 /* Same attribute comes in. */
2594 if (!CHECK_FLAG (ri
->flags
, BGP_INFO_REMOVED
)
2595 && attrhash_cmp (ri
->attr
, attr_new
)
2596 && (!bgp_labeled_safi(safi
) ||
2597 memcmp ((bgp_info_extra_get (ri
))->tag
, tag
, 3) == 0)
2598 && (overlay_index_equal(afi
, ri
, evpn
==NULL
?NULL
:&evpn
->eth_s_id
,
2599 evpn
==NULL
?NULL
:&evpn
->gw_ip
)))
2601 if (CHECK_FLAG (bgp
->af_flags
[afi
][safi
], BGP_CONFIG_DAMPENING
)
2602 && peer
->sort
== BGP_PEER_EBGP
2603 && CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
2605 if (bgp_debug_update(peer
, p
, NULL
, 1))
2606 zlog_debug ("%s rcvd %s %s", peer
->host
,
2607 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
2608 addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
);
2610 if (bgp_damp_update (ri
, rn
, afi
, safi
) != BGP_DAMP_SUPPRESSED
)
2612 bgp_aggregate_increment (bgp
, p
, ri
, afi
, safi
);
2613 bgp_process (bgp
, rn
, afi
, safi
);
2616 else /* Duplicate - odd */
2618 if (bgp_debug_update(peer
, p
, NULL
, 1))
2620 if (!peer
->rcvd_attr_printed
)
2622 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer
->host
, peer
->rcvd_attr_str
);
2623 peer
->rcvd_attr_printed
= 1;
2626 zlog_debug ("%s rcvd %s %s...duplicate ignored",
2628 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
?
2629 1 : 0, addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
);
2632 /* graceful restart STALE flag unset. */
2633 if (CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
))
2635 bgp_info_unset_flag (rn
, ri
, BGP_INFO_STALE
);
2636 bgp_process (bgp
, rn
, afi
, safi
);
2640 bgp_unlock_node (rn
);
2641 bgp_attr_unintern (&attr_new
);
2646 /* Withdraw/Announce before we fully processed the withdraw */
2647 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
2649 if (bgp_debug_update(peer
, p
, NULL
, 1))
2650 zlog_debug ("%s rcvd %s %s, flapped quicker than processing",
2652 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
2653 addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
);
2654 bgp_info_restore (rn
, ri
);
2657 /* Received Logging. */
2658 if (bgp_debug_update(peer
, p
, NULL
, 1))
2659 zlog_debug ("%s rcvd %s %s", peer
->host
,
2660 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
2661 addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
);
2663 /* graceful restart STALE flag unset. */
2664 if (CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
))
2665 bgp_info_unset_flag (rn
, ri
, BGP_INFO_STALE
);
2667 /* The attribute is changed. */
2668 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
2670 /* implicit withdraw, decrement aggregate and pcount here.
2671 * only if update is accepted, they'll increment below.
2673 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, safi
);
2675 /* Update bgp route dampening information. */
2676 if (CHECK_FLAG (bgp
->af_flags
[afi
][safi
], BGP_CONFIG_DAMPENING
)
2677 && peer
->sort
== BGP_PEER_EBGP
)
2679 /* This is implicit withdraw so we should update dampening
2681 if (! CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
2682 bgp_damp_withdraw (ri
, rn
, afi
, safi
, 1);
2685 if (safi
== SAFI_MPLS_VPN
) {
2686 struct bgp_node
*prn
= NULL
;
2687 struct bgp_table
*table
= NULL
;
2689 prn
= bgp_node_get(bgp
->rib
[afi
][safi
], (struct prefix
*) prd
);
2691 table
= (struct bgp_table
*)(prn
->info
);
2693 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2700 bgp_unlock_node(prn
);
2702 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
)) {
2703 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)) {
2705 * Implicit withdraw case.
2707 ++vnc_implicit_withdraw
;
2708 vnc_import_bgp_del_route(bgp
, p
, ri
);
2709 vnc_import_bgp_exterior_del_route(bgp
, p
, ri
);
2714 /* Update to new attribute. */
2715 bgp_attr_unintern (&ri
->attr
);
2716 ri
->attr
= attr_new
;
2718 /* Update MPLS tag. */
2719 if (bgp_labeled_safi(safi
))
2720 memcpy ((bgp_info_extra_get (ri
))->tag
, tag
, 3);
2723 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
))
2725 if (vnc_implicit_withdraw
)
2728 * Add back the route with its new attributes (e.g., nexthop).
2729 * The route is still selected, until the route selection
2730 * queued by bgp_process actually runs. We have to make this
2731 * update to the VNC side immediately to avoid racing against
2732 * configuration changes (e.g., route-map changes) which
2733 * trigger re-importation of the entire RIB.
2735 vnc_import_bgp_add_route(bgp
, p
, ri
);
2736 vnc_import_bgp_exterior_add_route(bgp
, p
, ri
);
2740 /* Update Overlay Index */
2741 if(afi
== AFI_L2VPN
)
2743 overlay_index_update(ri
->attr
, evpn
==NULL
?NULL
:&evpn
->eth_s_id
,
2744 evpn
==NULL
?NULL
:&evpn
->gw_ip
);
2747 /* Update bgp route dampening information. */
2748 if (CHECK_FLAG (bgp
->af_flags
[afi
][safi
], BGP_CONFIG_DAMPENING
)
2749 && peer
->sort
== BGP_PEER_EBGP
)
2751 /* Now we do normal update dampening. */
2752 ret
= bgp_damp_update (ri
, rn
, afi
, safi
);
2753 if (ret
== BGP_DAMP_SUPPRESSED
)
2755 bgp_unlock_node (rn
);
2760 /* Nexthop reachability check - for unicast and labeled-unicast.. */
2761 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) &&
2762 (safi
== SAFI_UNICAST
|| safi
== SAFI_LABELED_UNICAST
))
2764 if (peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
== 1 &&
2765 ! CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
2766 && ! bgp_flag_check(bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
2771 if (bgp_find_or_add_nexthop (bgp
, afi
, ri
, NULL
, connected
))
2772 bgp_info_set_flag (rn
, ri
, BGP_INFO_VALID
);
2775 if (BGP_DEBUG(nht
, NHT
))
2777 char buf1
[INET6_ADDRSTRLEN
];
2778 inet_ntop(AF_INET
, (const void *)&attr_new
->nexthop
, buf1
, INET6_ADDRSTRLEN
);
2779 zlog_debug("%s(%s): NH unresolved", __FUNCTION__
, buf1
);
2781 bgp_info_unset_flag (rn
, ri
, BGP_INFO_VALID
);
2785 bgp_info_set_flag (rn
, ri
, BGP_INFO_VALID
);
2788 if (safi
== SAFI_MPLS_VPN
)
2790 struct bgp_node
*prn
= NULL
;
2791 struct bgp_table
*table
= NULL
;
2793 prn
= bgp_node_get(bgp
->rib
[afi
][safi
], (struct prefix
*) prd
);
2796 table
= (struct bgp_table
*)(prn
->info
);
2798 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2805 bgp_unlock_node(prn
);
2809 /* Process change. */
2810 bgp_aggregate_increment (bgp
, p
, ri
, afi
, safi
);
2812 bgp_process (bgp
, rn
, afi
, safi
);
2813 bgp_unlock_node (rn
);
2816 if (SAFI_MPLS_VPN
== safi
)
2818 uint32_t label
= decode_label(tag
);
2820 rfapiProcessUpdate(peer
, NULL
, p
, prd
, attr
, afi
, safi
, type
, sub_type
,
2823 if (SAFI_ENCAP
== safi
)
2825 rfapiProcessUpdate(peer
, NULL
, p
, prd
, attr
, afi
, safi
, type
, sub_type
,
2831 } // End of implicit withdraw
2833 /* Received Logging. */
2834 if (bgp_debug_update(peer
, p
, NULL
, 1))
2836 if (!peer
->rcvd_attr_printed
)
2838 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer
->host
, peer
->rcvd_attr_str
);
2839 peer
->rcvd_attr_printed
= 1;
2842 zlog_debug ("%s rcvd %s%s ", peer
->host
,
2843 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
2844 addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
);
2847 /* Make new BGP info. */
2848 new = info_make(type
, sub_type
, 0, peer
, attr_new
, rn
);
2850 /* Update MPLS tag. */
2851 if (bgp_labeled_safi(safi
) || safi
== SAFI_EVPN
)
2852 memcpy ((bgp_info_extra_get (new))->tag
, tag
, 3);
2854 /* Update Overlay Index */
2855 if(afi
== AFI_L2VPN
)
2857 overlay_index_update(new->attr
, evpn
==NULL
?NULL
:&evpn
->eth_s_id
,
2858 evpn
==NULL
?NULL
:&evpn
->gw_ip
);
2860 /* Nexthop reachability check. */
2861 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) &&
2862 (safi
== SAFI_UNICAST
|| safi
== SAFI_LABELED_UNICAST
))
2864 if (peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
== 1 &&
2865 ! CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
2866 && ! bgp_flag_check(bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
2871 if (bgp_find_or_add_nexthop (bgp
, afi
, new, NULL
, connected
))
2872 bgp_info_set_flag (rn
, new, BGP_INFO_VALID
);
2875 if (BGP_DEBUG(nht
, NHT
))
2877 char buf1
[INET6_ADDRSTRLEN
];
2878 inet_ntop(AF_INET
, (const void *)&attr_new
->nexthop
, buf1
, INET6_ADDRSTRLEN
);
2879 zlog_debug("%s(%s): NH unresolved", __FUNCTION__
, buf1
);
2881 bgp_info_unset_flag (rn
, new, BGP_INFO_VALID
);
2885 bgp_info_set_flag (rn
, new, BGP_INFO_VALID
);
2888 new->addpath_rx_id
= addpath_id
;
2890 /* Increment prefix */
2891 bgp_aggregate_increment (bgp
, p
, new, afi
, safi
);
2893 /* Register new BGP information. */
2894 bgp_info_add (rn
, new);
2896 /* route_node_get lock */
2897 bgp_unlock_node (rn
);
2900 if (safi
== SAFI_MPLS_VPN
)
2902 struct bgp_node
*prn
= NULL
;
2903 struct bgp_table
*table
= NULL
;
2905 prn
= bgp_node_get(bgp
->rib
[afi
][safi
], (struct prefix
*) prd
);
2908 table
= (struct bgp_table
*)(prn
->info
);
2910 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2917 bgp_unlock_node(prn
);
2921 /* If maximum prefix count is configured and current prefix
2923 if (bgp_maximum_prefix_overflow (peer
, afi
, safi
, 0))
2926 /* Process change. */
2927 bgp_process (bgp
, rn
, afi
, safi
);
2930 if (SAFI_MPLS_VPN
== safi
)
2932 uint32_t label
= decode_label(tag
);
2934 rfapiProcessUpdate(peer
, NULL
, p
, prd
, attr
, afi
, safi
, type
, sub_type
,
2937 if (SAFI_ENCAP
== safi
)
2939 rfapiProcessUpdate(peer
, NULL
, p
, prd
, attr
, afi
, safi
, type
, sub_type
,
2946 /* This BGP update is filtered. Log the reason then update BGP
2949 if (bgp_debug_update(peer
, p
, NULL
, 1))
2951 if (!peer
->rcvd_attr_printed
)
2953 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer
->host
, peer
->rcvd_attr_str
);
2954 peer
->rcvd_attr_printed
= 1;
2957 zlog_debug ("%s rcvd UPDATE about %s %s -- DENIED due to: %s",
2959 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
2960 addpath_id
, pfx_buf
, sizeof (pfx_buf
)), label_buf
, reason
);
2964 bgp_rib_remove (rn
, ri
, peer
, afi
, safi
);
2966 bgp_unlock_node (rn
);
2970 * Filtered update is treated as an implicit withdrawal (see bgp_rib_remove()
2971 * a few lines above)
2973 if ((SAFI_MPLS_VPN
== safi
) || (SAFI_ENCAP
== safi
))
2975 rfapiProcessWithdraw(peer
, NULL
, p
, prd
, NULL
, afi
, safi
, type
, 0);
2983 bgp_withdraw (struct peer
*peer
, struct prefix
*p
, u_int32_t addpath_id
,
2984 struct attr
*attr
, afi_t afi
, safi_t safi
, int type
, int sub_type
,
2985 struct prefix_rd
*prd
, u_char
*tag
, struct bgp_route_evpn
*evpn
)
2988 char pfx_buf
[BGP_PRD_PATH_STRLEN
];
2989 struct bgp_node
*rn
;
2990 struct bgp_info
*ri
;
2993 if ((SAFI_MPLS_VPN
== safi
) || (SAFI_ENCAP
== safi
))
2995 rfapiProcessWithdraw(peer
, NULL
, p
, prd
, NULL
, afi
, safi
, type
, 0);
3002 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
3004 /* If peer is soft reconfiguration enabled. Record input packet for
3005 * further calculation.
3007 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
3008 * routes that are filtered. This tanks out Quagga RS pretty badly due to
3009 * the iteration over all RS clients.
3010 * Since we need to remove the entry from adj_in anyway, do that first and
3011 * if there was no entry, we don't need to do anything more.
3013 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
)
3014 && peer
!= bgp
->peer_self
)
3015 if (!bgp_adj_in_unset (rn
, peer
, addpath_id
))
3017 if (bgp_debug_update (peer
, p
, NULL
, 1))
3018 zlog_debug ("%s withdrawing route %s not in adj-in",
3020 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
3021 addpath_id
, pfx_buf
, sizeof (pfx_buf
)));
3022 bgp_unlock_node (rn
);
3026 /* Lookup withdrawn route. */
3027 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3028 if (ri
->peer
== peer
&& ri
->type
== type
&& ri
->sub_type
== sub_type
&&
3029 ri
->addpath_rx_id
== addpath_id
)
3033 if (bgp_debug_update(peer
, p
, NULL
, 1))
3035 zlog_debug ("%s rcvd UPDATE about %s -- withdrawn",
3037 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
3038 addpath_id
, pfx_buf
, sizeof (pfx_buf
)));
3041 /* Withdraw specified route from routing table. */
3042 if (ri
&& ! CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
3043 bgp_rib_withdraw (rn
, ri
, peer
, afi
, safi
, prd
);
3044 else if (bgp_debug_update(peer
, p
, NULL
, 1))
3045 zlog_debug ("%s Can't find the route %s",
3047 bgp_debug_rdpfxpath2str (prd
, p
, addpath_id
? 1 : 0,
3048 addpath_id
, pfx_buf
, sizeof (pfx_buf
)));
3050 /* Unlock bgp_node_get() lock. */
3051 bgp_unlock_node (rn
);
3057 bgp_default_originate (struct peer
*peer
, afi_t afi
, safi_t safi
, int withdraw
)
3059 struct update_subgroup
*subgrp
;
3060 subgrp
= peer_subgroup(peer
, afi
, safi
);
3061 subgroup_default_originate(subgrp
, withdraw
);
3066 * bgp_stop_announce_route_timer
3069 bgp_stop_announce_route_timer (struct peer_af
*paf
)
3071 if (!paf
->t_announce_route
)
3074 THREAD_TIMER_OFF (paf
->t_announce_route
);
3078 * bgp_announce_route_timer_expired
3080 * Callback that is invoked when the route announcement timer for a
3084 bgp_announce_route_timer_expired (struct thread
*t
)
3086 struct peer_af
*paf
;
3089 paf
= THREAD_ARG (t
);
3092 if (peer
->status
!= Established
)
3095 if (!peer
->afc_nego
[paf
->afi
][paf
->safi
])
3098 peer_af_announce_route (paf
, 1);
3103 * bgp_announce_route
3105 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3108 bgp_announce_route (struct peer
*peer
, afi_t afi
, safi_t safi
)
3110 struct peer_af
*paf
;
3111 struct update_subgroup
*subgrp
;
3113 paf
= peer_af_find (peer
, afi
, safi
);
3116 subgrp
= PAF_SUBGRP(paf
);
3119 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3120 * or a refresh has already been triggered.
3122 if (!subgrp
|| paf
->t_announce_route
)
3126 * Start a timer to stagger/delay the announce. This serves
3127 * two purposes - announcement can potentially be combined for
3128 * multiple peers and the announcement doesn't happen in the
3131 thread_add_timer_msec(bm
->master
, bgp_announce_route_timer_expired
, paf
,
3132 (subgrp
->peer_count
== 1) ? BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS
: BGP_ANNOUNCE_ROUTE_DELAY_MS
,
3133 &paf
->t_announce_route
);
3137 * Announce routes from all AF tables to a peer.
3139 * This should ONLY be called when there is a need to refresh the
3140 * routes to the peer based on a policy change for this peer alone
3141 * or a route refresh request received from the peer.
3142 * The operation will result in splitting the peer from its existing
3143 * subgroups and putting it in new subgroups.
3146 bgp_announce_route_all (struct peer
*peer
)
3151 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3152 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3153 bgp_announce_route (peer
, afi
, safi
);
3157 bgp_soft_reconfig_table (struct peer
*peer
, afi_t afi
, safi_t safi
,
3158 struct bgp_table
*table
, struct prefix_rd
*prd
)
3161 struct bgp_node
*rn
;
3162 struct bgp_adj_in
*ain
;
3165 table
= peer
->bgp
->rib
[afi
][safi
];
3167 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
3168 for (ain
= rn
->adj_in
; ain
; ain
= ain
->next
)
3170 if (ain
->peer
== peer
)
3172 struct bgp_info
*ri
= rn
->info
;
3173 u_char
*tag
= (ri
&& ri
->extra
) ? ri
->extra
->tag
: NULL
;
3175 ret
= bgp_update (peer
, &rn
->p
, ain
->addpath_rx_id
, ain
->attr
,
3176 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3181 bgp_unlock_node (rn
);
3189 bgp_soft_reconfig_in (struct peer
*peer
, afi_t afi
, safi_t safi
)
3191 struct bgp_node
*rn
;
3192 struct bgp_table
*table
;
3194 if (peer
->status
!= Established
)
3197 if ((safi
!= SAFI_MPLS_VPN
) && (safi
!= SAFI_ENCAP
) && (safi
!= SAFI_EVPN
))
3198 bgp_soft_reconfig_table (peer
, afi
, safi
, NULL
, NULL
);
3200 for (rn
= bgp_table_top (peer
->bgp
->rib
[afi
][safi
]); rn
;
3201 rn
= bgp_route_next (rn
))
3202 if ((table
= rn
->info
) != NULL
)
3204 struct prefix_rd prd
;
3205 prd
.family
= AF_UNSPEC
;
3207 memcpy(&prd
.val
, rn
->p
.u
.val
, 8);
3209 bgp_soft_reconfig_table (peer
, afi
, safi
, table
, &prd
);
3214 struct bgp_clear_node_queue
3216 struct bgp_node
*rn
;
3219 static wq_item_status
3220 bgp_clear_route_node (struct work_queue
*wq
, void *data
)
3222 struct bgp_clear_node_queue
*cnq
= data
;
3223 struct bgp_node
*rn
= cnq
->rn
;
3224 struct peer
*peer
= wq
->spec
.data
;
3225 struct bgp_info
*ri
;
3226 afi_t afi
= bgp_node_table (rn
)->afi
;
3227 safi_t safi
= bgp_node_table (rn
)->safi
;
3229 assert (rn
&& peer
);
3231 /* It is possible that we have multiple paths for a prefix from a peer
3232 * if that peer is using AddPath.
3234 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3235 if (ri
->peer
== peer
)
3237 /* graceful restart STALE flag set. */
3238 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
)
3239 && peer
->nsf
[afi
][safi
]
3240 && ! CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
)
3241 && ! CHECK_FLAG (ri
->flags
, BGP_INFO_UNUSEABLE
))
3242 bgp_info_set_flag (rn
, ri
, BGP_INFO_STALE
);
3244 bgp_rib_remove (rn
, ri
, peer
, afi
, safi
);
3250 bgp_clear_node_queue_del (struct work_queue
*wq
, void *data
)
3252 struct bgp_clear_node_queue
*cnq
= data
;
3253 struct bgp_node
*rn
= cnq
->rn
;
3254 struct bgp_table
*table
= bgp_node_table (rn
);
3256 bgp_unlock_node (rn
);
3257 bgp_table_unlock (table
);
3258 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE
, cnq
);
3262 bgp_clear_node_complete (struct work_queue
*wq
)
3264 struct peer
*peer
= wq
->spec
.data
;
3266 /* Tickle FSM to start moving again */
3267 BGP_EVENT_ADD (peer
, Clearing_Completed
);
3269 peer_unlock (peer
); /* bgp_clear_route */
3273 bgp_clear_node_queue_init (struct peer
*peer
)
3275 char wname
[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3277 snprintf (wname
, sizeof(wname
), "clear %s", peer
->host
);
3278 #undef CLEAR_QUEUE_NAME_LEN
3280 if ( (peer
->clear_node_queue
= work_queue_new (bm
->master
, wname
)) == NULL
)
3282 zlog_err ("%s: Failed to allocate work queue", __func__
);
3285 peer
->clear_node_queue
->spec
.hold
= 10;
3286 peer
->clear_node_queue
->spec
.workfunc
= &bgp_clear_route_node
;
3287 peer
->clear_node_queue
->spec
.del_item_data
= &bgp_clear_node_queue_del
;
3288 peer
->clear_node_queue
->spec
.completion_func
= &bgp_clear_node_complete
;
3289 peer
->clear_node_queue
->spec
.max_retries
= 0;
3291 /* we only 'lock' this peer reference when the queue is actually active */
3292 peer
->clear_node_queue
->spec
.data
= peer
;
3296 bgp_clear_route_table (struct peer
*peer
, afi_t afi
, safi_t safi
,
3297 struct bgp_table
*table
)
3299 struct bgp_node
*rn
;
3300 int force
= bm
->process_main_queue
? 0 : 1;
3303 table
= peer
->bgp
->rib
[afi
][safi
];
3305 /* If still no table => afi/safi isn't configured at all or smth. */
3309 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
3311 struct bgp_info
*ri
, *next
;
3312 struct bgp_adj_in
*ain
;
3313 struct bgp_adj_in
*ain_next
;
3315 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3316 * queued for every clearing peer, regardless of whether it is
3317 * relevant to the peer at hand.
3319 * Overview: There are 3 different indices which need to be
3320 * scrubbed, potentially, when a peer is removed:
3322 * 1 peer's routes visible via the RIB (ie accepted routes)
3323 * 2 peer's routes visible by the (optional) peer's adj-in index
3324 * 3 other routes visible by the peer's adj-out index
3326 * 3 there is no hurry in scrubbing, once the struct peer is
3327 * removed from bgp->peer, we could just GC such deleted peer's
3328 * adj-outs at our leisure.
3330 * 1 and 2 must be 'scrubbed' in some way, at least made
3331 * invisible via RIB index before peer session is allowed to be
3332 * brought back up. So one needs to know when such a 'search' is
3337 * - there'd be a single global queue or a single RIB walker
3338 * - rather than tracking which route_nodes still need to be
3339 * examined on a peer basis, we'd track which peers still
3342 * Given that our per-peer prefix-counts now should be reliable,
3343 * this may actually be achievable. It doesn't seem to be a huge
3344 * problem at this time,
3346 * It is possible that we have multiple paths for a prefix from a peer
3347 * if that peer is using AddPath.
3352 ain_next
= ain
->next
;
3354 if (ain
->peer
== peer
)
3356 bgp_adj_in_remove (rn
, ain
);
3357 bgp_unlock_node (rn
);
3363 for (ri
= rn
->info
; ri
; ri
= next
)
3366 if (ri
->peer
!= peer
)
3370 bgp_info_reap (rn
, ri
);
3373 struct bgp_clear_node_queue
*cnq
;
3375 /* both unlocked in bgp_clear_node_queue_del */
3376 bgp_table_lock (bgp_node_table (rn
));
3378 cnq
= XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE
,
3379 sizeof (struct bgp_clear_node_queue
));
3381 work_queue_add (peer
->clear_node_queue
, cnq
);
3390 bgp_clear_route (struct peer
*peer
, afi_t afi
, safi_t safi
)
3392 struct bgp_node
*rn
;
3393 struct bgp_table
*table
;
3395 if (peer
->clear_node_queue
== NULL
)
3396 bgp_clear_node_queue_init (peer
);
3398 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3399 * Idle until it receives a Clearing_Completed event. This protects
3400 * against peers which flap faster than we can we clear, which could
3403 * a) race with routes from the new session being installed before
3404 * clear_route_node visits the node (to delete the route of that
3406 * b) resource exhaustion, clear_route_node likely leads to an entry
3407 * on the process_main queue. Fast-flapping could cause that queue
3411 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3412 * the unlock will happen upon work-queue completion; other wise, the
3413 * unlock happens at the end of this function.
3415 if (!peer
->clear_node_queue
->thread
)
3418 if (safi
!= SAFI_MPLS_VPN
&& safi
!= SAFI_ENCAP
&& safi
!= SAFI_EVPN
)
3419 bgp_clear_route_table (peer
, afi
, safi
, NULL
);
3421 for (rn
= bgp_table_top (peer
->bgp
->rib
[afi
][safi
]); rn
;
3422 rn
= bgp_route_next (rn
))
3423 if ((table
= rn
->info
) != NULL
)
3424 bgp_clear_route_table (peer
, afi
, safi
, table
);
3426 /* unlock if no nodes got added to the clear-node-queue. */
3427 if (!peer
->clear_node_queue
->thread
)
3433 bgp_clear_route_all (struct peer
*peer
)
3438 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3439 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3440 bgp_clear_route (peer
, afi
, safi
);
3443 rfapiProcessPeerDown(peer
);
3448 bgp_clear_adj_in (struct peer
*peer
, afi_t afi
, safi_t safi
)
3450 struct bgp_table
*table
;
3451 struct bgp_node
*rn
;
3452 struct bgp_adj_in
*ain
;
3453 struct bgp_adj_in
*ain_next
;
3455 table
= peer
->bgp
->rib
[afi
][safi
];
3457 /* It is possible that we have multiple paths for a prefix from a peer
3458 * if that peer is using AddPath.
3460 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
3466 ain_next
= ain
->next
;
3468 if (ain
->peer
== peer
)
3470 bgp_adj_in_remove (rn
, ain
);
3471 bgp_unlock_node (rn
);
3480 bgp_clear_stale_route (struct peer
*peer
, afi_t afi
, safi_t safi
)
3482 struct bgp_node
*rn
;
3483 struct bgp_info
*ri
;
3484 struct bgp_table
*table
;
3486 if ( safi
== SAFI_MPLS_VPN
)
3488 for (rn
= bgp_table_top (peer
->bgp
->rib
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
3490 struct bgp_node
*rm
;
3491 struct bgp_info
*ri
;
3493 /* look for neighbor in tables */
3494 if ((table
= rn
->info
) != NULL
)
3496 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
3497 for (ri
= rm
->info
; ri
; ri
= ri
->next
)
3498 if (ri
->peer
== peer
)
3500 if (CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
))
3501 bgp_rib_remove (rm
, ri
, peer
, afi
, safi
);
3509 for (rn
= bgp_table_top (peer
->bgp
->rib
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
3510 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3511 if (ri
->peer
== peer
)
3513 if (CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
))
3514 bgp_rib_remove (rn
, ri
, peer
, afi
, safi
);
3521 bgp_cleanup_table(struct bgp_table
*table
, safi_t safi
)
3523 struct bgp_node
*rn
;
3524 struct bgp_info
*ri
;
3525 struct bgp_info
*next
;
3527 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
3528 for (ri
= rn
->info
; ri
; ri
= next
)
3531 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)
3532 && ri
->type
== ZEBRA_ROUTE_BGP
3533 && (ri
->sub_type
== BGP_ROUTE_NORMAL
||
3534 ri
->sub_type
== BGP_ROUTE_AGGREGATE
))
3537 if (table
->owner
&& table
->owner
->bgp
)
3538 vnc_import_bgp_del_route(table
->owner
->bgp
, &rn
->p
, ri
);
3540 bgp_zebra_withdraw (&rn
->p
, ri
, safi
);
3541 bgp_info_reap (rn
, ri
);
3546 /* Delete all kernel routes. */
3548 bgp_cleanup_routes (struct bgp
*bgp
)
3551 struct bgp_node
*rn
;
3553 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
3555 if (afi
== AFI_L2VPN
)
3557 bgp_cleanup_table(bgp
->rib
[afi
][SAFI_UNICAST
], SAFI_UNICAST
);
3559 * VPN and ENCAP and EVPN tables are two-level (RD is top level)
3561 if (afi
!= AFI_L2VPN
)
3564 safi
= SAFI_MPLS_VPN
;
3565 for (rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rn
;
3566 rn
= bgp_route_next (rn
))
3570 bgp_cleanup_table((struct bgp_table
*)(rn
->info
), safi
);
3571 bgp_table_finish ((struct bgp_table
**)&(rn
->info
));
3573 bgp_unlock_node(rn
);
3577 for (rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rn
;
3578 rn
= bgp_route_next (rn
))
3582 bgp_cleanup_table((struct bgp_table
*)(rn
->info
), safi
);
3583 bgp_table_finish ((struct bgp_table
**)&(rn
->info
));
3585 bgp_unlock_node(rn
);
3590 for (rn
= bgp_table_top(bgp
->rib
[AFI_L2VPN
][SAFI_EVPN
]); rn
;
3591 rn
= bgp_route_next (rn
))
3595 bgp_cleanup_table((struct bgp_table
*)(rn
->info
), SAFI_EVPN
);
3596 bgp_table_finish ((struct bgp_table
**)&(rn
->info
));
3598 bgp_unlock_node(rn
);
3607 bgp_zclient_reset ();
3608 access_list_reset ();
3609 prefix_list_reset ();
3613 bgp_addpath_encode_rx (struct peer
*peer
, afi_t afi
, safi_t safi
)
3615 return (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_RX_ADV
) &&
3616 CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_TX_RCV
));
3619 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3622 bgp_nlri_parse_ip (struct peer
*peer
, struct attr
*attr
,
3623 struct bgp_nlri
*packet
)
3632 int addpath_encoded
;
3633 u_int32_t addpath_id
;
3635 /* Check peer status. */
3636 if (peer
->status
!= Established
)
3640 lim
= pnt
+ packet
->length
;
3642 safi
= packet
->safi
;
3644 addpath_encoded
= bgp_addpath_encode_rx (peer
, afi
, safi
);
3646 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3647 syntactic validity. If the field is syntactically incorrect,
3648 then the Error Subcode is set to Invalid Network Field. */
3649 for (; pnt
< lim
; pnt
+= psize
)
3651 /* Clear prefix structure. */
3652 memset (&p
, 0, sizeof (struct prefix
));
3654 if (addpath_encoded
)
3657 /* When packet overflow occurs return immediately. */
3658 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
3661 addpath_id
= ntohl(*((uint32_t*) pnt
));
3662 pnt
+= BGP_ADDPATH_ID_LEN
;
3665 /* Fetch prefix length. */
3666 p
.prefixlen
= *pnt
++;
3667 /* afi/safi validity already verified by caller, bgp_update_receive */
3668 p
.family
= afi2family (afi
);
3670 /* Prefix length check. */
3671 if (p
.prefixlen
> prefix_blen (&p
) * 8)
3673 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3674 peer
->host
, p
.prefixlen
, packet
->afi
);
3678 /* Packet size overflow check. */
3679 psize
= PSIZE (p
.prefixlen
);
3681 /* When packet overflow occur return immediately. */
3682 if (pnt
+ psize
> lim
)
3684 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3685 peer
->host
, p
.prefixlen
);
3689 /* Defensive coding, double-check the psize fits in a struct prefix */
3690 if (psize
> (ssize_t
) sizeof(p
.u
))
3692 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3693 peer
->host
, p
.prefixlen
, sizeof(p
.u
));
3697 /* Fetch prefix from NLRI packet. */
3698 memcpy (&p
.u
.prefix
, pnt
, psize
);
3700 /* Check address. */
3701 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
3703 if (IN_CLASSD (ntohl (p
.u
.prefix4
.s_addr
)))
3705 /* From RFC4271 Section 6.3:
3707 * If a prefix in the NLRI field is semantically incorrect
3708 * (e.g., an unexpected multicast IP address), an error SHOULD
3709 * be logged locally, and the prefix SHOULD be ignored.
3711 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3712 peer
->host
, inet_ntoa (p
.u
.prefix4
));
3717 /* Check address. */
3718 if (afi
== AFI_IP6
&& safi
== SAFI_UNICAST
)
3720 if (IN6_IS_ADDR_LINKLOCAL (&p
.u
.prefix6
))
3724 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3725 peer
->host
, inet_ntop (AF_INET6
, &p
.u
.prefix6
, buf
, BUFSIZ
));
3729 if (IN6_IS_ADDR_MULTICAST (&p
.u
.prefix6
))
3733 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3734 peer
->host
, inet_ntop (AF_INET6
, &p
.u
.prefix6
, buf
, BUFSIZ
));
3740 /* Normal process. */
3742 ret
= bgp_update (peer
, &p
, addpath_id
, attr
, afi
, safi
,
3743 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, NULL
, NULL
, 0, NULL
);
3745 ret
= bgp_withdraw (peer
, &p
, addpath_id
, attr
, afi
, safi
,
3746 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, NULL
, NULL
, NULL
);
3748 /* Address family configuration mismatch or maximum-prefix count
3754 /* Packet length consistency check. */
3757 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3765 static struct bgp_static
*
3766 bgp_static_new (void)
3768 return XCALLOC (MTYPE_BGP_STATIC
, sizeof (struct bgp_static
));
3772 bgp_static_free (struct bgp_static
*bgp_static
)
3774 if (bgp_static
->rmap
.name
)
3775 XFREE(MTYPE_ROUTE_MAP_NAME
, bgp_static
->rmap
.name
);
3776 if(bgp_static
->eth_s_id
)
3777 XFREE(MTYPE_ATTR
, bgp_static
->eth_s_id
);
3778 XFREE (MTYPE_BGP_STATIC
, bgp_static
);
3782 bgp_static_update (struct bgp
*bgp
, struct prefix
*p
,
3783 struct bgp_static
*bgp_static
, afi_t afi
, safi_t safi
)
3785 struct bgp_node
*rn
;
3786 struct bgp_info
*ri
;
3787 struct bgp_info
*new;
3788 struct bgp_info info
;
3790 struct attr
*attr_new
;
3793 int vnc_implicit_withdraw
= 0;
3796 assert (bgp_static
);
3800 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, NULL
);
3802 bgp_attr_default_set (&attr
, BGP_ORIGIN_IGP
);
3804 attr
.nexthop
= bgp_static
->igpnexthop
;
3805 attr
.med
= bgp_static
->igpmetric
;
3806 attr
.flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
3808 if (bgp_static
->atomic
)
3809 attr
.flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
3811 /* Store label index, if required. */
3812 if (bgp_static
->label_index
!= BGP_INVALID_LABEL_INDEX
)
3814 (bgp_attr_extra_get (&attr
))->label_index
= bgp_static
->label_index
;
3815 attr
.flag
|= ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
);
3818 /* Apply route-map. */
3819 if (bgp_static
->rmap
.name
)
3821 struct attr attr_tmp
= attr
;
3822 info
.peer
= bgp
->peer_self
;
3823 info
.attr
= &attr_tmp
;
3825 SET_FLAG (bgp
->peer_self
->rmap_type
, PEER_RMAP_TYPE_NETWORK
);
3827 ret
= route_map_apply (bgp_static
->rmap
.map
, p
, RMAP_BGP
, &info
);
3829 bgp
->peer_self
->rmap_type
= 0;
3831 if (ret
== RMAP_DENYMATCH
)
3833 /* Free uninterned attribute. */
3834 bgp_attr_flush (&attr_tmp
);
3836 /* Unintern original. */
3837 aspath_unintern (&attr
.aspath
);
3838 bgp_attr_extra_free (&attr
);
3839 bgp_static_withdraw (bgp
, p
, afi
, safi
);
3842 attr_new
= bgp_attr_intern (&attr_tmp
);
3845 attr_new
= bgp_attr_intern (&attr
);
3847 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3848 if (ri
->peer
== bgp
->peer_self
&& ri
->type
== ZEBRA_ROUTE_BGP
3849 && ri
->sub_type
== BGP_ROUTE_STATIC
)
3854 if (attrhash_cmp (ri
->attr
, attr_new
) &&
3855 !CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
) &&
3856 !bgp_flag_check(bgp
, BGP_FLAG_FORCE_STATIC_PROCESS
))
3858 bgp_unlock_node (rn
);
3859 bgp_attr_unintern (&attr_new
);
3860 aspath_unintern (&attr
.aspath
);
3861 bgp_attr_extra_free (&attr
);
3866 /* The attribute is changed. */
3867 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
3869 /* Rewrite BGP route information. */
3870 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
3871 bgp_info_restore(rn
, ri
);
3873 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, safi
);
3875 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
))
3877 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))
3880 * Implicit withdraw case.
3881 * We have to do this before ri is changed
3883 ++vnc_implicit_withdraw
;
3884 vnc_import_bgp_del_route(bgp
, p
, ri
);
3885 vnc_import_bgp_exterior_del_route(bgp
, p
, ri
);
3889 bgp_attr_unintern (&ri
->attr
);
3890 ri
->attr
= attr_new
;
3891 ri
->uptime
= bgp_clock ();
3893 if ((afi
== AFI_IP
|| afi
== AFI_IP6
) && (safi
== SAFI_UNICAST
))
3895 if (vnc_implicit_withdraw
)
3897 vnc_import_bgp_add_route(bgp
, p
, ri
);
3898 vnc_import_bgp_exterior_add_route(bgp
, p
, ri
);
3903 /* Nexthop reachability check. */
3904 if (bgp_flag_check (bgp
, BGP_FLAG_IMPORT_CHECK
) &&
3905 safi
== SAFI_UNICAST
)
3907 if (bgp_find_or_add_nexthop (bgp
, afi
, ri
, NULL
, 0) &&
3908 safi
== SAFI_UNICAST
)
3909 bgp_info_set_flag (rn
, ri
, BGP_INFO_VALID
);
3912 if (BGP_DEBUG(nht
, NHT
))
3914 char buf1
[INET6_ADDRSTRLEN
];
3915 inet_ntop(p
->family
, &p
->u
.prefix
, buf1
,
3917 zlog_debug("%s(%s): Route not in table, not advertising",
3918 __FUNCTION__
, buf1
);
3920 bgp_info_unset_flag (rn
, ri
, BGP_INFO_VALID
);
3925 /* Delete the NHT structure if any, if we're toggling between
3926 * enabling/disabling import check. We deregister the route
3927 * from NHT to avoid overloading NHT and the process interaction
3929 bgp_unlink_nexthop(ri
);
3930 bgp_info_set_flag (rn
, ri
, BGP_INFO_VALID
);
3932 /* Process change. */
3933 bgp_aggregate_increment (bgp
, p
, ri
, afi
, safi
);
3934 bgp_process (bgp
, rn
, afi
, safi
);
3935 bgp_unlock_node (rn
);
3936 aspath_unintern (&attr
.aspath
);
3937 bgp_attr_extra_free (&attr
);
3942 /* Make new BGP info. */
3943 new = info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0, bgp
->peer_self
, attr_new
,
3945 /* Nexthop reachability check. */
3946 if (bgp_flag_check (bgp
, BGP_FLAG_IMPORT_CHECK
))
3948 if (bgp_find_or_add_nexthop (bgp
, afi
, new, NULL
, 0))
3949 bgp_info_set_flag (rn
, new, BGP_INFO_VALID
);
3952 if (BGP_DEBUG(nht
, NHT
))
3954 char buf1
[INET6_ADDRSTRLEN
];
3955 inet_ntop(p
->family
, &p
->u
.prefix
, buf1
,
3957 zlog_debug("%s(%s): Route not in table, not advertising",
3958 __FUNCTION__
, buf1
);
3960 bgp_info_unset_flag (rn
, new, BGP_INFO_VALID
);
3965 /* Delete the NHT structure if any, if we're toggling between
3966 * enabling/disabling import check. We deregister the route
3967 * from NHT to avoid overloading NHT and the process interaction
3969 bgp_unlink_nexthop(new);
3971 bgp_info_set_flag (rn
, new, BGP_INFO_VALID
);
3974 /* Aggregate address increment. */
3975 bgp_aggregate_increment (bgp
, p
, new, afi
, safi
);
3977 /* Register new BGP information. */
3978 bgp_info_add (rn
, new);
3980 /* route_node_get lock */
3981 bgp_unlock_node (rn
);
3983 /* Process change. */
3984 bgp_process (bgp
, rn
, afi
, safi
);
3986 /* Unintern original. */
3987 aspath_unintern (&attr
.aspath
);
3988 bgp_attr_extra_free (&attr
);
3992 bgp_static_withdraw (struct bgp
*bgp
, struct prefix
*p
, afi_t afi
,
3995 struct bgp_node
*rn
;
3996 struct bgp_info
*ri
;
3998 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, NULL
);
4000 /* Check selected route and self inserted route. */
4001 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
4002 if (ri
->peer
== bgp
->peer_self
4003 && ri
->type
== ZEBRA_ROUTE_BGP
4004 && ri
->sub_type
== BGP_ROUTE_STATIC
)
4007 /* Withdraw static BGP route from routing table. */
4010 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, safi
);
4011 bgp_unlink_nexthop(ri
);
4012 bgp_info_delete (rn
, ri
);
4013 bgp_process (bgp
, rn
, afi
, safi
);
4016 /* Unlock bgp_node_lookup. */
4017 bgp_unlock_node (rn
);
4021 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
4024 bgp_static_withdraw_safi (struct bgp
*bgp
, struct prefix
*p
, afi_t afi
,
4025 safi_t safi
, struct prefix_rd
*prd
, u_char
*tag
)
4027 struct bgp_node
*rn
;
4028 struct bgp_info
*ri
;
4030 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
4032 /* Check selected route and self inserted route. */
4033 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
4034 if (ri
->peer
== bgp
->peer_self
4035 && ri
->type
== ZEBRA_ROUTE_BGP
4036 && ri
->sub_type
== BGP_ROUTE_STATIC
)
4039 /* Withdraw static BGP route from routing table. */
4043 rfapiProcessWithdraw(
4052 1); /* Kill, since it is an administrative change */
4054 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, safi
);
4055 bgp_info_delete (rn
, ri
);
4056 bgp_process (bgp
, rn
, afi
, safi
);
4059 /* Unlock bgp_node_lookup. */
4060 bgp_unlock_node (rn
);
4064 bgp_static_update_safi (struct bgp
*bgp
, struct prefix
*p
,
4065 struct bgp_static
*bgp_static
, afi_t afi
, safi_t safi
)
4067 struct bgp_node
*rn
;
4068 struct bgp_info
*new;
4069 struct attr
*attr_new
;
4070 struct attr attr
= { 0 };
4071 struct bgp_info
*ri
;
4073 u_int32_t label
= 0;
4077 assert (bgp_static
);
4079 rn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, &bgp_static
->prd
);
4081 bgp_attr_default_set (&attr
, BGP_ORIGIN_IGP
);
4083 attr
.nexthop
= bgp_static
->igpnexthop
;
4084 attr
.med
= bgp_static
->igpmetric
;
4085 attr
.flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
4087 if ((safi
== SAFI_EVPN
) || (safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
))
4089 if (bgp_static
->igpnexthop
.s_addr
)
4091 bgp_attr_extra_get (&attr
)->mp_nexthop_global_in
= bgp_static
->igpnexthop
;
4092 bgp_attr_extra_get (&attr
)->mp_nexthop_len
= IPV4_MAX_BYTELEN
;
4095 if(afi
== AFI_L2VPN
)
4097 if (bgp_static
->gatewayIp
.family
== AF_INET
)
4098 add
.ipv4
.s_addr
= bgp_static
->gatewayIp
.u
.prefix4
.s_addr
;
4099 else if (bgp_static
->gatewayIp
.family
== AF_INET6
)
4100 memcpy( &(add
.ipv6
), &(bgp_static
->gatewayIp
.u
.prefix6
), sizeof (struct in6_addr
));
4101 overlay_index_update(&attr
, bgp_static
->eth_s_id
, &add
);
4102 if (bgp_static
->encap_tunneltype
== BGP_ENCAP_TYPE_VXLAN
)
4104 struct bgp_encap_type_vxlan bet
;
4105 memset(&bet
, 0, sizeof(struct bgp_encap_type_vxlan
));
4106 bet
.vnid
= p
->u
.prefix_evpn
.eth_tag
;
4107 bgp_encap_type_vxlan_to_tlv(&bet
, &attr
);
4109 if (bgp_static
->router_mac
)
4111 bgp_add_routermac_ecom (&attr
, bgp_static
->router_mac
);
4114 /* Apply route-map. */
4115 if (bgp_static
->rmap
.name
)
4117 struct attr attr_tmp
= attr
;
4118 struct bgp_info info
;
4121 info
.peer
= bgp
->peer_self
;
4122 info
.attr
= &attr_tmp
;
4124 SET_FLAG (bgp
->peer_self
->rmap_type
, PEER_RMAP_TYPE_NETWORK
);
4126 ret
= route_map_apply (bgp_static
->rmap
.map
, p
, RMAP_BGP
, &info
);
4128 bgp
->peer_self
->rmap_type
= 0;
4130 if (ret
== RMAP_DENYMATCH
)
4132 /* Free uninterned attribute. */
4133 bgp_attr_flush (&attr_tmp
);
4135 /* Unintern original. */
4136 aspath_unintern (&attr
.aspath
);
4137 bgp_attr_extra_free (&attr
);
4138 bgp_static_withdraw_safi (bgp
, p
, afi
, safi
, &bgp_static
->prd
,
4143 attr_new
= bgp_attr_intern (&attr_tmp
);
4147 attr_new
= bgp_attr_intern (&attr
);
4150 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
4151 if (ri
->peer
== bgp
->peer_self
&& ri
->type
== ZEBRA_ROUTE_BGP
4152 && ri
->sub_type
== BGP_ROUTE_STATIC
)
4158 memset(&add
, 0, sizeof(union gw_addr
));
4159 if (attrhash_cmp (ri
->attr
, attr_new
) &&
4160 overlay_index_equal(afi
, ri
, bgp_static
->eth_s_id
, &add
) &&
4161 !CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
4163 bgp_unlock_node (rn
);
4164 bgp_attr_unintern (&attr_new
);
4165 aspath_unintern (&attr
.aspath
);
4166 bgp_attr_extra_free (&attr
);
4171 /* The attribute is changed. */
4172 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
4174 /* Rewrite BGP route information. */
4175 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
4176 bgp_info_restore(rn
, ri
);
4178 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, safi
);
4179 bgp_attr_unintern (&ri
->attr
);
4180 ri
->attr
= attr_new
;
4181 ri
->uptime
= bgp_clock ();
4184 label
= decode_label (ri
->extra
->tag
);
4187 /* Process change. */
4188 bgp_aggregate_increment (bgp
, p
, ri
, afi
, safi
);
4189 bgp_process (bgp
, rn
, afi
, safi
);
4191 rfapiProcessUpdate(ri
->peer
, NULL
, p
, &bgp_static
->prd
,
4192 ri
->attr
, afi
, safi
,
4193 ri
->type
, ri
->sub_type
, &label
);
4195 bgp_unlock_node (rn
);
4196 aspath_unintern (&attr
.aspath
);
4197 bgp_attr_extra_free (&attr
);
4203 /* Make new BGP info. */
4204 new = info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0, bgp
->peer_self
, attr_new
,
4206 SET_FLAG (new->flags
, BGP_INFO_VALID
);
4207 new->extra
= bgp_info_extra_new();
4208 memcpy (new->extra
->tag
, bgp_static
->tag
, 3);
4210 label
= decode_label (bgp_static
->tag
);
4213 /* Aggregate address increment. */
4214 bgp_aggregate_increment (bgp
, p
, new, afi
, safi
);
4216 /* Register new BGP information. */
4217 bgp_info_add (rn
, new);
4218 /* route_node_get lock */
4219 bgp_unlock_node (rn
);
4221 /* Process change. */
4222 bgp_process (bgp
, rn
, afi
, safi
);
4225 rfapiProcessUpdate(new->peer
, NULL
, p
, &bgp_static
->prd
,
4226 new->attr
, afi
, safi
,
4227 new->type
, new->sub_type
, &label
);
4230 /* Unintern original. */
4231 aspath_unintern (&attr
.aspath
);
4232 bgp_attr_extra_free (&attr
);
4235 /* Configure static BGP network. When user don't run zebra, static
4236 route should be installed as valid. */
4238 bgp_static_set (struct vty
*vty
, const char *ip_str
,
4239 afi_t afi
, safi_t safi
, const char *rmap
, int backdoor
,
4240 u_int32_t label_index
)
4242 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4245 struct bgp_static
*bgp_static
;
4246 struct bgp_node
*rn
;
4247 u_char need_update
= 0;
4249 /* Convert IP prefix string to struct prefix. */
4250 ret
= str2prefix (ip_str
, &p
);
4253 vty_out (vty
, "%% Malformed prefix%s", VTY_NEWLINE
);
4256 if (afi
== AFI_IP6
&& IN6_IS_ADDR_LINKLOCAL (&p
.u
.prefix6
))
4258 vty_out (vty
, "%% Malformed prefix (link-local address)%s",
4265 /* Set BGP static route configuration. */
4266 rn
= bgp_node_get (bgp
->route
[afi
][safi
], &p
);
4270 /* Configuration change. */
4271 bgp_static
= rn
->info
;
4273 /* Label index cannot be changed. */
4274 if (bgp_static
->label_index
!= label_index
)
4276 vty_out (vty
, "%% Label index cannot be changed%s", VTY_NEWLINE
);
4280 /* Check previous routes are installed into BGP. */
4281 if (bgp_static
->valid
&& bgp_static
->backdoor
!= backdoor
)
4284 bgp_static
->backdoor
= backdoor
;
4288 if (bgp_static
->rmap
.name
)
4289 XFREE(MTYPE_ROUTE_MAP_NAME
, bgp_static
->rmap
.name
);
4290 bgp_static
->rmap
.name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, rmap
);
4291 bgp_static
->rmap
.map
= route_map_lookup_by_name (rmap
);
4295 if (bgp_static
->rmap
.name
)
4296 XFREE(MTYPE_ROUTE_MAP_NAME
, bgp_static
->rmap
.name
);
4297 bgp_static
->rmap
.name
= NULL
;
4298 bgp_static
->rmap
.map
= NULL
;
4299 bgp_static
->valid
= 0;
4301 bgp_unlock_node (rn
);
4305 /* New configuration. */
4306 bgp_static
= bgp_static_new ();
4307 bgp_static
->backdoor
= backdoor
;
4308 bgp_static
->valid
= 0;
4309 bgp_static
->igpmetric
= 0;
4310 bgp_static
->igpnexthop
.s_addr
= 0;
4311 bgp_static
->label_index
= label_index
;
4315 if (bgp_static
->rmap
.name
)
4316 XFREE(MTYPE_ROUTE_MAP_NAME
, bgp_static
->rmap
.name
);
4317 bgp_static
->rmap
.name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, rmap
);
4318 bgp_static
->rmap
.map
= route_map_lookup_by_name (rmap
);
4320 rn
->info
= bgp_static
;
4323 bgp_static
->valid
= 1;
4325 bgp_static_withdraw (bgp
, &p
, afi
, safi
);
4327 if (! bgp_static
->backdoor
)
4328 bgp_static_update (bgp
, &p
, bgp_static
, afi
, safi
);
4333 /* Configure static BGP network. */
4335 bgp_static_unset (struct vty
*vty
, const char *ip_str
,
4336 afi_t afi
, safi_t safi
)
4338 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4341 struct bgp_static
*bgp_static
;
4342 struct bgp_node
*rn
;
4344 /* Convert IP prefix string to struct prefix. */
4345 ret
= str2prefix (ip_str
, &p
);
4348 vty_out (vty
, "%% Malformed prefix%s", VTY_NEWLINE
);
4351 if (afi
== AFI_IP6
&& IN6_IS_ADDR_LINKLOCAL (&p
.u
.prefix6
))
4353 vty_out (vty
, "%% Malformed prefix (link-local address)%s",
4360 rn
= bgp_node_lookup (bgp
->route
[afi
][safi
], &p
);
4363 vty_out (vty
, "%% Can't find specified static route configuration.%s",
4368 bgp_static
= rn
->info
;
4370 /* Update BGP RIB. */
4371 if (! bgp_static
->backdoor
)
4372 bgp_static_withdraw (bgp
, &p
, afi
, safi
);
4374 /* Clear configuration. */
4375 bgp_static_free (bgp_static
);
4377 bgp_unlock_node (rn
);
4378 bgp_unlock_node (rn
);
4384 bgp_static_add (struct bgp
*bgp
)
4388 struct bgp_node
*rn
;
4389 struct bgp_node
*rm
;
4390 struct bgp_table
*table
;
4391 struct bgp_static
*bgp_static
;
4393 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4394 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4395 for (rn
= bgp_table_top (bgp
->route
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
4396 if (rn
->info
!= NULL
)
4398 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) || (safi
== SAFI_EVPN
))
4402 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
4404 bgp_static
= rn
->info
;
4405 bgp_static_update_safi (bgp
, &rm
->p
, bgp_static
, afi
, safi
);
4410 bgp_static_update (bgp
, &rn
->p
, rn
->info
, afi
, safi
);
4415 /* Called from bgp_delete(). Delete all static routes from the BGP
4418 bgp_static_delete (struct bgp
*bgp
)
4422 struct bgp_node
*rn
;
4423 struct bgp_node
*rm
;
4424 struct bgp_table
*table
;
4425 struct bgp_static
*bgp_static
;
4427 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4428 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4429 for (rn
= bgp_table_top (bgp
->route
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
4430 if (rn
->info
!= NULL
)
4432 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) || (safi
== SAFI_EVPN
))
4436 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
4438 bgp_static
= rn
->info
;
4439 bgp_static_withdraw_safi (bgp
, &rm
->p
,
4441 (struct prefix_rd
*)&rn
->p
,
4443 bgp_static_free (bgp_static
);
4445 bgp_unlock_node (rn
);
4450 bgp_static
= rn
->info
;
4451 bgp_static_withdraw (bgp
, &rn
->p
, afi
, safi
);
4452 bgp_static_free (bgp_static
);
4454 bgp_unlock_node (rn
);
4460 bgp_static_redo_import_check (struct bgp
*bgp
)
4464 struct bgp_node
*rn
;
4465 struct bgp_static
*bgp_static
;
4467 /* Use this flag to force reprocessing of the route */
4468 bgp_flag_set(bgp
, BGP_FLAG_FORCE_STATIC_PROCESS
);
4469 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4470 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4471 for (rn
= bgp_table_top (bgp
->route
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
4472 if (rn
->info
!= NULL
)
4474 bgp_static
= rn
->info
;
4475 bgp_static_update (bgp
, &rn
->p
, bgp_static
, afi
, safi
);
4477 bgp_flag_unset(bgp
, BGP_FLAG_FORCE_STATIC_PROCESS
);
4481 bgp_purge_af_static_redist_routes (struct bgp
*bgp
, afi_t afi
, safi_t safi
)
4483 struct bgp_table
*table
;
4484 struct bgp_node
*rn
;
4485 struct bgp_info
*ri
;
4487 table
= bgp
->rib
[afi
][safi
];
4488 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
4490 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
4492 if (ri
->peer
== bgp
->peer_self
&&
4493 ((ri
->type
== ZEBRA_ROUTE_BGP
&&
4494 ri
->sub_type
== BGP_ROUTE_STATIC
) ||
4495 (ri
->type
!= ZEBRA_ROUTE_BGP
&&
4496 ri
->sub_type
== BGP_ROUTE_REDISTRIBUTE
)))
4498 bgp_aggregate_decrement (bgp
, &rn
->p
, ri
, afi
, safi
);
4499 bgp_unlink_nexthop(ri
);
4500 bgp_info_delete (rn
, ri
);
4501 bgp_process (bgp
, rn
, afi
, safi
);
4508 * Purge all networks and redistributed routes from routing table.
4509 * Invoked upon the instance going down.
4512 bgp_purge_static_redist_routes (struct bgp
*bgp
)
4517 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4518 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4519 bgp_purge_af_static_redist_routes (bgp
, afi
, safi
);
4524 * Currently this is used to set static routes for VPN and ENCAP.
4525 * I think it can probably be factored with bgp_static_set.
4528 bgp_static_set_safi (safi_t safi
, struct vty
*vty
, const char *ip_str
,
4529 const char *rd_str
, const char *tag_str
,
4530 const char *rmap_str
, int evpn_type
, const char *esi
, const char *gwip
,
4531 const char *ethtag
, const char *routermac
)
4533 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4536 struct prefix_rd prd
;
4537 struct bgp_node
*prn
;
4538 struct bgp_node
*rn
;
4539 struct bgp_table
*table
;
4540 struct bgp_static
*bgp_static
;
4543 struct prefix gw_ip
;
4545 if(safi
== SAFI_EVPN
)
4550 /* validate ip prefix */
4551 ret
= str2prefix (ip_str
, &p
);
4554 vty_out (vty
, "%% Malformed prefix%s", VTY_NEWLINE
);
4558 if ( (afi
== AFI_L2VPN
) &&
4559 (bgp_build_evpn_prefix ( evpn_type
, ethtag
!=NULL
?atol(ethtag
):0, &p
)))
4561 vty_out (vty
, "%% L2VPN prefix could not be forged%s", VTY_NEWLINE
);
4565 ret
= str2prefix_rd (rd_str
, &prd
);
4568 vty_out (vty
, "%% Malformed rd%s", VTY_NEWLINE
);
4574 ret
= str2tag (tag_str
, tag
);
4577 vty_out (vty
, "%% Malformed tag%s", VTY_NEWLINE
);
4583 encode_label (0, tag
);
4585 if (safi
== SAFI_EVPN
)
4587 if( esi
&& str2esi (esi
, NULL
) == 0)
4589 vty_out (vty
, "%% Malformed ESI%s", VTY_NEWLINE
);
4592 if( routermac
&& prefix_str2mac (routermac
, NULL
) == 0)
4594 vty_out (vty
, "%% Malformed Router MAC%s", VTY_NEWLINE
);
4599 memset (&gw_ip
, 0, sizeof (struct prefix
));
4600 ret
= str2prefix (gwip
, &gw_ip
);
4603 vty_out (vty
, "%% Malformed GatewayIp%s", VTY_NEWLINE
);
4606 if((gw_ip
.family
== AF_INET
&& (p
.u
.prefix_evpn
.flags
& IP_PREFIX_V6
))
4607 || (gw_ip
.family
== AF_INET6
&& (p
.u
.prefix_evpn
.flags
& IP_PREFIX_V4
)))
4609 vty_out (vty
, "%% GatewayIp family differs with IP prefix%s", VTY_NEWLINE
);
4614 prn
= bgp_node_get (bgp
->route
[afi
][safi
],
4615 (struct prefix
*)&prd
);
4616 if (prn
->info
== NULL
)
4617 prn
->info
= bgp_table_init (afi
, safi
);
4619 bgp_unlock_node (prn
);
4622 rn
= bgp_node_get (table
, &p
);
4626 vty_out (vty
, "%% Same network configuration exists%s", VTY_NEWLINE
);
4627 bgp_unlock_node (rn
);
4631 /* New configuration. */
4632 bgp_static
= bgp_static_new ();
4633 bgp_static
->backdoor
= 0;
4634 bgp_static
->valid
= 0;
4635 bgp_static
->igpmetric
= 0;
4636 bgp_static
->igpnexthop
.s_addr
= 0;
4637 memcpy(bgp_static
->tag
, tag
, 3);
4638 bgp_static
->prd
= prd
;
4642 if (bgp_static
->rmap
.name
)
4643 free (bgp_static
->rmap
.name
);
4644 bgp_static
->rmap
.name
= strdup (rmap_str
);
4645 bgp_static
->rmap
.map
= route_map_lookup_by_name (rmap_str
);
4648 if (safi
== SAFI_EVPN
)
4652 bgp_static
->eth_s_id
= XCALLOC (MTYPE_ATTR
, sizeof(struct eth_segment_id
));
4653 str2esi (esi
, bgp_static
->eth_s_id
);
4657 bgp_static
->router_mac
= XCALLOC (MTYPE_ATTR
, ETHER_ADDR_LEN
+1);
4658 prefix_str2mac (routermac
, bgp_static
->router_mac
);
4661 prefix_copy (&bgp_static
->gatewayIp
, &gw_ip
);
4663 rn
->info
= bgp_static
;
4665 bgp_static
->valid
= 1;
4666 bgp_static_update_safi (bgp
, &p
, bgp_static
, afi
, safi
);
4672 /* Configure static BGP network. */
4674 bgp_static_unset_safi(safi_t safi
, struct vty
*vty
, const char *ip_str
,
4675 const char *rd_str
, const char *tag_str
,
4676 int evpn_type
, const char *esi
, const char *gwip
, const char *ethtag
)
4678 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4681 struct prefix_rd prd
;
4682 struct bgp_node
*prn
;
4683 struct bgp_node
*rn
;
4684 struct bgp_table
*table
;
4685 struct bgp_static
*bgp_static
;
4689 if(safi
== SAFI_EVPN
)
4694 /* Convert IP prefix string to struct prefix. */
4695 ret
= str2prefix (ip_str
, &p
);
4698 vty_out (vty
, "%% Malformed prefix%s", VTY_NEWLINE
);
4702 if ( (afi
== AFI_L2VPN
) &&
4703 (bgp_build_evpn_prefix ( evpn_type
, ethtag
!=NULL
?atol(ethtag
):0, &p
)))
4705 vty_out (vty
, "%% L2VPN prefix could not be forged%s", VTY_NEWLINE
);
4708 ret
= str2prefix_rd (rd_str
, &prd
);
4711 vty_out (vty
, "%% Malformed rd%s", VTY_NEWLINE
);
4715 ret
= str2tag (tag_str
, tag
);
4718 vty_out (vty
, "%% Malformed tag%s", VTY_NEWLINE
);
4722 prn
= bgp_node_get (bgp
->route
[afi
][safi
],
4723 (struct prefix
*)&prd
);
4724 if (prn
->info
== NULL
)
4725 prn
->info
= bgp_table_init (afi
, safi
);
4727 bgp_unlock_node (prn
);
4730 rn
= bgp_node_lookup (table
, &p
);
4734 bgp_static_withdraw_safi (bgp
, &p
, afi
, safi
, &prd
, tag
);
4736 bgp_static
= rn
->info
;
4737 bgp_static_free (bgp_static
);
4739 bgp_unlock_node (rn
);
4740 bgp_unlock_node (rn
);
4743 vty_out (vty
, "%% Can't find the route%s", VTY_NEWLINE
);
4749 bgp_table_map_set (struct vty
*vty
, afi_t afi
, safi_t safi
,
4750 const char *rmap_name
)
4752 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4753 struct bgp_rmap
*rmap
;
4755 rmap
= &bgp
->table_map
[afi
][safi
];
4759 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap
->name
);
4760 rmap
->name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
4761 rmap
->map
= route_map_lookup_by_name (rmap_name
);
4766 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap
->name
);
4771 bgp_zebra_announce_table(bgp
, afi
, safi
);
4777 bgp_table_map_unset (struct vty
*vty
, afi_t afi
, safi_t safi
,
4778 const char *rmap_name
)
4780 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
4781 struct bgp_rmap
*rmap
;
4783 rmap
= &bgp
->table_map
[afi
][safi
];
4785 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap
->name
);
4789 bgp_zebra_announce_table(bgp
, afi
, safi
);
4795 bgp_config_write_table_map (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
4796 safi_t safi
, int *write
)
4798 if (bgp
->table_map
[afi
][safi
].name
)
4800 bgp_config_write_family_header (vty
, afi
, safi
, write
);
4801 vty_out (vty
, " table-map %s%s",
4802 bgp
->table_map
[afi
][safi
].name
, VTY_NEWLINE
);
4808 DEFUN (bgp_table_map
,
4811 "BGP table to RIB route download filter\n"
4812 "Name of the route map\n")
4815 return bgp_table_map_set (vty
,
4816 bgp_node_afi (vty
), bgp_node_safi (vty
), argv
[idx_word
]->arg
);
4818 DEFUN (no_bgp_table_map
,
4819 no_bgp_table_map_cmd
,
4820 "no table-map WORD",
4822 "BGP table to RIB route download filter\n"
4823 "Name of the route map\n")
4826 return bgp_table_map_unset (vty
,
4827 bgp_node_afi (vty
), bgp_node_safi (vty
), argv
[idx_word
]->arg
);
4832 "network A.B.C.D/M",
4833 "Specify a network to announce via BGP\n"
4836 int idx_ipv4_prefixlen
= 1;
4837 return bgp_static_set (vty
, argv
[idx_ipv4_prefixlen
]->arg
,
4838 AFI_IP
, bgp_node_safi (vty
), NULL
, 0,
4839 BGP_INVALID_LABEL_INDEX
);
4842 DEFUN (bgp_network_route_map
,
4843 bgp_network_route_map_cmd
,
4844 "network A.B.C.D/M route-map WORD",
4845 "Specify a network to announce via BGP\n"
4847 "Route-map to modify the attributes\n"
4848 "Name of the route map\n")
4850 int idx_ipv4_prefixlen
= 1;
4852 return bgp_static_set (vty
, argv
[idx_ipv4_prefixlen
]->arg
,
4853 AFI_IP
, bgp_node_safi (vty
), argv
[idx_word
]->arg
, 0,
4854 BGP_INVALID_LABEL_INDEX
);
4857 DEFUN (bgp_network_backdoor
,
4858 bgp_network_backdoor_cmd
,
4859 "network A.B.C.D/M backdoor",
4860 "Specify a network to announce via BGP\n"
4862 "Specify a BGP backdoor route\n")
4864 int idx_ipv4_prefixlen
= 1;
4865 return bgp_static_set (vty
, argv
[idx_ipv4_prefixlen
]->arg
, AFI_IP
, SAFI_UNICAST
,
4866 NULL
, 1, BGP_INVALID_LABEL_INDEX
);
4869 DEFUN (bgp_network_mask
,
4870 bgp_network_mask_cmd
,
4871 "network A.B.C.D mask A.B.C.D",
4872 "Specify a network to announce via BGP\n"
4880 char prefix_str
[BUFSIZ
];
4882 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, argv
[idx_ipv4_2
]->arg
, prefix_str
);
4885 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
4889 return bgp_static_set (vty
, prefix_str
,
4890 AFI_IP
, bgp_node_safi (vty
), NULL
, 0, BGP_INVALID_LABEL_INDEX
);
4893 DEFUN (bgp_network_mask_route_map
,
4894 bgp_network_mask_route_map_cmd
,
4895 "network A.B.C.D mask A.B.C.D route-map WORD",
4896 "Specify a network to announce via BGP\n"
4900 "Route-map to modify the attributes\n"
4901 "Name of the route map\n")
4907 char prefix_str
[BUFSIZ
];
4909 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, argv
[idx_ipv4_2
]->arg
, prefix_str
);
4912 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
4916 return bgp_static_set (vty
, prefix_str
,
4917 AFI_IP
, bgp_node_safi (vty
), argv
[idx_word
]->arg
, 0, BGP_INVALID_LABEL_INDEX
);
4920 DEFUN (bgp_network_mask_backdoor
,
4921 bgp_network_mask_backdoor_cmd
,
4922 "network A.B.C.D mask A.B.C.D backdoor",
4923 "Specify a network to announce via BGP\n"
4927 "Specify a BGP backdoor route\n")
4932 char prefix_str
[BUFSIZ
];
4934 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, argv
[idx_ipv4_2
]->arg
, prefix_str
);
4937 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
4941 return bgp_static_set (vty
, prefix_str
, AFI_IP
, SAFI_UNICAST
,
4943 BGP_INVALID_LABEL_INDEX
);
4946 DEFUN (bgp_network_mask_natural
,
4947 bgp_network_mask_natural_cmd
,
4949 "Specify a network to announce via BGP\n"
4954 char prefix_str
[BUFSIZ
];
4956 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, NULL
, prefix_str
);
4959 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
4963 return bgp_static_set (vty
, prefix_str
,
4964 AFI_IP
, bgp_node_safi (vty
), NULL
, 0,
4965 BGP_INVALID_LABEL_INDEX
);
4968 DEFUN (bgp_network_mask_natural_route_map
,
4969 bgp_network_mask_natural_route_map_cmd
,
4970 "network A.B.C.D route-map WORD",
4971 "Specify a network to announce via BGP\n"
4973 "Route-map to modify the attributes\n"
4974 "Name of the route map\n")
4979 char prefix_str
[BUFSIZ
];
4981 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, NULL
, prefix_str
);
4984 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
4988 return bgp_static_set (vty
, prefix_str
,
4989 AFI_IP
, bgp_node_safi (vty
), argv
[idx_word
]->arg
, 0,
4990 BGP_INVALID_LABEL_INDEX
);
4993 DEFUN (bgp_network_mask_natural_backdoor
,
4994 bgp_network_mask_natural_backdoor_cmd
,
4995 "network A.B.C.D backdoor",
4996 "Specify a network to announce via BGP\n"
4998 "Specify a BGP backdoor route\n")
5002 char prefix_str
[BUFSIZ
];
5004 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, NULL
, prefix_str
);
5007 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
5011 return bgp_static_set (vty
, prefix_str
, AFI_IP
, SAFI_UNICAST
,
5012 NULL
, 1, BGP_INVALID_LABEL_INDEX
);
5015 DEFUN (bgp_network_label_index
,
5016 bgp_network_label_index_cmd
,
5017 "network A.B.C.D/M label-index (0-4294967294)",
5018 "Specify a network to announce via BGP\n"
5019 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5020 "Label index to associate with the prefix\n"
5021 "Label index value\n")
5023 u_int32_t label_index
;
5025 VTY_GET_INTEGER ("label-index", label_index
, argv
[3]->arg
);
5026 return bgp_static_set (vty
, argv
[1]->arg
,
5027 AFI_IP
, bgp_node_safi (vty
), NULL
, 0, label_index
);
5030 DEFUN (bgp_network_label_index_route_map
,
5031 bgp_network_label_index_route_map_cmd
,
5032 "network A.B.C.D/M label-index (0-4294967294) route-map WORD",
5033 "Specify a network to announce via BGP\n"
5035 "Label index to associate with the prefix\n"
5036 "Label index value\n"
5037 "Route-map to modify the attributes\n"
5038 "Name of the route map\n")
5040 u_int32_t label_index
;
5042 VTY_GET_INTEGER ("label-index", label_index
, argv
[3]->arg
);
5043 return bgp_static_set (vty
, argv
[1]->arg
,
5044 AFI_IP
, bgp_node_safi (vty
), argv
[5]->arg
, 0, label_index
);
5047 DEFUN (no_bgp_network
,
5049 "no network A.B.C.D/M [<backdoor|route-map WORD>]",
5051 "Specify a network to announce via BGP\n"
5053 "Specify a BGP backdoor route\n"
5054 "Route-map to modify the attributes\n"
5055 "Name of the route map\n")
5057 int idx_ipv4_prefixlen
= 2;
5058 return bgp_static_unset (vty
, argv
[idx_ipv4_prefixlen
]->arg
, AFI_IP
,
5059 bgp_node_safi (vty
));
5062 DEFUN (no_bgp_network_mask
,
5063 no_bgp_network_mask_cmd
,
5064 "no network A.B.C.D mask A.B.C.D [<backdoor|route-map WORD>]",
5066 "Specify a network to announce via BGP\n"
5070 "Specify a BGP backdoor route\n"
5071 "Route-map to modify the attributes\n"
5072 "Name of the route map\n")
5077 char prefix_str
[BUFSIZ
];
5079 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, argv
[idx_ipv4_2
]->arg
, prefix_str
);
5082 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
5086 return bgp_static_unset (vty
, prefix_str
, AFI_IP
,
5087 bgp_node_safi (vty
));
5090 DEFUN (no_bgp_network_mask_natural
,
5091 no_bgp_network_mask_natural_cmd
,
5092 "no network A.B.C.D [<backdoor|route-map WORD>]",
5094 "Specify a network to announce via BGP\n"
5096 "Specify a BGP backdoor route\n"
5097 "Route-map to modify the attributes\n"
5098 "Name of the route map\n")
5102 char prefix_str
[BUFSIZ
];
5104 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, NULL
, prefix_str
);
5107 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
5111 return bgp_static_unset (vty
, prefix_str
, AFI_IP
,
5112 bgp_node_safi (vty
));
5115 ALIAS (no_bgp_network
,
5116 no_bgp_network_label_index_cmd
,
5117 "no network A.B.C.D/M label-index (0-4294967294)",
5119 "Specify a network to announce via BGP\n"
5120 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5121 "Label index to associate with the prefix\n"
5122 "Label index value\n")
5124 ALIAS (no_bgp_network
,
5125 no_bgp_network_label_index_route_map_cmd
,
5126 "no network A.B.C.D/M label-index (0-4294967294) route-map WORD",
5128 "Specify a network to announce via BGP\n"
5130 "Label index to associate with the prefix\n"
5131 "Label index value\n"
5132 "Route-map to modify the attributes\n"
5133 "Name of the route map\n")
5135 DEFUN (ipv6_bgp_network
,
5136 ipv6_bgp_network_cmd
,
5137 "network X:X::X:X/M",
5138 "Specify a network to announce via BGP\n"
5141 int idx_ipv6_prefixlen
= 1;
5142 return bgp_static_set (vty
, argv
[idx_ipv6_prefixlen
]->arg
, AFI_IP6
, bgp_node_safi(vty
),
5144 BGP_INVALID_LABEL_INDEX
);
5147 DEFUN (ipv6_bgp_network_route_map
,
5148 ipv6_bgp_network_route_map_cmd
,
5149 "network X:X::X:X/M route-map WORD",
5150 "Specify a network to announce via BGP\n"
5152 "Route-map to modify the attributes\n"
5153 "Name of the route map\n")
5155 int idx_ipv6_prefixlen
= 1;
5157 return bgp_static_set (vty
, argv
[idx_ipv6_prefixlen
]->arg
, AFI_IP6
,
5158 bgp_node_safi (vty
), argv
[idx_word
]->arg
, 0,
5159 BGP_INVALID_LABEL_INDEX
);
5162 DEFUN (ipv6_bgp_network_label_index
,
5163 ipv6_bgp_network_label_index_cmd
,
5164 "network X:X::X:X/M label-index (0-4294967294)",
5165 "Specify a network to announce via BGP\n"
5166 "IPv6 prefix <network>/<length>\n"
5167 "Label index to associate with the prefix\n"
5168 "Label index value\n")
5170 u_int32_t label_index
;
5172 VTY_GET_INTEGER ("label-index", label_index
, argv
[3]->arg
);
5173 return bgp_static_set (vty
, argv
[1]->arg
,
5174 AFI_IP6
, bgp_node_safi (vty
), NULL
, 0, label_index
);
5177 DEFUN (ipv6_bgp_network_label_index_route_map
,
5178 ipv6_bgp_network_label_index_route_map_cmd
,
5179 "network X:X::X:X/M label-index (0-4294967294) route-map WORD",
5180 "Specify a network to announce via BGP\n"
5182 "Label index to associate with the prefix\n"
5183 "Label index value\n"
5184 "Route-map to modify the attributes\n"
5185 "Name of the route map\n")
5187 u_int32_t label_index
;
5189 VTY_GET_INTEGER ("label-index", label_index
, argv
[3]->arg
);
5190 return bgp_static_set (vty
, argv
[1]->arg
,
5191 AFI_IP6
, bgp_node_safi (vty
), argv
[5]->arg
, 0, label_index
);
5194 DEFUN (no_ipv6_bgp_network
,
5195 no_ipv6_bgp_network_cmd
,
5196 "no network X:X::X:X/M [route-map WORD]",
5198 "Specify a network to announce via BGP\n"
5200 "Route-map to modify the attributes\n"
5201 "Name of the route map\n")
5203 int idx_ipv6_prefixlen
= 2;
5204 return bgp_static_unset (vty
, argv
[idx_ipv6_prefixlen
]->arg
, AFI_IP6
, bgp_node_safi(vty
));
5207 ALIAS (no_ipv6_bgp_network
,
5208 no_ipv6_bgp_network_label_index_cmd
,
5209 "no network X:X::X:X/M label-index (0-4294967294)",
5211 "Specify a network to announce via BGP\n"
5212 "IPv6 prefix <network>/<length>\n"
5213 "Label index to associate with the prefix\n"
5214 "Label index value\n")
5216 ALIAS (no_ipv6_bgp_network
,
5217 no_ipv6_bgp_network_label_index_route_map_cmd
,
5218 "no network X:X::X:X/M label-index (0-4294967294) route-map WORD",
5220 "Specify a network to announce via BGP\n"
5222 "Label index to associate with the prefix\n"
5223 "Label index value\n"
5224 "Route-map to modify the attributes\n"
5225 "Name of the route map\n")
5227 /* Aggreagete address:
5229 advertise-map Set condition to advertise attribute
5230 as-set Generate AS set path information
5231 attribute-map Set attributes of aggregate
5232 route-map Set parameters of aggregate
5233 summary-only Filter more specific routes from updates
5234 suppress-map Conditionally filter more specific routes from updates
5237 struct bgp_aggregate
5239 /* Summary-only flag. */
5240 u_char summary_only
;
5242 /* AS set generation. */
5245 /* Route-map for aggregated route. */
5246 struct route_map
*map
;
5248 /* Suppress-count. */
5249 unsigned long count
;
5251 /* SAFI configuration. */
5255 static struct bgp_aggregate
*
5256 bgp_aggregate_new (void)
5258 return XCALLOC (MTYPE_BGP_AGGREGATE
, sizeof (struct bgp_aggregate
));
5262 bgp_aggregate_free (struct bgp_aggregate
*aggregate
)
5264 XFREE (MTYPE_BGP_AGGREGATE
, aggregate
);
5267 /* Update an aggregate as routes are added/removed from the BGP table */
5269 bgp_aggregate_route (struct bgp
*bgp
, struct prefix
*p
, struct bgp_info
*rinew
,
5270 afi_t afi
, safi_t safi
, struct bgp_info
*del
,
5271 struct bgp_aggregate
*aggregate
)
5273 struct bgp_table
*table
;
5274 struct bgp_node
*top
;
5275 struct bgp_node
*rn
;
5277 struct aspath
*aspath
= NULL
;
5278 struct aspath
*asmerge
= NULL
;
5279 struct community
*community
= NULL
;
5280 struct community
*commerge
= NULL
;
5281 #if defined(AGGREGATE_NEXTHOP_CHECK)
5282 struct in_addr nexthop
;
5285 struct bgp_info
*ri
;
5286 struct bgp_info
*new;
5288 unsigned long match
= 0;
5289 u_char atomic_aggregate
= 0;
5291 /* Record adding route's nexthop and med. */
5294 #if defined(AGGREGATE_NEXTHOP_CHECK)
5295 nexthop
= rinew
->attr
->nexthop
;
5296 med
= rinew
->attr
->med
;
5300 /* ORIGIN attribute: If at least one route among routes that are
5301 aggregated has ORIGIN with the value INCOMPLETE, then the
5302 aggregated route must have the ORIGIN attribute with the value
5303 INCOMPLETE. Otherwise, if at least one route among routes that
5304 are aggregated has ORIGIN with the value EGP, then the aggregated
5305 route must have the origin attribute with the value EGP. In all
5306 other case the value of the ORIGIN attribute of the aggregated
5307 route is INTERNAL. */
5308 origin
= BGP_ORIGIN_IGP
;
5310 table
= bgp
->rib
[afi
][safi
];
5312 top
= bgp_node_get (table
, p
);
5313 for (rn
= bgp_node_get (table
, p
); rn
; rn
= bgp_route_next_until (rn
, top
))
5314 if (rn
->p
.prefixlen
> p
->prefixlen
)
5318 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
5320 if (BGP_INFO_HOLDDOWN (ri
))
5323 if (del
&& ri
== del
)
5326 if (! rinew
&& first
)
5328 #if defined(AGGREGATE_NEXTHOP_CHECK)
5329 nexthop
= ri
->attr
->nexthop
;
5330 med
= ri
->attr
->med
;
5335 #ifdef AGGREGATE_NEXTHOP_CHECK
5336 if (! IPV4_ADDR_SAME (&ri
->attr
->nexthop
, &nexthop
)
5337 || ri
->attr
->med
!= med
)
5340 aspath_free (aspath
);
5342 community_free (community
);
5343 bgp_unlock_node (rn
);
5344 bgp_unlock_node (top
);
5347 #endif /* AGGREGATE_NEXTHOP_CHECK */
5349 if (ri
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
))
5350 atomic_aggregate
= 1;
5352 if (ri
->sub_type
!= BGP_ROUTE_AGGREGATE
)
5354 if (aggregate
->summary_only
)
5356 (bgp_info_extra_get (ri
))->suppress
++;
5357 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
5363 if (origin
< ri
->attr
->origin
)
5364 origin
= ri
->attr
->origin
;
5366 if (aggregate
->as_set
)
5370 asmerge
= aspath_aggregate (aspath
, ri
->attr
->aspath
);
5371 aspath_free (aspath
);
5375 aspath
= aspath_dup (ri
->attr
->aspath
);
5377 if (ri
->attr
->community
)
5381 commerge
= community_merge (community
,
5382 ri
->attr
->community
);
5383 community
= community_uniq_sort (commerge
);
5384 community_free (commerge
);
5387 community
= community_dup (ri
->attr
->community
);
5393 bgp_process (bgp
, rn
, afi
, safi
);
5395 bgp_unlock_node (top
);
5401 if (aggregate
->summary_only
)
5402 (bgp_info_extra_get (rinew
))->suppress
++;
5404 if (origin
< rinew
->attr
->origin
)
5405 origin
= rinew
->attr
->origin
;
5407 if (aggregate
->as_set
)
5411 asmerge
= aspath_aggregate (aspath
, rinew
->attr
->aspath
);
5412 aspath_free (aspath
);
5416 aspath
= aspath_dup (rinew
->attr
->aspath
);
5418 if (rinew
->attr
->community
)
5422 commerge
= community_merge (community
,
5423 rinew
->attr
->community
);
5424 community
= community_uniq_sort (commerge
);
5425 community_free (commerge
);
5428 community
= community_dup (rinew
->attr
->community
);
5433 if (aggregate
->count
> 0)
5435 rn
= bgp_node_get (table
, p
);
5436 new = info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_AGGREGATE
, 0, bgp
->peer_self
,
5437 bgp_attr_aggregate_intern(bgp
, origin
, aspath
, community
,
5439 atomic_aggregate
), rn
);
5440 SET_FLAG (new->flags
, BGP_INFO_VALID
);
5442 bgp_info_add (rn
, new);
5443 bgp_unlock_node (rn
);
5444 bgp_process (bgp
, rn
, afi
, safi
);
5449 aspath_free (aspath
);
5451 community_free (community
);
5455 void bgp_aggregate_delete (struct bgp
*, struct prefix
*, afi_t
, safi_t
,
5456 struct bgp_aggregate
*);
5459 bgp_aggregate_increment (struct bgp
*bgp
, struct prefix
*p
,
5460 struct bgp_info
*ri
, afi_t afi
, safi_t safi
)
5462 struct bgp_node
*child
;
5463 struct bgp_node
*rn
;
5464 struct bgp_aggregate
*aggregate
;
5465 struct bgp_table
*table
;
5467 /* MPLS-VPN aggregation is not yet supported. */
5468 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) || (safi
== SAFI_EVPN
))
5471 table
= bgp
->aggregate
[afi
][safi
];
5473 /* No aggregates configured. */
5474 if (bgp_table_top_nolock (table
) == NULL
)
5477 if (p
->prefixlen
== 0)
5480 if (BGP_INFO_HOLDDOWN (ri
))
5483 child
= bgp_node_get (table
, p
);
5485 /* Aggregate address configuration check. */
5486 for (rn
= child
; rn
; rn
= bgp_node_parent_nolock (rn
))
5487 if ((aggregate
= rn
->info
) != NULL
&& rn
->p
.prefixlen
< p
->prefixlen
)
5489 bgp_aggregate_delete (bgp
, &rn
->p
, afi
, safi
, aggregate
);
5490 bgp_aggregate_route (bgp
, &rn
->p
, ri
, afi
, safi
, NULL
, aggregate
);
5492 bgp_unlock_node (child
);
5496 bgp_aggregate_decrement (struct bgp
*bgp
, struct prefix
*p
,
5497 struct bgp_info
*del
, afi_t afi
, safi_t safi
)
5499 struct bgp_node
*child
;
5500 struct bgp_node
*rn
;
5501 struct bgp_aggregate
*aggregate
;
5502 struct bgp_table
*table
;
5504 /* MPLS-VPN aggregation is not yet supported. */
5505 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) || (safi
== SAFI_EVPN
))
5508 table
= bgp
->aggregate
[afi
][safi
];
5510 /* No aggregates configured. */
5511 if (bgp_table_top_nolock (table
) == NULL
)
5514 if (p
->prefixlen
== 0)
5517 child
= bgp_node_get (table
, p
);
5519 /* Aggregate address configuration check. */
5520 for (rn
= child
; rn
; rn
= bgp_node_parent_nolock (rn
))
5521 if ((aggregate
= rn
->info
) != NULL
&& rn
->p
.prefixlen
< p
->prefixlen
)
5523 bgp_aggregate_delete (bgp
, &rn
->p
, afi
, safi
, aggregate
);
5524 bgp_aggregate_route (bgp
, &rn
->p
, NULL
, afi
, safi
, del
, aggregate
);
5526 bgp_unlock_node (child
);
5529 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5531 bgp_aggregate_add (struct bgp
*bgp
, struct prefix
*p
, afi_t afi
, safi_t safi
,
5532 struct bgp_aggregate
*aggregate
)
5534 struct bgp_table
*table
;
5535 struct bgp_node
*top
;
5536 struct bgp_node
*rn
;
5537 struct bgp_info
*new;
5538 struct bgp_info
*ri
;
5539 unsigned long match
;
5540 u_char origin
= BGP_ORIGIN_IGP
;
5541 struct aspath
*aspath
= NULL
;
5542 struct aspath
*asmerge
= NULL
;
5543 struct community
*community
= NULL
;
5544 struct community
*commerge
= NULL
;
5545 u_char atomic_aggregate
= 0;
5547 table
= bgp
->rib
[afi
][safi
];
5550 if (afi
== AFI_IP
&& p
->prefixlen
== IPV4_MAX_BITLEN
)
5552 if (afi
== AFI_IP6
&& p
->prefixlen
== IPV6_MAX_BITLEN
)
5555 /* If routes exists below this node, generate aggregate routes. */
5556 top
= bgp_node_get (table
, p
);
5557 for (rn
= bgp_node_get (table
, p
); rn
; rn
= bgp_route_next_until (rn
, top
))
5558 if (rn
->p
.prefixlen
> p
->prefixlen
)
5562 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
5564 if (BGP_INFO_HOLDDOWN (ri
))
5567 if (ri
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
))
5568 atomic_aggregate
= 1;
5570 if (ri
->sub_type
!= BGP_ROUTE_AGGREGATE
)
5572 /* summary-only aggregate route suppress aggregated
5573 route announcement. */
5574 if (aggregate
->summary_only
)
5576 (bgp_info_extra_get (ri
))->suppress
++;
5577 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
5581 /* If at least one route among routes that are aggregated has
5582 * ORIGIN with the value INCOMPLETE, then the aggregated route
5583 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5584 * Otherwise, if at least one route among routes that are
5585 * aggregated has ORIGIN with the value EGP, then the aggregated
5586 * route MUST have the ORIGIN attribute with the value EGP.
5588 if (origin
< ri
->attr
->origin
)
5589 origin
= ri
->attr
->origin
;
5591 /* as-set aggregate route generate origin, as path,
5592 community aggregation. */
5593 if (aggregate
->as_set
)
5597 asmerge
= aspath_aggregate (aspath
, ri
->attr
->aspath
);
5598 aspath_free (aspath
);
5602 aspath
= aspath_dup (ri
->attr
->aspath
);
5604 if (ri
->attr
->community
)
5608 commerge
= community_merge (community
,
5609 ri
->attr
->community
);
5610 community
= community_uniq_sort (commerge
);
5611 community_free (commerge
);
5614 community
= community_dup (ri
->attr
->community
);
5621 /* If this node is suppressed, process the change. */
5623 bgp_process (bgp
, rn
, afi
, safi
);
5625 bgp_unlock_node (top
);
5627 /* Add aggregate route to BGP table. */
5628 if (aggregate
->count
)
5630 rn
= bgp_node_get (table
, p
);
5631 new = info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_AGGREGATE
, 0, bgp
->peer_self
,
5632 bgp_attr_aggregate_intern(bgp
, origin
, aspath
, community
,
5634 atomic_aggregate
), rn
);
5635 SET_FLAG (new->flags
, BGP_INFO_VALID
);
5637 bgp_info_add (rn
, new);
5638 bgp_unlock_node (rn
);
5640 /* Process change. */
5641 bgp_process (bgp
, rn
, afi
, safi
);
5646 aspath_free (aspath
);
5648 community_free (community
);
5653 bgp_aggregate_delete (struct bgp
*bgp
, struct prefix
*p
, afi_t afi
,
5654 safi_t safi
, struct bgp_aggregate
*aggregate
)
5656 struct bgp_table
*table
;
5657 struct bgp_node
*top
;
5658 struct bgp_node
*rn
;
5659 struct bgp_info
*ri
;
5660 unsigned long match
;
5662 table
= bgp
->rib
[afi
][safi
];
5664 if (afi
== AFI_IP
&& p
->prefixlen
== IPV4_MAX_BITLEN
)
5666 if (afi
== AFI_IP6
&& p
->prefixlen
== IPV6_MAX_BITLEN
)
5669 /* If routes exists below this node, generate aggregate routes. */
5670 top
= bgp_node_get (table
, p
);
5671 for (rn
= bgp_node_get (table
, p
); rn
; rn
= bgp_route_next_until (rn
, top
))
5672 if (rn
->p
.prefixlen
> p
->prefixlen
)
5676 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
5678 if (BGP_INFO_HOLDDOWN (ri
))
5681 if (ri
->sub_type
!= BGP_ROUTE_AGGREGATE
)
5683 if (aggregate
->summary_only
&& ri
->extra
)
5685 ri
->extra
->suppress
--;
5687 if (ri
->extra
->suppress
== 0)
5689 bgp_info_set_flag (rn
, ri
, BGP_INFO_ATTR_CHANGED
);
5697 /* If this node was suppressed, process the change. */
5699 bgp_process (bgp
, rn
, afi
, safi
);
5701 bgp_unlock_node (top
);
5703 /* Delete aggregate route from BGP table. */
5704 rn
= bgp_node_get (table
, p
);
5706 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
5707 if (ri
->peer
== bgp
->peer_self
5708 && ri
->type
== ZEBRA_ROUTE_BGP
5709 && ri
->sub_type
== BGP_ROUTE_AGGREGATE
)
5712 /* Withdraw static BGP route from routing table. */
5715 bgp_info_delete (rn
, ri
);
5716 bgp_process (bgp
, rn
, afi
, safi
);
5719 /* Unlock bgp_node_lookup. */
5720 bgp_unlock_node (rn
);
5723 /* Aggregate route attribute. */
5724 #define AGGREGATE_SUMMARY_ONLY 1
5725 #define AGGREGATE_AS_SET 1
5728 bgp_aggregate_unset (struct vty
*vty
, const char *prefix_str
,
5729 afi_t afi
, safi_t safi
)
5731 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
5734 struct bgp_node
*rn
;
5735 struct bgp_aggregate
*aggregate
;
5737 /* Convert string to prefix structure. */
5738 ret
= str2prefix (prefix_str
, &p
);
5741 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
5746 /* Old configuration check. */
5747 rn
= bgp_node_lookup (bgp
->aggregate
[afi
][safi
], &p
);
5750 vty_out (vty
, "%% There is no aggregate-address configuration.%s",
5755 aggregate
= rn
->info
;
5756 if (aggregate
->safi
== SAFI_UNICAST
)
5757 bgp_aggregate_delete (bgp
, &p
, afi
, SAFI_UNICAST
, aggregate
);
5758 if (aggregate
->safi
== SAFI_LABELED_UNICAST
)
5759 bgp_aggregate_delete (bgp
, &p
, afi
, SAFI_LABELED_UNICAST
, aggregate
);
5760 if (aggregate
->safi
== SAFI_MULTICAST
)
5761 bgp_aggregate_delete (bgp
, &p
, afi
, SAFI_MULTICAST
, aggregate
);
5763 /* Unlock aggregate address configuration. */
5765 bgp_aggregate_free (aggregate
);
5766 bgp_unlock_node (rn
);
5767 bgp_unlock_node (rn
);
5773 bgp_aggregate_set (struct vty
*vty
, const char *prefix_str
,
5774 afi_t afi
, safi_t safi
,
5775 u_char summary_only
, u_char as_set
)
5777 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
5780 struct bgp_node
*rn
;
5781 struct bgp_aggregate
*aggregate
;
5783 /* Convert string to prefix structure. */
5784 ret
= str2prefix (prefix_str
, &p
);
5787 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
5792 /* Old configuration check. */
5793 rn
= bgp_node_get (bgp
->aggregate
[afi
][safi
], &p
);
5797 vty_out (vty
, "There is already same aggregate network.%s", VTY_NEWLINE
);
5798 /* try to remove the old entry */
5799 ret
= bgp_aggregate_unset (vty
, prefix_str
, afi
, safi
);
5802 vty_out (vty
, "Error deleting aggregate.%s", VTY_NEWLINE
);
5803 bgp_unlock_node (rn
);
5808 /* Make aggregate address structure. */
5809 aggregate
= bgp_aggregate_new ();
5810 aggregate
->summary_only
= summary_only
;
5811 aggregate
->as_set
= as_set
;
5812 aggregate
->safi
= safi
;
5813 rn
->info
= aggregate
;
5815 /* Aggregate address insert into BGP routing table. */
5816 if (safi
== SAFI_UNICAST
)
5817 bgp_aggregate_add (bgp
, &p
, afi
, SAFI_UNICAST
, aggregate
);
5818 if (safi
== SAFI_LABELED_UNICAST
)
5819 bgp_aggregate_add (bgp
, &p
, afi
, SAFI_LABELED_UNICAST
, aggregate
);
5820 if (safi
== SAFI_MULTICAST
)
5821 bgp_aggregate_add (bgp
, &p
, afi
, SAFI_MULTICAST
, aggregate
);
5826 DEFUN (aggregate_address
,
5827 aggregate_address_cmd
,
5828 "aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>]",
5829 "Configure BGP aggregate entries\n"
5830 "Aggregate prefix\n"
5831 "Generate AS set path information\n"
5832 "Filter more specific routes from updates\n"
5833 "Filter more specific routes from updates\n"
5834 "Generate AS set path information\n")
5837 argv_find (argv
, argc
, "A.B.C.D/M", &idx
);
5838 char *prefix
= argv
[idx
]->arg
;
5839 int as_set
= argv_find (argv
, argc
, "as-set", &idx
) ? AGGREGATE_AS_SET
: 0;
5841 int summary_only
= argv_find (argv
, argc
, "summary-only", &idx
) ? AGGREGATE_SUMMARY_ONLY
: 0;
5843 return bgp_aggregate_set (vty
, prefix
, AFI_IP
, bgp_node_safi (vty
), summary_only
, as_set
);
5846 DEFUN (aggregate_address_mask
,
5847 aggregate_address_mask_cmd
,
5848 "aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>]",
5849 "Configure BGP aggregate entries\n"
5850 "Aggregate address\n"
5852 "Generate AS set path information\n"
5853 "Filter more specific routes from updates\n"
5854 "Filter more specific routes from updates\n"
5855 "Generate AS set path information\n")
5858 argv_find (argv
, argc
, "A.B.C.D", &idx
);
5859 char *prefix
= argv
[idx
]->arg
;
5860 char *mask
= argv
[idx
+1]->arg
;
5861 int as_set
= argv_find (argv
, argc
, "as-set", &idx
) ? AGGREGATE_AS_SET
: 0;
5863 int summary_only
= argv_find (argv
, argc
, "summary-only", &idx
) ? AGGREGATE_SUMMARY_ONLY
: 0;
5865 char prefix_str
[BUFSIZ
];
5866 int ret
= netmask_str2prefix_str (prefix
, mask
, prefix_str
);
5870 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
5874 return bgp_aggregate_set (vty
, prefix_str
, AFI_IP
, bgp_node_safi (vty
), summary_only
, as_set
);
5877 DEFUN (no_aggregate_address
,
5878 no_aggregate_address_cmd
,
5879 "no aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>]",
5881 "Configure BGP aggregate entries\n"
5882 "Aggregate prefix\n"
5883 "Generate AS set path information\n"
5884 "Filter more specific routes from updates\n"
5885 "Filter more specific routes from updates\n"
5886 "Generate AS set path information\n")
5889 argv_find (argv
, argc
, "A.B.C.D/M", &idx
);
5890 char *prefix
= argv
[idx
]->arg
;
5891 return bgp_aggregate_unset (vty
, prefix
, AFI_IP
, bgp_node_safi (vty
));
5894 DEFUN (no_aggregate_address_mask
,
5895 no_aggregate_address_mask_cmd
,
5896 "no aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>]",
5898 "Configure BGP aggregate entries\n"
5899 "Aggregate address\n"
5901 "Generate AS set path information\n"
5902 "Filter more specific routes from updates\n"
5903 "Filter more specific routes from updates\n"
5904 "Generate AS set path information\n")
5907 argv_find (argv
, argc
, "A.B.C.D", &idx
);
5908 char *prefix
= argv
[idx
]->arg
;
5909 char *mask
= argv
[idx
+1]->arg
;
5911 char prefix_str
[BUFSIZ
];
5912 int ret
= netmask_str2prefix_str (prefix
, mask
, prefix_str
);
5916 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
5920 return bgp_aggregate_unset (vty
, prefix_str
, AFI_IP
, bgp_node_safi (vty
));
5923 DEFUN (ipv6_aggregate_address
,
5924 ipv6_aggregate_address_cmd
,
5925 "aggregate-address X:X::X:X/M [summary-only]",
5926 "Configure BGP aggregate entries\n"
5927 "Aggregate prefix\n"
5928 "Filter more specific routes from updates\n")
5931 argv_find (argv
, argc
, "X:X::X:X/M", &idx
);
5932 char *prefix
= argv
[idx
]->arg
;
5933 int sum_only
= argv_find (argv
, argc
, "summary-only", &idx
) ? AGGREGATE_SUMMARY_ONLY
: 0;
5934 return bgp_aggregate_set (vty
, prefix
, AFI_IP6
, SAFI_UNICAST
, sum_only
, 0);
5937 DEFUN (no_ipv6_aggregate_address
,
5938 no_ipv6_aggregate_address_cmd
,
5939 "no aggregate-address X:X::X:X/M [summary-only]",
5941 "Configure BGP aggregate entries\n"
5942 "Aggregate prefix\n"
5943 "Filter more specific routes from updates\n")
5946 argv_find (argv
, argc
, "X:X::X:X/M", &idx
);
5947 char *prefix
= argv
[idx
]->arg
;
5948 return bgp_aggregate_unset (vty
, prefix
, AFI_IP6
, SAFI_UNICAST
);
5951 /* Redistribute route treatment. */
5953 bgp_redistribute_add (struct bgp
*bgp
, struct prefix
*p
, const struct in_addr
*nexthop
,
5954 const struct in6_addr
*nexthop6
, unsigned int ifindex
,
5955 u_int32_t metric
, u_char type
, u_short instance
, route_tag_t tag
)
5957 struct bgp_info
*new;
5958 struct bgp_info
*bi
;
5959 struct bgp_info info
;
5960 struct bgp_node
*bn
;
5962 struct attr
*new_attr
;
5965 struct bgp_redist
*red
;
5967 /* Make default attribute. */
5968 bgp_attr_default_set (&attr
, BGP_ORIGIN_INCOMPLETE
);
5970 attr
.nexthop
= *nexthop
;
5971 attr
.nh_ifindex
= ifindex
;
5975 struct attr_extra
*extra
= bgp_attr_extra_get(&attr
);
5976 extra
->mp_nexthop_global
= *nexthop6
;
5977 extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
5981 attr
.flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
5982 attr
.extra
->tag
= tag
;
5984 afi
= family2afi (p
->family
);
5986 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
5989 struct attr attr_new
;
5990 struct attr_extra extra_new
;
5992 /* Copy attribute for modification. */
5993 attr_new
.extra
= &extra_new
;
5994 bgp_attr_dup (&attr_new
, &attr
);
5996 if (red
->redist_metric_flag
)
5997 attr_new
.med
= red
->redist_metric
;
5999 /* Apply route-map. */
6002 info
.peer
= bgp
->peer_self
;
6003 info
.attr
= &attr_new
;
6005 SET_FLAG (bgp
->peer_self
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
);
6007 ret
= route_map_apply (red
->rmap
.map
, p
, RMAP_BGP
, &info
);
6009 bgp
->peer_self
->rmap_type
= 0;
6011 if (ret
== RMAP_DENYMATCH
)
6013 /* Free uninterned attribute. */
6014 bgp_attr_flush (&attr_new
);
6016 /* Unintern original. */
6017 aspath_unintern (&attr
.aspath
);
6018 bgp_attr_extra_free (&attr
);
6019 bgp_redistribute_delete (bgp
, p
, type
, instance
);
6024 bn
= bgp_afi_node_get (bgp
->rib
[afi
][SAFI_UNICAST
],
6025 afi
, SAFI_UNICAST
, p
, NULL
);
6027 new_attr
= bgp_attr_intern (&attr_new
);
6029 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
6030 if (bi
->peer
== bgp
->peer_self
6031 && bi
->sub_type
== BGP_ROUTE_REDISTRIBUTE
)
6036 /* Ensure the (source route) type is updated. */
6038 if (attrhash_cmp (bi
->attr
, new_attr
) &&
6039 !CHECK_FLAG(bi
->flags
, BGP_INFO_REMOVED
))
6041 bgp_attr_unintern (&new_attr
);
6042 aspath_unintern (&attr
.aspath
);
6043 bgp_attr_extra_free (&attr
);
6044 bgp_unlock_node (bn
);
6049 /* The attribute is changed. */
6050 bgp_info_set_flag (bn
, bi
, BGP_INFO_ATTR_CHANGED
);
6052 /* Rewrite BGP route information. */
6053 if (CHECK_FLAG(bi
->flags
, BGP_INFO_REMOVED
))
6054 bgp_info_restore(bn
, bi
);
6056 bgp_aggregate_decrement (bgp
, p
, bi
, afi
, SAFI_UNICAST
);
6057 bgp_attr_unintern (&bi
->attr
);
6058 bi
->attr
= new_attr
;
6059 bi
->uptime
= bgp_clock ();
6061 /* Process change. */
6062 bgp_aggregate_increment (bgp
, p
, bi
, afi
, SAFI_UNICAST
);
6063 bgp_process (bgp
, bn
, afi
, SAFI_UNICAST
);
6064 bgp_unlock_node (bn
);
6065 aspath_unintern (&attr
.aspath
);
6066 bgp_attr_extra_free (&attr
);
6071 new = info_make(type
, BGP_ROUTE_REDISTRIBUTE
, instance
, bgp
->peer_self
,
6073 SET_FLAG (new->flags
, BGP_INFO_VALID
);
6075 bgp_aggregate_increment (bgp
, p
, new, afi
, SAFI_UNICAST
);
6076 bgp_info_add (bn
, new);
6077 bgp_unlock_node (bn
);
6078 bgp_process (bgp
, bn
, afi
, SAFI_UNICAST
);
6081 /* Unintern original. */
6082 aspath_unintern (&attr
.aspath
);
6083 bgp_attr_extra_free (&attr
);
6087 bgp_redistribute_delete (struct bgp
*bgp
, struct prefix
*p
, u_char type
, u_short instance
)
6090 struct bgp_node
*rn
;
6091 struct bgp_info
*ri
;
6092 struct bgp_redist
*red
;
6094 afi
= family2afi (p
->family
);
6096 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
6099 rn
= bgp_afi_node_get (bgp
->rib
[afi
][SAFI_UNICAST
], afi
, SAFI_UNICAST
, p
, NULL
);
6101 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
6102 if (ri
->peer
== bgp
->peer_self
6103 && ri
->type
== type
)
6108 bgp_aggregate_decrement (bgp
, p
, ri
, afi
, SAFI_UNICAST
);
6109 bgp_info_delete (rn
, ri
);
6110 bgp_process (bgp
, rn
, afi
, SAFI_UNICAST
);
6112 bgp_unlock_node (rn
);
6116 /* Withdraw specified route type's route. */
6118 bgp_redistribute_withdraw (struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
6120 struct bgp_node
*rn
;
6121 struct bgp_info
*ri
;
6122 struct bgp_table
*table
;
6124 table
= bgp
->rib
[afi
][SAFI_UNICAST
];
6126 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
6128 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
6129 if (ri
->peer
== bgp
->peer_self
6131 && ri
->instance
== instance
)
6136 bgp_aggregate_decrement (bgp
, &rn
->p
, ri
, afi
, SAFI_UNICAST
);
6137 bgp_info_delete (rn
, ri
);
6138 bgp_process (bgp
, rn
, afi
, SAFI_UNICAST
);
6143 /* Static function to display route. */
6145 route_vty_out_route (struct prefix
*p
, struct vty
*vty
)
6148 u_int32_t destination
;
6151 if (p
->family
== AF_INET
)
6153 len
= vty_out (vty
, "%s", inet_ntop (p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
));
6154 destination
= ntohl (p
->u
.prefix4
.s_addr
);
6156 if ((IN_CLASSC (destination
) && p
->prefixlen
== 24)
6157 || (IN_CLASSB (destination
) && p
->prefixlen
== 16)
6158 || (IN_CLASSA (destination
) && p
->prefixlen
== 8)
6159 || p
->u
.prefix4
.s_addr
== 0)
6161 /* When mask is natural, mask is not displayed. */
6164 len
+= vty_out (vty
, "/%d", p
->prefixlen
);
6166 else if (p
->family
== AF_ETHERNET
)
6168 prefix2str(p
, buf
, PREFIX_STRLEN
);
6169 len
= vty_out (vty
, "%s", buf
);
6172 len
= vty_out (vty
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
6177 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 20, " ");
6179 vty_out (vty
, "%*s", len
, " ");
6182 enum bgp_display_type
6187 /* Print the short form route status for a bgp_info */
6189 route_vty_short_status_out (struct vty
*vty
, struct bgp_info
*binfo
,
6190 json_object
*json_path
)
6195 /* Route status display. */
6196 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_REMOVED
))
6197 json_object_boolean_true_add(json_path
, "removed");
6199 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_STALE
))
6200 json_object_boolean_true_add(json_path
, "stale");
6202 if (binfo
->extra
&& binfo
->extra
->suppress
)
6203 json_object_boolean_true_add(json_path
, "suppressed");
6205 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_VALID
) &&
6206 ! CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
6207 json_object_boolean_true_add(json_path
, "valid");
6210 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
6211 json_object_boolean_true_add(json_path
, "history");
6213 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_DAMPED
))
6214 json_object_boolean_true_add(json_path
, "damped");
6216 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
))
6217 json_object_boolean_true_add(json_path
, "bestpath");
6219 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_MULTIPATH
))
6220 json_object_boolean_true_add(json_path
, "multipath");
6222 /* Internal route. */
6223 if ((binfo
->peer
->as
) && (binfo
->peer
->as
== binfo
->peer
->local_as
))
6224 json_object_string_add(json_path
, "pathFrom", "internal");
6226 json_object_string_add(json_path
, "pathFrom", "external");
6231 /* Route status display. */
6232 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_REMOVED
))
6234 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_STALE
))
6236 else if (binfo
->extra
&& binfo
->extra
->suppress
)
6238 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_VALID
) &&
6239 ! CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
6245 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
6247 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_DAMPED
))
6249 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
))
6251 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_MULTIPATH
))
6256 /* Internal route. */
6258 (binfo
->peer
->as
) && (binfo
->peer
->as
== binfo
->peer
->local_as
))
6264 /* called from terminal list command */
6266 route_vty_out (struct vty
*vty
, struct prefix
*p
,
6267 struct bgp_info
*binfo
, int display
, safi_t safi
,
6268 json_object
*json_paths
)
6271 json_object
*json_path
= NULL
;
6272 json_object
*json_nexthops
= NULL
;
6273 json_object
*json_nexthop_global
= NULL
;
6274 json_object
*json_nexthop_ll
= NULL
;
6277 json_path
= json_object_new_object();
6279 /* short status lead text */
6280 route_vty_short_status_out (vty
, binfo
, json_path
);
6284 /* print prefix and mask */
6286 route_vty_out_route (p
, vty
);
6288 vty_out (vty
, "%*s", 17, " ");
6291 /* Print attribute */
6296 * For ENCAP routes, nexthop address family is not
6297 * neccessarily the same as the prefix address family.
6298 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6300 if ((safi
== SAFI_ENCAP
) || (safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_EVPN
))
6305 int af
= NEXTHOP_FAMILY(attr
->extra
->mp_nexthop_len
);
6310 vty_out (vty
, "%s", inet_ntop(af
,
6311 &attr
->extra
->mp_nexthop_global_in
, buf
, BUFSIZ
));
6314 vty_out (vty
, "%s", inet_ntop(af
,
6315 &attr
->extra
->mp_nexthop_global
, buf
, BUFSIZ
));
6326 else if (p
->family
== AF_INET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6330 json_nexthop_global
= json_object_new_object();
6332 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_EVPN
))
6333 json_object_string_add(json_nexthop_global
, "ip", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6335 json_object_string_add(json_nexthop_global
, "ip", inet_ntoa (attr
->nexthop
));
6337 json_object_string_add(json_nexthop_global
, "afi", "ipv4");
6338 json_object_boolean_true_add(json_nexthop_global
, "used");
6342 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_EVPN
))
6343 vty_out (vty
, "%-16s",
6344 inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6346 vty_out (vty
, "%-16s", inet_ntoa (attr
->nexthop
));
6351 else if (p
->family
== AF_INET6
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6358 json_nexthop_global
= json_object_new_object();
6359 json_object_string_add(json_nexthop_global
, "ip",
6360 inet_ntop (AF_INET6
,
6361 &attr
->extra
->mp_nexthop_global
,
6363 json_object_string_add(json_nexthop_global
, "afi", "ipv6");
6364 json_object_string_add(json_nexthop_global
, "scope", "global");
6366 /* We display both LL & GL if both have been received */
6367 if ((attr
->extra
->mp_nexthop_len
== 32) || (binfo
->peer
->conf_if
))
6369 json_nexthop_ll
= json_object_new_object();
6370 json_object_string_add(json_nexthop_ll
, "ip",
6371 inet_ntop (AF_INET6
,
6372 &attr
->extra
->mp_nexthop_local
,
6374 json_object_string_add(json_nexthop_ll
, "afi", "ipv6");
6375 json_object_string_add(json_nexthop_ll
, "scope", "link-local");
6377 if ((IPV6_ADDR_CMP (&attr
->extra
->mp_nexthop_global
,
6378 &attr
->extra
->mp_nexthop_local
) != 0) &&
6379 !attr
->extra
->mp_nexthop_prefer_global
)
6380 json_object_boolean_true_add(json_nexthop_ll
, "used");
6382 json_object_boolean_true_add(json_nexthop_global
, "used");
6385 json_object_boolean_true_add(json_nexthop_global
, "used");
6389 /* Display LL if LL/Global both in table unless prefer-global is set */
6390 if (((attr
->extra
->mp_nexthop_len
== 32) &&
6391 !attr
->extra
->mp_nexthop_prefer_global
) ||
6392 (binfo
->peer
->conf_if
))
6394 if (binfo
->peer
->conf_if
)
6396 len
= vty_out (vty
, "%s",
6397 binfo
->peer
->conf_if
);
6398 len
= 7 - len
; /* len of IPv6 addr + max len of def ifname */
6401 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 45, " ");
6403 vty_out (vty
, "%*s", len
, " ");
6407 len
= vty_out (vty
, "%s",
6408 inet_ntop (AF_INET6
,
6409 &attr
->extra
->mp_nexthop_local
,
6414 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 36, " ");
6416 vty_out (vty
, "%*s", len
, " ");
6421 len
= vty_out (vty
, "%s",
6422 inet_ntop (AF_INET6
,
6423 &attr
->extra
->mp_nexthop_global
,
6428 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 36, " ");
6430 vty_out (vty
, "%*s", len
, " ");
6436 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
6438 json_object_int_add(json_path
, "med", attr
->med
);
6440 vty_out (vty
, "%10u", attr
->med
);
6446 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
6448 json_object_int_add(json_path
, "localpref", attr
->local_pref
);
6450 vty_out (vty
, "%7u", attr
->local_pref
);
6458 json_object_int_add(json_path
, "weight", attr
->extra
->weight
);
6460 json_object_int_add(json_path
, "weight", 0);
6463 vty_out (vty
, "%7u ", (attr
->extra
? attr
->extra
->weight
: 0));
6467 json_object_string_add(json_path
, "peerId", sockunion2str (&binfo
->peer
->su
, buf
, SU_ADDRSTRLEN
));
6474 json_object_string_add(json_path
, "aspath", attr
->aspath
->str
);
6476 aspath_print_vty (vty
, "%s", attr
->aspath
, " ");
6481 json_object_string_add(json_path
, "origin", bgp_origin_long_str
[attr
->origin
]);
6483 vty_out (vty
, "%s", bgp_origin_str
[attr
->origin
]);
6488 json_object_string_add(json_path
, "alert", "No attributes");
6490 vty_out (vty
, "No attributes to print%s", VTY_NEWLINE
);
6495 if (json_nexthop_global
|| json_nexthop_ll
)
6497 json_nexthops
= json_object_new_array();
6499 if (json_nexthop_global
)
6500 json_object_array_add(json_nexthops
, json_nexthop_global
);
6502 if (json_nexthop_ll
)
6503 json_object_array_add(json_nexthops
, json_nexthop_ll
);
6505 json_object_object_add(json_path
, "nexthops", json_nexthops
);
6508 json_object_array_add(json_paths
, json_path
);
6512 vty_out (vty
, "%s", VTY_NEWLINE
);
6514 /* prints an additional line, indented, with VNC info, if present */
6515 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
))
6516 rfapi_vty_out_vncinfo(vty
, p
, binfo
, safi
);
6521 /* called from terminal list command */
6523 route_vty_out_tmp (struct vty
*vty
, struct prefix
*p
, struct attr
*attr
, safi_t safi
,
6524 u_char use_json
, json_object
*json_ar
)
6526 json_object
*json_status
= NULL
;
6527 json_object
*json_net
= NULL
;
6529 /* Route status display. */
6532 json_status
= json_object_new_object();
6533 json_net
= json_object_new_object();
6542 /* print prefix and mask */
6544 json_object_string_add(json_net
, "addrPrefix", inet_ntop (p
->family
, &p
->u
.prefix
, buff
, BUFSIZ
));
6546 route_vty_out_route (p
, vty
);
6548 /* Print attribute */
6553 if (p
->family
== AF_INET
&&
6554 (safi
== SAFI_MPLS_VPN
||
6555 safi
== SAFI_ENCAP
||
6556 safi
== SAFI_EVPN
||
6557 !BGP_ATTR_NEXTHOP_AFI_IP6(attr
)))
6559 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
)
6560 json_object_string_add(json_net
, "nextHop", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6562 json_object_string_add(json_net
, "nextHop", inet_ntoa (attr
->nexthop
));
6564 else if (p
->family
== AF_INET6
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6568 json_object_string_add(json_net
, "netHopGloabal", inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
6572 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
6573 json_object_int_add(json_net
, "metric", attr
->med
);
6575 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
6576 json_object_int_add(json_net
, "localPref", attr
->local_pref
);
6579 json_object_int_add(json_net
, "weight", attr
->extra
->weight
);
6581 json_object_int_add(json_net
, "weight", 0);
6585 json_object_string_add(json_net
, "asPath", attr
->aspath
->str
);
6588 json_object_string_add(json_net
, "bgpOriginCode", bgp_origin_str
[attr
->origin
]);
6592 if (p
->family
== AF_INET
&&
6593 (safi
== SAFI_MPLS_VPN
||
6594 safi
== SAFI_ENCAP
||
6595 safi
== SAFI_EVPN
||
6596 !BGP_ATTR_NEXTHOP_AFI_IP6(attr
)))
6598 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
)
6599 vty_out (vty
, "%-16s",
6600 inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6602 vty_out (vty
, "%-16s", inet_ntoa (attr
->nexthop
));
6604 else if (p
->family
== AF_INET6
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6609 assert (attr
->extra
);
6611 len
= vty_out (vty
, "%s",
6612 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
6616 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 36, " ");
6618 vty_out (vty
, "%*s", len
, " ");
6620 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
6621 vty_out (vty
, "%10u", attr
->med
);
6625 if (attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
6626 vty_out (vty
, "%7u", attr
->local_pref
);
6630 vty_out (vty
, "%7u ", (attr
->extra
? attr
->extra
->weight
: 0));
6634 aspath_print_vty (vty
, "%s", attr
->aspath
, " ");
6637 vty_out (vty
, "%s", bgp_origin_str
[attr
->origin
]);
6642 json_object_boolean_true_add(json_status
, "*");
6643 json_object_boolean_true_add(json_status
, ">");
6644 json_object_object_add(json_net
, "appliedStatusSymbols", json_status
);
6645 char buf_cut
[BUFSIZ
];
6646 json_object_object_add(json_ar
, inet_ntop (p
->family
, &p
->u
.prefix
, buf_cut
, BUFSIZ
), json_net
);
6649 vty_out (vty
, "%s", VTY_NEWLINE
);
6653 route_vty_out_tag (struct vty
*vty
, struct prefix
*p
,
6654 struct bgp_info
*binfo
, int display
, safi_t safi
, json_object
*json
)
6656 json_object
*json_out
= NULL
;
6658 u_int32_t label
= 0;
6664 json_out
= json_object_new_object();
6666 /* short status lead text */
6667 route_vty_short_status_out (vty
, binfo
, json_out
);
6669 /* print prefix and mask */
6673 route_vty_out_route (p
, vty
);
6675 vty_out (vty
, "%*s", 17, " ");
6678 /* Print attribute */
6682 if (((p
->family
== AF_INET
) && ((safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
)))
6683 || (safi
== SAFI_EVPN
&& p
->family
== AF_ETHERNET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6684 || (!BGP_ATTR_NEXTHOP_AFI_IP6(attr
)))
6686 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
)
6689 json_object_string_add(json_out
, "mpNexthopGlobalIn", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6691 vty_out (vty
, "%-16s", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
6696 json_object_string_add(json_out
, "nexthop", inet_ntoa (attr
->nexthop
));
6698 vty_out (vty
, "%-16s", inet_ntoa (attr
->nexthop
));
6701 else if (((p
->family
== AF_INET6
) && ((safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
)))
6702 || (safi
== SAFI_EVPN
&& p
->family
== AF_ETHERNET
&& BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
6703 || (BGP_ATTR_NEXTHOP_AFI_IP6(attr
)))
6705 assert (attr
->extra
);
6709 if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
)
6712 json_object_string_add(json_out
, "mpNexthopGlobalIn",
6713 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
, buf_a
, BUFSIZ
));
6716 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
6719 else if (attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
6723 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
6725 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
6727 sprintf(buf_c
, "%s(%s)", buf_a
, buf_b
);
6728 json_object_string_add(json_out
, "mpNexthopGlobalLocal", buf_c
);
6731 vty_out (vty
, "%s(%s)",
6732 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
6734 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
6741 label
= decode_label (binfo
->extra
->tag
);
6746 json_object_int_add(json_out
, "notag", label
);
6747 json_object_array_add(json
, json_out
);
6751 vty_out (vty
, "notag/%d", label
);
6753 vty_out (vty
, "%s", VTY_NEWLINE
);
6758 route_vty_out_overlay (struct vty
*vty
, struct prefix
*p
,
6759 struct bgp_info
*binfo
, int display
, json_object
*json_paths
)
6763 json_object
*json_path
= NULL
;
6766 json_path
= json_object_new_object();
6771 /* short status lead text */
6772 route_vty_short_status_out (vty
, binfo
, json_path
);
6774 /* print prefix and mask */
6776 route_vty_out_route (p
, vty
);
6778 vty_out (vty
, "%*s", 17, " ");
6780 /* Print attribute */
6787 int af
= NEXTHOP_FAMILY(attr
->extra
->mp_nexthop_len
);
6791 vty_out (vty
, "%-16s", inet_ntop(af
,
6792 &attr
->extra
->mp_nexthop_global_in
, buf
, BUFSIZ
));
6795 vty_out (vty
, "%s(%s)",
6797 &attr
->extra
->mp_nexthop_global
, buf
, BUFSIZ
),
6799 &attr
->extra
->mp_nexthop_local
, buf1
, BUFSIZ
));
6811 struct eth_segment_id
*id
= &(attr
->extra
->evpn_overlay
.eth_s_id
);
6812 char *str
= esi2str(id
);
6813 vty_out (vty
, "%s", str
);
6814 XFREE (MTYPE_TMP
, str
);
6815 if (p
->u
.prefix_evpn
.flags
& IP_PREFIX_V4
)
6817 vty_out (vty
, "/%s", inet_ntoa (attr
->extra
->evpn_overlay
.gw_ip
.ipv4
));
6819 else if (p
->u
.prefix_evpn
.flags
& IP_PREFIX_V6
)
6821 vty_out (vty
, "/%s",
6822 inet_ntop (AF_INET6
, &(attr
->extra
->evpn_overlay
.gw_ip
.ipv6
),
6825 if(attr
->extra
->ecommunity
)
6828 struct ecommunity_val
*routermac
= ecommunity_lookup (attr
->extra
->ecommunity
,
6829 ECOMMUNITY_ENCODE_EVPN
,
6830 ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC
);
6832 mac
= ecom_mac2str((char *)routermac
->val
);
6835 vty_out (vty
, "/%s",(char *)mac
);
6836 XFREE(MTYPE_TMP
, mac
);
6840 vty_out (vty
, "%s", VTY_NEWLINE
);
6843 /* dampening route */
6845 damp_route_vty_out (struct vty
*vty
, struct prefix
*p
, struct bgp_info
*binfo
,
6846 int display
, safi_t safi
, u_char use_json
, json_object
*json
)
6850 char timebuf
[BGP_UPTIME_LEN
];
6852 /* short status lead text */
6853 route_vty_short_status_out (vty
, binfo
, json
);
6855 /* print prefix and mask */
6859 route_vty_out_route (p
, vty
);
6861 vty_out (vty
, "%*s", 17, " ");
6864 len
= vty_out (vty
, "%s", binfo
->peer
->host
);
6869 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 34, " ");
6874 json_object_int_add(json
, "peerHost", len
);
6876 vty_out (vty
, "%*s", len
, " ");
6880 bgp_damp_reuse_time_vty (vty
, binfo
, timebuf
, BGP_UPTIME_LEN
, use_json
, json
);
6882 vty_out (vty
, "%s ", bgp_damp_reuse_time_vty (vty
, binfo
, timebuf
, BGP_UPTIME_LEN
, use_json
, json
));
6884 /* Print attribute */
6892 json_object_string_add(json
, "asPath", attr
->aspath
->str
);
6894 aspath_print_vty (vty
, "%s", attr
->aspath
, " ");
6899 json_object_string_add(json
, "origin", bgp_origin_str
[attr
->origin
]);
6901 vty_out (vty
, "%s", bgp_origin_str
[attr
->origin
]);
6904 vty_out (vty
, "%s", VTY_NEWLINE
);
6909 flap_route_vty_out (struct vty
*vty
, struct prefix
*p
, struct bgp_info
*binfo
,
6910 int display
, safi_t safi
, u_char use_json
, json_object
*json
)
6913 struct bgp_damp_info
*bdi
;
6914 char timebuf
[BGP_UPTIME_LEN
];
6920 bdi
= binfo
->extra
->damp_info
;
6922 /* short status lead text */
6923 route_vty_short_status_out (vty
, binfo
, json
);
6925 /* print prefix and mask */
6929 route_vty_out_route (p
, vty
);
6931 vty_out (vty
, "%*s", 17, " ");
6934 len
= vty_out (vty
, "%s", binfo
->peer
->host
);
6939 vty_out (vty
, "%s%*s", VTY_NEWLINE
, 33, " ");
6944 json_object_int_add(json
, "peerHost", len
);
6946 vty_out (vty
, "%*s", len
, " ");
6949 len
= vty_out (vty
, "%d", bdi
->flap
);
6959 json_object_int_add(json
, "bdiFlap", len
);
6961 vty_out (vty
, "%*s", len
, " ");
6965 peer_uptime (bdi
->start_time
, timebuf
, BGP_UPTIME_LEN
, use_json
, json
);
6967 vty_out (vty
, "%s ", peer_uptime (bdi
->start_time
,
6968 timebuf
, BGP_UPTIME_LEN
, 0, NULL
));
6970 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_DAMPED
)
6971 && ! CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
6974 bgp_damp_reuse_time_vty (vty
, binfo
, timebuf
, BGP_UPTIME_LEN
, use_json
, json
);
6976 vty_out (vty
, "%s ", bgp_damp_reuse_time_vty (vty
, binfo
, timebuf
, BGP_UPTIME_LEN
, use_json
, json
));
6981 vty_out (vty
, "%*s ", 8, " ");
6984 /* Print attribute */
6992 json_object_string_add(json
, "asPath", attr
->aspath
->str
);
6994 aspath_print_vty (vty
, "%s", attr
->aspath
, " ");
6999 json_object_string_add(json
, "origin", bgp_origin_str
[attr
->origin
]);
7001 vty_out (vty
, "%s", bgp_origin_str
[attr
->origin
]);
7004 vty_out (vty
, "%s", VTY_NEWLINE
);
7008 route_vty_out_advertised_to (struct vty
*vty
, struct peer
*peer
, int *first
,
7009 const char *header
, json_object
*json_adv_to
)
7011 char buf1
[INET6_ADDRSTRLEN
];
7012 json_object
*json_peer
= NULL
;
7016 /* 'advertised-to' is a dictionary of peers we have advertised this
7017 * prefix too. The key is the peer's IP or swpX, the value is the
7018 * hostname if we know it and "" if not.
7020 json_peer
= json_object_new_object();
7023 json_object_string_add(json_peer
, "hostname", peer
->hostname
);
7026 json_object_object_add(json_adv_to
, peer
->conf_if
, json_peer
);
7028 json_object_object_add(json_adv_to
,
7029 sockunion2str (&peer
->su
, buf1
, SU_ADDRSTRLEN
),
7036 vty_out (vty
, "%s", header
);
7040 if (peer
->hostname
&& bgp_flag_check(peer
->bgp
, BGP_FLAG_SHOW_HOSTNAME
))
7043 vty_out (vty
, " %s(%s)", peer
->hostname
, peer
->conf_if
);
7045 vty_out (vty
, " %s(%s)", peer
->hostname
,
7046 sockunion2str (&peer
->su
, buf1
, SU_ADDRSTRLEN
));
7051 vty_out (vty
, " %s", peer
->conf_if
);
7053 vty_out (vty
, " %s", sockunion2str (&peer
->su
, buf1
, SU_ADDRSTRLEN
));
7059 route_vty_out_detail (struct vty
*vty
, struct bgp
*bgp
, struct prefix
*p
,
7060 struct bgp_info
*binfo
, afi_t afi
, safi_t safi
,
7061 json_object
*json_paths
)
7063 char buf
[INET6_ADDRSTRLEN
];
7066 int sockunion_vty_out (struct vty
*, union sockunion
*);
7068 json_object
*json_bestpath
= NULL
;
7069 json_object
*json_cluster_list
= NULL
;
7070 json_object
*json_cluster_list_list
= NULL
;
7071 json_object
*json_ext_community
= NULL
;
7072 json_object
*json_last_update
= NULL
;
7073 json_object
*json_nexthop_global
= NULL
;
7074 json_object
*json_nexthop_ll
= NULL
;
7075 json_object
*json_nexthops
= NULL
;
7076 json_object
*json_path
= NULL
;
7077 json_object
*json_peer
= NULL
;
7078 json_object
*json_string
= NULL
;
7079 json_object
*json_adv_to
= NULL
;
7081 struct listnode
*node
, *nnode
;
7083 int addpath_capable
;
7085 unsigned int first_as
;
7089 json_path
= json_object_new_object();
7090 json_peer
= json_object_new_object();
7091 json_nexthop_global
= json_object_new_object();
7098 /* Line1 display AS-path, Aggregator */
7103 json_object_lock(attr
->aspath
->json
);
7104 json_object_object_add(json_path
, "aspath", attr
->aspath
->json
);
7108 if (attr
->aspath
->segments
)
7109 aspath_print_vty (vty
, " %s", attr
->aspath
, "");
7111 vty_out (vty
, " Local");
7115 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_REMOVED
))
7118 json_object_boolean_true_add(json_path
, "removed");
7120 vty_out (vty
, ", (removed)");
7123 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_STALE
))
7126 json_object_boolean_true_add(json_path
, "stale");
7128 vty_out (vty
, ", (stale)");
7131 if (CHECK_FLAG (attr
->flag
, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
)))
7135 json_object_int_add(json_path
, "aggregatorAs", attr
->extra
->aggregator_as
);
7136 json_object_string_add(json_path
, "aggregatorId", inet_ntoa (attr
->extra
->aggregator_addr
));
7140 vty_out (vty
, ", (aggregated by %u %s)",
7141 attr
->extra
->aggregator_as
,
7142 inet_ntoa (attr
->extra
->aggregator_addr
));
7146 if (CHECK_FLAG (binfo
->peer
->af_flags
[afi
][safi
], PEER_FLAG_REFLECTOR_CLIENT
))
7149 json_object_boolean_true_add(json_path
, "rxedFromRrClient");
7151 vty_out (vty
, ", (Received from a RR-client)");
7154 if (CHECK_FLAG (binfo
->peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
7157 json_object_boolean_true_add(json_path
, "rxedFromRsClient");
7159 vty_out (vty
, ", (Received from a RS-client)");
7162 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
7165 json_object_boolean_true_add(json_path
, "dampeningHistoryEntry");
7167 vty_out (vty
, ", (history entry)");
7169 else if (CHECK_FLAG (binfo
->flags
, BGP_INFO_DAMPED
))
7172 json_object_boolean_true_add(json_path
, "dampeningSuppressed");
7174 vty_out (vty
, ", (suppressed due to dampening)");
7178 vty_out (vty
, "%s", VTY_NEWLINE
);
7180 /* Line2 display Next-hop, Neighbor, Router-id */
7181 /* Display the nexthop */
7182 if (p
->family
== AF_INET
&&
7183 (safi
== SAFI_MPLS_VPN
||
7184 safi
== SAFI_ENCAP
||
7185 safi
== SAFI_EVPN
||
7186 !BGP_ATTR_NEXTHOP_AFI_IP6(attr
)))
7188 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
)
7191 json_object_string_add(json_nexthop_global
, "ip", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
7193 vty_out (vty
, " %s", inet_ntoa (attr
->extra
->mp_nexthop_global_in
));
7198 json_object_string_add(json_nexthop_global
, "ip", inet_ntoa (attr
->nexthop
));
7200 vty_out (vty
, " %s", inet_ntoa (attr
->nexthop
));
7204 json_object_string_add(json_nexthop_global
, "afi", "ipv4");
7208 assert (attr
->extra
);
7211 json_object_string_add(json_nexthop_global
, "ip",
7212 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
7213 buf
, INET6_ADDRSTRLEN
));
7214 json_object_string_add(json_nexthop_global
, "afi", "ipv6");
7215 json_object_string_add(json_nexthop_global
, "scope", "global");
7219 vty_out (vty
, " %s",
7220 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_global
,
7221 buf
, INET6_ADDRSTRLEN
));
7225 /* Display the IGP cost or 'inaccessible' */
7226 if (! CHECK_FLAG (binfo
->flags
, BGP_INFO_VALID
))
7229 json_object_boolean_false_add(json_nexthop_global
, "accessible");
7231 vty_out (vty
, " (inaccessible)");
7235 if (binfo
->extra
&& binfo
->extra
->igpmetric
)
7238 json_object_int_add(json_nexthop_global
, "metric", binfo
->extra
->igpmetric
);
7240 vty_out (vty
, " (metric %u)", binfo
->extra
->igpmetric
);
7243 /* IGP cost is 0, display this only for json */
7247 json_object_int_add(json_nexthop_global
, "metric", 0);
7251 json_object_boolean_true_add(json_nexthop_global
, "accessible");
7254 /* Display peer "from" output */
7255 /* This path was originated locally */
7256 if (binfo
->peer
== bgp
->peer_self
)
7259 if (p
->family
== AF_INET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
7262 json_object_string_add(json_peer
, "peerId", "0.0.0.0");
7264 vty_out (vty
, " from 0.0.0.0 ");
7269 json_object_string_add(json_peer
, "peerId", "::");
7271 vty_out (vty
, " from :: ");
7275 json_object_string_add(json_peer
, "routerId", inet_ntoa(bgp
->router_id
));
7277 vty_out (vty
, "(%s)", inet_ntoa(bgp
->router_id
));
7280 /* We RXed this path from one of our peers */
7286 json_object_string_add(json_peer
, "peerId", sockunion2str (&binfo
->peer
->su
, buf
, SU_ADDRSTRLEN
));
7287 json_object_string_add(json_peer
, "routerId", inet_ntop (AF_INET
, &binfo
->peer
->remote_id
, buf1
, BUFSIZ
));
7289 if (binfo
->peer
->hostname
)
7290 json_object_string_add(json_peer
, "hostname", binfo
->peer
->hostname
);
7292 if (binfo
->peer
->domainname
)
7293 json_object_string_add(json_peer
, "domainname", binfo
->peer
->domainname
);
7295 if (binfo
->peer
->conf_if
)
7296 json_object_string_add(json_peer
, "interface", binfo
->peer
->conf_if
);
7300 if (binfo
->peer
->conf_if
)
7302 if (binfo
->peer
->hostname
&&
7303 bgp_flag_check(binfo
->peer
->bgp
, BGP_FLAG_SHOW_HOSTNAME
))
7304 vty_out (vty
, " from %s(%s)", binfo
->peer
->hostname
,
7305 binfo
->peer
->conf_if
);
7307 vty_out (vty
, " from %s", binfo
->peer
->conf_if
);
7311 if (binfo
->peer
->hostname
&&
7312 bgp_flag_check(binfo
->peer
->bgp
, BGP_FLAG_SHOW_HOSTNAME
))
7313 vty_out (vty
, " from %s(%s)", binfo
->peer
->hostname
,
7316 vty_out (vty
, " from %s", sockunion2str (&binfo
->peer
->su
, buf
, SU_ADDRSTRLEN
));
7319 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
))
7320 vty_out (vty
, " (%s)", inet_ntoa (attr
->extra
->originator_id
));
7322 vty_out (vty
, " (%s)", inet_ntop (AF_INET
, &binfo
->peer
->remote_id
, buf1
, BUFSIZ
));
7327 vty_out (vty
, "%s", VTY_NEWLINE
);
7329 /* display the link-local nexthop */
7330 if (attr
->extra
&& attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
7334 json_nexthop_ll
= json_object_new_object();
7335 json_object_string_add(json_nexthop_ll
, "ip",
7336 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
7337 buf
, INET6_ADDRSTRLEN
));
7338 json_object_string_add(json_nexthop_ll
, "afi", "ipv6");
7339 json_object_string_add(json_nexthop_ll
, "scope", "link-local");
7341 json_object_boolean_true_add(json_nexthop_ll
, "accessible");
7343 if (!attr
->extra
->mp_nexthop_prefer_global
)
7344 json_object_boolean_true_add(json_nexthop_ll
, "used");
7346 json_object_boolean_true_add(json_nexthop_global
, "used");
7350 vty_out (vty
, " (%s) %s%s",
7351 inet_ntop (AF_INET6
, &attr
->extra
->mp_nexthop_local
,
7352 buf
, INET6_ADDRSTRLEN
),
7353 attr
->extra
->mp_nexthop_prefer_global
?
7354 "(prefer-global)" : "(used)",
7358 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7362 json_object_boolean_true_add(json_nexthop_global
, "used");
7365 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7367 json_object_string_add(json_path
, "origin", bgp_origin_long_str
[attr
->origin
]);
7369 vty_out (vty
, " Origin %s", bgp_origin_long_str
[attr
->origin
]);
7371 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
7374 json_object_int_add(json_path
, "med", attr
->med
);
7376 vty_out (vty
, ", metric %u", attr
->med
);
7379 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
7382 json_object_int_add(json_path
, "localpref", attr
->local_pref
);
7384 vty_out (vty
, ", localpref %u", attr
->local_pref
);
7389 json_object_int_add(json_path
, "localpref", bgp
->default_local_pref
);
7391 vty_out (vty
, ", localpref %u", bgp
->default_local_pref
);
7394 if (attr
->extra
&& attr
->extra
->weight
!= 0)
7397 json_object_int_add(json_path
, "weight", attr
->extra
->weight
);
7399 vty_out (vty
, ", weight %u", attr
->extra
->weight
);
7402 if (attr
->extra
&& attr
->extra
->tag
!= 0)
7405 json_object_int_add(json_path
, "tag", attr
->extra
->tag
);
7407 vty_out (vty
, ", tag %"ROUTE_TAG_PRI
, attr
->extra
->tag
);
7410 if (! CHECK_FLAG (binfo
->flags
, BGP_INFO_VALID
))
7413 json_object_boolean_false_add(json_path
, "valid");
7415 vty_out (vty
, ", invalid");
7417 else if (! CHECK_FLAG (binfo
->flags
, BGP_INFO_HISTORY
))
7420 json_object_boolean_true_add(json_path
, "valid");
7422 vty_out (vty
, ", valid");
7425 if (binfo
->peer
!= bgp
->peer_self
)
7427 if (binfo
->peer
->as
== binfo
->peer
->local_as
)
7429 if (CHECK_FLAG(bgp
->config
, BGP_CONFIG_CONFEDERATION
))
7432 json_object_string_add(json_peer
, "type", "confed-internal");
7434 vty_out (vty
, ", confed-internal");
7439 json_object_string_add(json_peer
, "type", "internal");
7441 vty_out (vty
, ", internal");
7446 if (bgp_confederation_peers_check(bgp
, binfo
->peer
->as
))
7449 json_object_string_add(json_peer
, "type", "confed-external");
7451 vty_out (vty
, ", confed-external");
7456 json_object_string_add(json_peer
, "type", "external");
7458 vty_out (vty
, ", external");
7462 else if (binfo
->sub_type
== BGP_ROUTE_AGGREGATE
)
7466 json_object_boolean_true_add(json_path
, "aggregated");
7467 json_object_boolean_true_add(json_path
, "local");
7471 vty_out (vty
, ", aggregated, local");
7474 else if (binfo
->type
!= ZEBRA_ROUTE_BGP
)
7477 json_object_boolean_true_add(json_path
, "sourced");
7479 vty_out (vty
, ", sourced");
7485 json_object_boolean_true_add(json_path
, "sourced");
7486 json_object_boolean_true_add(json_path
, "local");
7490 vty_out (vty
, ", sourced, local");
7494 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
))
7497 json_object_boolean_true_add(json_path
, "atomicAggregate");
7499 vty_out (vty
, ", atomic-aggregate");
7502 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_MULTIPATH
) ||
7503 (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
) &&
7504 bgp_info_mpath_count (binfo
)))
7507 json_object_boolean_true_add(json_path
, "multipath");
7509 vty_out (vty
, ", multipath");
7512 // Mark the bestpath(s)
7513 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_DMED_SELECTED
))
7515 first_as
= aspath_get_first_as(attr
->aspath
);
7520 json_bestpath
= json_object_new_object();
7521 json_object_int_add(json_bestpath
, "bestpathFromAs", first_as
);
7526 vty_out (vty
, ", bestpath-from-AS %d", first_as
);
7528 vty_out (vty
, ", bestpath-from-AS Local");
7532 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
))
7537 json_bestpath
= json_object_new_object();
7538 json_object_boolean_true_add(json_bestpath
, "overall");
7541 vty_out (vty
, ", best");
7545 json_object_object_add(json_path
, "bestpath", json_bestpath
);
7548 vty_out (vty
, "%s", VTY_NEWLINE
);
7550 /* Line 4 display Community */
7551 if (attr
->community
)
7555 json_object_lock(attr
->community
->json
);
7556 json_object_object_add(json_path
, "community", attr
->community
->json
);
7560 vty_out (vty
, " Community: %s%s", attr
->community
->str
,
7565 /* Line 5 display Extended-community */
7566 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
))
7570 json_ext_community
= json_object_new_object();
7571 json_object_string_add(json_ext_community
, "string", attr
->extra
->ecommunity
->str
);
7572 json_object_object_add(json_path
, "extendedCommunity", json_ext_community
);
7576 vty_out (vty
, " Extended Community: %s%s",
7577 attr
->extra
->ecommunity
->str
, VTY_NEWLINE
);
7581 /* Line 6 display Large community */
7582 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
))
7583 vty_out (vty
, " Large Community: %s%s",
7584 attr
->extra
->lcommunity
->str
, VTY_NEWLINE
);
7586 /* Line 7 display Originator, Cluster-id */
7587 if ((attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
)) ||
7588 (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
)))
7590 assert (attr
->extra
);
7591 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
))
7594 json_object_string_add(json_path
, "originatorId", inet_ntoa (attr
->extra
->originator_id
));
7596 vty_out (vty
, " Originator: %s",
7597 inet_ntoa (attr
->extra
->originator_id
));
7600 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST
))
7606 json_cluster_list
= json_object_new_object();
7607 json_cluster_list_list
= json_object_new_array();
7609 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
7611 json_string
= json_object_new_string(inet_ntoa (attr
->extra
->cluster
->list
[i
]));
7612 json_object_array_add(json_cluster_list_list
, json_string
);
7615 /* struct cluster_list does not have "str" variable like
7616 * aspath and community do. Add this someday if someone
7618 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7620 json_object_object_add(json_cluster_list
, "list", json_cluster_list_list
);
7621 json_object_object_add(json_path
, "clusterList", json_cluster_list
);
7625 vty_out (vty
, ", Cluster list: ");
7627 for (i
= 0; i
< attr
->extra
->cluster
->length
/ 4; i
++)
7629 vty_out (vty
, "%s ",
7630 inet_ntoa (attr
->extra
->cluster
->list
[i
]));
7636 vty_out (vty
, "%s", VTY_NEWLINE
);
7639 if (binfo
->extra
&& binfo
->extra
->damp_info
)
7640 bgp_damp_info_vty (vty
, binfo
, json_path
);
7643 if (bgp_labeled_safi(safi
) && binfo
->extra
)
7645 uint32_t label
= label_pton(binfo
->extra
->tag
);
7647 json_object_int_add(json_path
, "remoteLabel", label
);
7649 vty_out(vty
, " Remote label: %d%s", label
, VTY_NEWLINE
);
7653 if (attr
->extra
->label_index
!= BGP_INVALID_LABEL_INDEX
)
7656 json_object_int_add(json_path
, "labelIndex", attr
->extra
->label_index
);
7658 vty_out(vty
, " Label Index: %d%s", attr
->extra
->label_index
, VTY_NEWLINE
);
7661 /* Line 8 display Addpath IDs */
7662 if (binfo
->addpath_rx_id
|| binfo
->addpath_tx_id
)
7666 json_object_int_add(json_path
, "addpathRxId", binfo
->addpath_rx_id
);
7667 json_object_int_add(json_path
, "addpathTxId", binfo
->addpath_tx_id
);
7671 vty_out (vty
, " AddPath ID: RX %u, TX %u%s",
7672 binfo
->addpath_rx_id
, binfo
->addpath_tx_id
,
7677 /* If we used addpath to TX a non-bestpath we need to display
7678 * "Advertised to" on a path-by-path basis */
7679 if (bgp
->addpath_tx_used
[afi
][safi
])
7683 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
7685 addpath_capable
= bgp_addpath_encode_tx (peer
, afi
, safi
);
7686 has_adj
= bgp_adj_out_lookup (peer
, binfo
->net
, binfo
->addpath_tx_id
);
7688 if ((addpath_capable
&& has_adj
) ||
7689 (!addpath_capable
&& has_adj
&& CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
)))
7691 if (json_path
&& !json_adv_to
)
7692 json_adv_to
= json_object_new_object();
7694 route_vty_out_advertised_to(vty
, peer
, &first
,
7704 json_object_object_add(json_path
, "advertisedTo", json_adv_to
);
7711 vty_out (vty
, "%s", VTY_NEWLINE
);
7716 /* Line 9 display Uptime */
7717 tbuf
= time(NULL
) - (bgp_clock() - binfo
->uptime
);
7720 json_last_update
= json_object_new_object();
7721 json_object_int_add(json_last_update
, "epoch", tbuf
);
7722 json_object_string_add(json_last_update
, "string", ctime(&tbuf
));
7723 json_object_object_add(json_path
, "lastUpdate", json_last_update
);
7726 vty_out (vty
, " Last update: %s", ctime(&tbuf
));
7729 /* We've constructed the json object for this path, add it to the json
7734 if (json_nexthop_global
|| json_nexthop_ll
)
7736 json_nexthops
= json_object_new_array();
7738 if (json_nexthop_global
)
7739 json_object_array_add(json_nexthops
, json_nexthop_global
);
7741 if (json_nexthop_ll
)
7742 json_object_array_add(json_nexthops
, json_nexthop_ll
);
7744 json_object_object_add(json_path
, "nexthops", json_nexthops
);
7747 json_object_object_add(json_path
, "peer", json_peer
);
7748 json_object_array_add(json_paths
, json_path
);
7751 vty_out (vty
, "%s", VTY_NEWLINE
);
7754 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7755 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7756 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7759 bgp_show_prefix_list (struct vty
*vty
, struct bgp
*bgp
,
7760 const char *prefix_list_str
, afi_t afi
,
7761 safi_t safi
, enum bgp_show_type type
);
7763 bgp_show_filter_list (struct vty
*vty
, struct bgp
*bgp
,
7764 const char *filter
, afi_t afi
,
7765 safi_t safi
, enum bgp_show_type type
);
7767 bgp_show_route_map (struct vty
*vty
, struct bgp
*bgp
,
7768 const char *rmap_str
, afi_t afi
,
7769 safi_t safi
, enum bgp_show_type type
);
7771 bgp_show_community_list (struct vty
*vty
, struct bgp
*bgp
,
7772 const char *com
, int exact
,
7773 afi_t afi
, safi_t safi
);
7775 bgp_show_prefix_longer (struct vty
*vty
, struct bgp
*bgp
,
7776 const char *prefix
, afi_t afi
,
7777 safi_t safi
, enum bgp_show_type type
);
7779 bgp_show_regexp (struct vty
*vty
, const char *regstr
, afi_t afi
,
7780 safi_t safi
, enum bgp_show_type type
);
7782 bgp_show_community (struct vty
*vty
, struct bgp
*bgp
, int argc
,
7783 struct cmd_token
**argv
, int exact
, afi_t afi
, safi_t safi
);
7786 bgp_show_table (struct vty
*vty
, struct bgp
*bgp
, struct bgp_table
*table
,
7787 enum bgp_show_type type
, void *output_arg
, u_char use_json
)
7789 struct bgp_info
*ri
;
7790 struct bgp_node
*rn
;
7793 unsigned long output_count
;
7794 unsigned long total_count
;
7798 json_object
*json_paths
= NULL
;
7803 vty_out (vty
, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64
", \"routerId\": \"%s\", \"routes\": { ",
7804 bgp
->vrf_id
== VRF_UNKNOWN
? -1 : bgp
->vrf_id
,
7805 bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
? "Default" : bgp
->name
,
7806 table
->version
, inet_ntoa (bgp
->router_id
));
7807 json_paths
= json_object_new_object();
7810 /* This is first entry point, so reset total line. */
7814 /* Start processing of routes. */
7815 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
7816 if (rn
->info
!= NULL
)
7819 if (!first
&& use_json
)
7824 json_paths
= json_object_new_array();
7828 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
7831 if (type
== bgp_show_type_flap_statistics
7832 || type
== bgp_show_type_flap_neighbor
7833 || type
== bgp_show_type_dampend_paths
7834 || type
== bgp_show_type_damp_neighbor
)
7836 if (!(ri
->extra
&& ri
->extra
->damp_info
))
7839 if (type
== bgp_show_type_regexp
)
7841 regex_t
*regex
= output_arg
;
7843 if (bgp_regexec (regex
, ri
->attr
->aspath
) == REG_NOMATCH
)
7846 if (type
== bgp_show_type_prefix_list
)
7848 struct prefix_list
*plist
= output_arg
;
7850 if (prefix_list_apply (plist
, &rn
->p
) != PREFIX_PERMIT
)
7853 if (type
== bgp_show_type_filter_list
)
7855 struct as_list
*as_list
= output_arg
;
7857 if (as_list_apply (as_list
, ri
->attr
->aspath
) != AS_FILTER_PERMIT
)
7860 if (type
== bgp_show_type_route_map
)
7862 struct route_map
*rmap
= output_arg
;
7863 struct bgp_info binfo
;
7864 struct attr dummy_attr
;
7865 struct attr_extra dummy_extra
;
7868 dummy_attr
.extra
= &dummy_extra
;
7869 bgp_attr_dup (&dummy_attr
, ri
->attr
);
7871 binfo
.peer
= ri
->peer
;
7872 binfo
.attr
= &dummy_attr
;
7874 ret
= route_map_apply (rmap
, &rn
->p
, RMAP_BGP
, &binfo
);
7875 if (ret
== RMAP_DENYMATCH
)
7878 if (type
== bgp_show_type_neighbor
7879 || type
== bgp_show_type_flap_neighbor
7880 || type
== bgp_show_type_damp_neighbor
)
7882 union sockunion
*su
= output_arg
;
7884 if (ri
->peer
== NULL
||
7885 ri
->peer
->su_remote
== NULL
|| ! sockunion_same(ri
->peer
->su_remote
, su
))
7888 if (type
== bgp_show_type_cidr_only
)
7890 u_int32_t destination
;
7892 destination
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
7893 if (IN_CLASSC (destination
) && rn
->p
.prefixlen
== 24)
7895 if (IN_CLASSB (destination
) && rn
->p
.prefixlen
== 16)
7897 if (IN_CLASSA (destination
) && rn
->p
.prefixlen
== 8)
7900 if (type
== bgp_show_type_prefix_longer
)
7902 struct prefix
*p
= output_arg
;
7904 if (! prefix_match (p
, &rn
->p
))
7907 if (type
== bgp_show_type_community_all
)
7909 if (! ri
->attr
->community
)
7912 if (type
== bgp_show_type_community
)
7914 struct community
*com
= output_arg
;
7916 if (! ri
->attr
->community
||
7917 ! community_match (ri
->attr
->community
, com
))
7920 if (type
== bgp_show_type_community_exact
)
7922 struct community
*com
= output_arg
;
7924 if (! ri
->attr
->community
||
7925 ! community_cmp (ri
->attr
->community
, com
))
7928 if (type
== bgp_show_type_community_list
)
7930 struct community_list
*list
= output_arg
;
7932 if (! community_list_match (ri
->attr
->community
, list
))
7935 if (type
== bgp_show_type_community_list_exact
)
7937 struct community_list
*list
= output_arg
;
7939 if (! community_list_exact_match (ri
->attr
->community
, list
))
7942 if (type
== bgp_show_type_lcommunity
)
7944 struct lcommunity
*lcom
= output_arg
;
7946 if (! ri
->attr
->extra
|| ! ri
->attr
->extra
->lcommunity
||
7947 ! lcommunity_match (ri
->attr
->extra
->lcommunity
, lcom
))
7950 if (type
== bgp_show_type_lcommunity_list
)
7952 struct community_list
*list
= output_arg
;
7954 if (! ri
->attr
->extra
||
7955 ! lcommunity_list_match (ri
->attr
->extra
->lcommunity
, list
))
7958 if (type
== bgp_show_type_lcommunity_all
)
7960 if (! ri
->attr
->extra
|| ! ri
->attr
->extra
->lcommunity
)
7963 if (type
== bgp_show_type_dampend_paths
7964 || type
== bgp_show_type_damp_neighbor
)
7966 if (! CHECK_FLAG (ri
->flags
, BGP_INFO_DAMPED
)
7967 || CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
7971 if (!use_json
&& header
)
7973 vty_out (vty
, "BGP table version is %" PRIu64
", local router ID is %s%s", table
->version
, inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
7974 vty_out (vty
, BGP_SHOW_SCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
7975 vty_out (vty
, BGP_SHOW_OCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
7976 if (type
== bgp_show_type_dampend_paths
7977 || type
== bgp_show_type_damp_neighbor
)
7978 vty_out (vty
, BGP_SHOW_DAMP_HEADER
, VTY_NEWLINE
);
7979 else if (type
== bgp_show_type_flap_statistics
7980 || type
== bgp_show_type_flap_neighbor
)
7981 vty_out (vty
, BGP_SHOW_FLAP_HEADER
, VTY_NEWLINE
);
7983 vty_out (vty
, BGP_SHOW_HEADER
, VTY_NEWLINE
);
7987 if (type
== bgp_show_type_dampend_paths
7988 || type
== bgp_show_type_damp_neighbor
)
7989 damp_route_vty_out (vty
, &rn
->p
, ri
, display
, SAFI_UNICAST
, use_json
, json_paths
);
7990 else if (type
== bgp_show_type_flap_statistics
7991 || type
== bgp_show_type_flap_neighbor
)
7992 flap_route_vty_out (vty
, &rn
->p
, ri
, display
, SAFI_UNICAST
, use_json
, json_paths
);
7994 route_vty_out (vty
, &rn
->p
, ri
, display
, SAFI_UNICAST
, json_paths
);
8004 sprintf(buf2
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
), p
->prefixlen
);
8005 vty_out (vty
, "\"%s\": ", buf2
);
8006 vty_out (vty
, "%s", json_object_to_json_string (json_paths
));
8007 json_object_free (json_paths
);
8016 json_object_free (json_paths
);
8017 vty_out (vty
, " } }%s", VTY_NEWLINE
);
8021 /* No route is displayed */
8022 if (output_count
== 0)
8024 if (type
== bgp_show_type_normal
)
8025 vty_out (vty
, "No BGP prefixes displayed, %ld exist%s", total_count
, VTY_NEWLINE
);
8028 vty_out (vty
, "%sDisplayed %ld routes and %ld total paths%s",
8029 VTY_NEWLINE
, output_count
, total_count
, VTY_NEWLINE
);
8036 bgp_show (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
, safi_t safi
,
8037 enum bgp_show_type type
, void *output_arg
, u_char use_json
)
8039 struct bgp_table
*table
;
8043 bgp
= bgp_get_default ();
8049 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
8052 /* use MPLS and ENCAP specific shows until they are merged */
8053 if (safi
== SAFI_MPLS_VPN
)
8055 return bgp_show_mpls_vpn(vty
, afi
, NULL
, type
, output_arg
,
8058 if (safi
== SAFI_ENCAP
)
8060 return bgp_show_encap(vty
, afi
, NULL
, type
, output_arg
,
8065 table
= bgp
->rib
[afi
][safi
];
8067 return bgp_show_table (vty
, bgp
, table
, type
, output_arg
,
8072 bgp_show_all_instances_routes_vty (struct vty
*vty
, afi_t afi
, safi_t safi
,
8075 struct listnode
*node
, *nnode
;
8077 struct bgp_table
*table
;
8081 vty_out (vty
, "{%s", VTY_NEWLINE
);
8083 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
8088 vty_out (vty
, ",%s", VTY_NEWLINE
);
8092 vty_out(vty
, "\"%s\":", (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
8093 ? "Default" : bgp
->name
);
8097 vty_out (vty
, "%sInstance %s:%s",
8099 (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
8100 ? "Default" : bgp
->name
,
8103 table
= bgp
->rib
[afi
][safi
];
8104 bgp_show_table (vty
, bgp
, table
,
8105 bgp_show_type_normal
, NULL
, use_json
);
8110 vty_out (vty
, "}%s", VTY_NEWLINE
);
8113 /* Header of detailed BGP route information */
8115 route_vty_out_detail_header (struct vty
*vty
, struct bgp
*bgp
,
8116 struct bgp_node
*rn
,
8117 struct prefix_rd
*prd
, afi_t afi
, safi_t safi
,
8120 struct bgp_info
*ri
;
8123 struct listnode
*node
, *nnode
;
8124 char buf1
[INET6_ADDRSTRLEN
];
8125 char buf2
[INET6_ADDRSTRLEN
];
8130 int no_advertise
= 0;
8133 json_object
*json_adv_to
= NULL
;
8139 json_object_string_add(json
, "prefix", inet_ntop (p
->family
, &p
->u
.prefix
, buf2
, INET6_ADDRSTRLEN
));
8140 json_object_int_add(json
, "prefixlen", p
->prefixlen
);
8144 if (p
->family
== AF_ETHERNET
)
8145 prefix2str (p
, buf2
, INET6_ADDRSTRLEN
);
8147 inet_ntop (p
->family
, &p
->u
.prefix
, buf2
, INET6_ADDRSTRLEN
);
8148 vty_out (vty
, "BGP routing table entry for %s%s%s/%d%s",
8149 ((safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
) ?
8150 prefix_rd2str (prd
, buf1
, RD_ADDRSTRLEN
) : ""),
8151 ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_EVPN
)) ? ":" : "",
8153 p
->prefixlen
, VTY_NEWLINE
);
8155 if (bgp_labeled_safi(safi
))
8157 vty_out(vty
, "Local label: ");
8158 if (!bgp_is_valid_label(rn
->local_label
))
8159 vty_out(vty
, "not allocated%s", VTY_NEWLINE
);
8162 uint32_t label
= label_pton(rn
->local_label
);
8163 vty_out(vty
, "%d%s", label
, VTY_NEWLINE
);
8168 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
8171 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))
8174 if (ri
->extra
&& ri
->extra
->suppress
)
8176 if (ri
->attr
->community
!= NULL
)
8178 if (community_include (ri
->attr
->community
, COMMUNITY_NO_ADVERTISE
))
8180 if (community_include (ri
->attr
->community
, COMMUNITY_NO_EXPORT
))
8182 if (community_include (ri
->attr
->community
, COMMUNITY_LOCAL_AS
))
8190 vty_out (vty
, "Paths: (%d available", count
);
8193 vty_out (vty
, ", best #%d", best
);
8194 if (safi
== SAFI_UNICAST
)
8195 vty_out (vty
, ", table %s",
8196 (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
8197 ? "Default-IP-Routing-Table" : bgp
->name
);
8200 vty_out (vty
, ", no best path");
8203 vty_out (vty
, ", not advertised to any peer");
8205 vty_out (vty
, ", not advertised to EBGP peer");
8207 vty_out (vty
, ", not advertised outside local AS");
8210 vty_out (vty
, ", Advertisements suppressed by an aggregate.");
8211 vty_out (vty
, ")%s", VTY_NEWLINE
);
8214 /* If we are not using addpath then we can display Advertised to and that will
8215 * show what peers we advertised the bestpath to. If we are using addpath
8216 * though then we must display Advertised to on a path-by-path basis. */
8217 if (!bgp
->addpath_tx_used
[afi
][safi
])
8219 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
8221 if (bgp_adj_out_lookup (peer
, rn
, 0))
8223 if (json
&& !json_adv_to
)
8224 json_adv_to
= json_object_new_object();
8226 route_vty_out_advertised_to(vty
, peer
, &first
,
8227 " Advertised to non peer-group peers:\n ",
8236 json_object_object_add(json
, "advertisedTo", json_adv_to
);
8242 vty_out (vty
, " Not advertised to any peer");
8243 vty_out (vty
, "%s", VTY_NEWLINE
);
8248 /* Display specified route of BGP table. */
8250 bgp_show_route_in_table (struct vty
*vty
, struct bgp
*bgp
,
8251 struct bgp_table
*rib
, const char *ip_str
,
8252 afi_t afi
, safi_t safi
, struct prefix_rd
*prd
,
8253 int prefix_check
, enum bgp_path_type pathtype
,
8259 struct prefix match
;
8260 struct bgp_node
*rn
;
8261 struct bgp_node
*rm
;
8262 struct bgp_info
*ri
;
8263 struct bgp_table
*table
;
8264 json_object
*json
= NULL
;
8265 json_object
*json_paths
= NULL
;
8267 /* Check IP address argument. */
8268 ret
= str2prefix (ip_str
, &match
);
8271 vty_out (vty
, "address is malformed%s", VTY_NEWLINE
);
8275 match
.family
= afi2family (afi
);
8279 json
= json_object_new_object();
8280 json_paths
= json_object_new_array();
8283 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
|| safi
== SAFI_EVPN
)
8285 for (rn
= bgp_table_top (rib
); rn
; rn
= bgp_route_next (rn
))
8287 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
8290 if ((table
= rn
->info
) != NULL
)
8294 if ((rm
= bgp_node_match (table
, &match
)) != NULL
)
8296 if (prefix_check
&& rm
->p
.prefixlen
!= match
.prefixlen
)
8298 bgp_unlock_node (rm
);
8302 for (ri
= rm
->info
; ri
; ri
= ri
->next
)
8306 route_vty_out_detail_header (vty
, bgp
, rm
, (struct prefix_rd
*)&rn
->p
,
8307 AFI_IP
, safi
, json
);
8312 if (pathtype
== BGP_PATH_ALL
||
8313 (pathtype
== BGP_PATH_BESTPATH
&& CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)) ||
8314 (pathtype
== BGP_PATH_MULTIPATH
&&
8315 (CHECK_FLAG (ri
->flags
, BGP_INFO_MULTIPATH
) || CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))))
8316 route_vty_out_detail (vty
, bgp
, &rm
->p
, ri
, AFI_IP
, safi
, json_paths
);
8319 bgp_unlock_node (rm
);
8328 if ((rn
= bgp_node_match (rib
, &match
)) != NULL
)
8330 if (! prefix_check
|| rn
->p
.prefixlen
== match
.prefixlen
)
8332 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
8336 route_vty_out_detail_header (vty
, bgp
, rn
, NULL
, afi
, safi
, json
);
8341 if (pathtype
== BGP_PATH_ALL
||
8342 (pathtype
== BGP_PATH_BESTPATH
&& CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)) ||
8343 (pathtype
== BGP_PATH_MULTIPATH
&&
8344 (CHECK_FLAG (ri
->flags
, BGP_INFO_MULTIPATH
) || CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
))))
8345 route_vty_out_detail (vty
, bgp
, &rn
->p
, ri
, afi
, safi
, json_paths
);
8349 bgp_unlock_node (rn
);
8356 json_object_object_add(json
, "paths", json_paths
);
8358 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
8359 json_object_free(json
);
8365 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
8373 /* Display specified route of Main RIB */
8375 bgp_show_route (struct vty
*vty
, struct bgp
*bgp
, const char *ip_str
,
8376 afi_t afi
, safi_t safi
, struct prefix_rd
*prd
,
8377 int prefix_check
, enum bgp_path_type pathtype
,
8381 bgp
= bgp_get_default ();
8383 return bgp_show_route_in_table (vty
, bgp
, bgp
->rib
[afi
][safi
], ip_str
,
8384 afi
, safi
, prd
, prefix_check
, pathtype
,
8389 bgp_show_lcommunity (struct vty
*vty
, struct bgp
*bgp
, int argc
,
8390 struct cmd_token
**argv
, afi_t afi
, safi_t safi
, u_char uj
)
8392 struct lcommunity
*lcom
;
8398 b
= buffer_new (1024);
8399 for (i
= 0; i
< argc
; i
++)
8402 buffer_putc (b
, ' ');
8405 if (strmatch (argv
[i
]->text
, "AA:BB:CC"))
8408 buffer_putstr (b
, argv
[i
]->arg
);
8412 buffer_putc (b
, '\0');
8414 str
= buffer_getstr (b
);
8417 lcom
= lcommunity_str2com (str
);
8418 XFREE (MTYPE_TMP
, str
);
8421 vty_out (vty
, "%% Large-community malformed%s", VTY_NEWLINE
);
8425 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_lcommunity
, lcom
, uj
);
8429 bgp_show_lcommunity_list (struct vty
*vty
, struct bgp
*bgp
, const char *lcom
,
8430 afi_t afi
, safi_t safi
, u_char uj
)
8432 struct community_list
*list
;
8434 list
= community_list_lookup (bgp_clist
, lcom
, LARGE_COMMUNITY_LIST_MASTER
);
8437 vty_out (vty
, "%% %s is not a valid large-community-list name%s", lcom
,
8442 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_lcommunity_list
, list
, uj
);
8445 DEFUN (show_ip_bgp_large_community_list
,
8446 show_ip_bgp_large_community_list_cmd
,
8447 "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] large-community-list <(1-500)|WORD> [json]",
8451 BGP_INSTANCE_HELP_STR
8454 "Address Family modifier\n"
8455 "Address Family modifier\n"
8456 "Address Family modifier\n"
8457 "Address Family modifier\n"
8458 "Address Family modifier\n"
8459 "Display routes matching the large-community-list\n"
8460 "large-community-list number\n"
8461 "large-community-list name\n"
8465 afi_t afi
= AFI_IP6
;
8466 safi_t safi
= SAFI_UNICAST
;
8469 if (argv_find (argv
, argc
, "ip", &idx
))
8471 if (argv_find (argv
, argc
, "view", &idx
) || argv_find (argv
, argc
, "vrf", &idx
))
8472 vrf
= argv
[++idx
]->arg
;
8473 if (argv_find (argv
, argc
, "ipv4", &idx
) || argv_find (argv
, argc
, "ipv6", &idx
))
8475 afi
= strmatch(argv
[idx
]->text
, "ipv6") ? AFI_IP6
: AFI_IP
;
8476 if (argv_find (argv
, argc
, "unicast", &idx
) || argv_find (argv
, argc
, "multicast", &idx
))
8477 safi
= bgp_vty_safi_from_arg (argv
[idx
]->text
);
8480 int uj
= use_json (argc
, argv
);
8482 struct bgp
*bgp
= bgp_lookup_by_name (vrf
);
8485 vty_out (vty
, "Can't find BGP instance %s%s", vrf
, VTY_NEWLINE
);
8489 argv_find (argv
, argc
, "large-community-list", &idx
);
8490 return bgp_show_lcommunity_list (vty
, bgp
, argv
[idx
+1]->arg
, afi
, safi
, uj
);
8492 DEFUN (show_ip_bgp_large_community
,
8493 show_ip_bgp_large_community_cmd
,
8494 "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] large-community [AA:BB:CC] [json]",
8498 BGP_INSTANCE_HELP_STR
8501 "Address Family modifier\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
8504 "Address Family modifier\n"
8505 "Address Family modifier\n"
8506 "Display routes matching the large-communities\n"
8507 "List of large-community numbers\n"
8511 afi_t afi
= AFI_IP6
;
8512 safi_t safi
= SAFI_UNICAST
;
8515 if (argv_find (argv
, argc
, "ip", &idx
))
8517 if (argv_find (argv
, argc
, "view", &idx
) || argv_find (argv
, argc
, "vrf", &idx
))
8518 vrf
= argv
[++idx
]->arg
;
8519 if (argv_find (argv
, argc
, "ipv4", &idx
) || argv_find (argv
, argc
, "ipv6", &idx
))
8521 afi
= strmatch(argv
[idx
]->text
, "ipv6") ? AFI_IP6
: AFI_IP
;
8522 if (argv_find (argv
, argc
, "unicast", &idx
) || argv_find (argv
, argc
, "multicast", &idx
))
8523 safi
= bgp_vty_safi_from_arg (argv
[idx
]->text
);
8526 int uj
= use_json (argc
, argv
);
8528 struct bgp
*bgp
= bgp_lookup_by_name (vrf
);
8531 vty_out (vty
, "Can't find BGP instance %s%s", vrf
, VTY_NEWLINE
);
8535 if (argv_find (argv
, argc
, "AA:BB:CC", &idx
))
8536 return bgp_show_lcommunity (vty
, bgp
, argc
, argv
, afi
, safi
, uj
);
8538 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_lcommunity_all
, NULL
, uj
);
8541 static int bgp_table_stats (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
, safi_t safi
);
8543 /* BGP route print out function. */
8546 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]]\
8549 |dampening <flap-statistics|dampened-paths|parameters>\
8554 |community [<AA:NN|local-AS|no-advertise|no-export> [exact-match]]\
8555 |community-list <(1-500)|WORD> [exact-match]\
8556 |A.B.C.D/M longer-prefixes\
8557 |X:X::X:X/M longer-prefixes>\
8562 BGP_INSTANCE_HELP_STR
8565 "Display only routes with non-natural netmasks\n"
8566 "Display detailed information about dampening\n"
8567 "Display flap statistics of routes\n"
8568 "Display paths suppressed due to dampening\n"
8569 "Display detail of configured dampening parameters\n"
8570 "Display routes matching the route-map\n"
8571 "A route-map to match on\n"
8572 "Display routes conforming to the prefix-list\n"
8573 "Prefix-list name\n"
8574 "Display routes conforming to the filter-list\n"
8575 "Regular expression access list name\n"
8576 "BGP RIB advertisement statistics\n"
8577 "Display routes matching the communities\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "Exact match of the communities\n"
8583 "Display routes matching the community-list\n"
8584 "community-list number\n"
8585 "community-list name\n"
8586 "Exact match of the communities\n"
8588 "Display route and more specific routes\n"
8590 "Display route and more specific routes\n"
8593 afi_t afi
= AFI_IP6
;
8594 safi_t safi
= SAFI_UNICAST
;
8595 int exact_match
= 0;
8596 enum bgp_show_type sh_type
= bgp_show_type_normal
;
8597 struct bgp
*bgp
= NULL
;
8600 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
8604 int uj
= use_json (argc
, argv
);
8607 if (argv_find(argv
, argc
, "cidr-only", &idx
))
8608 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_cidr_only
, NULL
, uj
);
8610 if (argv_find(argv
, argc
, "dampening", &idx
))
8612 if (argv_find (argv
, argc
, "dampened-paths", &idx
))
8613 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_dampend_paths
, NULL
, uj
);
8614 else if (argv_find (argv
, argc
, "flap-statistics", &idx
))
8615 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_flap_statistics
, NULL
, uj
);
8616 else if (argv_find (argv
, argc
, "parameters", &idx
))
8617 return bgp_show_dampening_parameters (vty
, afi
, safi
);
8620 if (argv_find(argv
, argc
, "prefix-list", &idx
))
8621 return bgp_show_prefix_list (vty
, bgp
, argv
[idx
+ 1]->arg
, afi
, safi
, bgp_show_type_prefix_list
);
8623 if (argv_find(argv
, argc
, "filter-list", &idx
))
8624 return bgp_show_filter_list (vty
, bgp
, argv
[idx
+ 1]->arg
, afi
, safi
, bgp_show_type_filter_list
);
8626 if (argv_find(argv
, argc
, "statistics", &idx
))
8627 return bgp_table_stats (vty
, bgp
, afi
, safi
);
8629 if (argv_find(argv
, argc
, "route-map", &idx
))
8630 return bgp_show_route_map (vty
, bgp
, argv
[idx
+ 1]->arg
, afi
, safi
, bgp_show_type_route_map
);
8632 if (argv_find(argv
, argc
, "community", &idx
))
8634 /* show a specific community */
8635 if (argv_find (argv
, argc
, "local-AS", &idx
) ||
8636 argv_find (argv
, argc
, "no-advertise", &idx
) ||
8637 argv_find (argv
, argc
, "no-export", &idx
))
8639 if (argv_find (argv
, argc
, "exact_match", &idx
))
8641 return bgp_show_community (vty
, bgp
, argc
, argv
, exact_match
, afi
, safi
);
8643 /* show all communities */
8645 return bgp_show (vty
, bgp
, afi
, safi
, bgp_show_type_community_all
, NULL
, uj
);
8648 if (argv_find(argv
, argc
, "community-list", &idx
))
8650 const char *clist_number_or_name
= argv
[++idx
]->arg
;
8651 if (++idx
< argc
&& strmatch (argv
[idx
]->text
, "exact-match"))
8653 return bgp_show_community_list (vty
, bgp
, clist_number_or_name
, exact_match
, afi
, safi
);
8656 if (argv_find(argv
, argc
, "A.B.C.D/M", &idx
) || argv_find(argv
, argc
, "X:X::X:X/M", &idx
))
8657 return bgp_show_prefix_longer (vty
, bgp
, argv
[idx
+ 1]->arg
, afi
, safi
, bgp_show_type_prefix_longer
);
8659 if (safi
== SAFI_MPLS_VPN
)
8660 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, uj
);
8661 else if (safi
== SAFI_ENCAP
)
8662 return bgp_show_encap (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0);
8664 return bgp_show (vty
, bgp
, afi
, safi
, sh_type
, NULL
, uj
);
8667 DEFUN (show_ip_bgp_route
,
8668 show_ip_bgp_route_cmd
,
8669 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]]"
8670 "<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [json]",
8674 BGP_INSTANCE_HELP_STR
8677 "Network in the BGP routing table to display\n"
8679 "Network in the BGP routing table to display\n"
8681 "Display only the bestpath\n"
8682 "Display only multipaths\n"
8685 int prefix_check
= 0;
8687 afi_t afi
= AFI_IP6
;
8688 safi_t safi
= SAFI_UNICAST
;
8689 char *prefix
= NULL
;
8690 struct bgp
*bgp
= NULL
;
8691 enum bgp_path_type path_type
;
8692 u_char uj
= use_json(argc
, argv
);
8696 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
8702 vty_out (vty
, "Specified 'all' vrf's but this command currently only works per view/vrf%s", VTY_NEWLINE
);
8706 /* <A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> */
8707 if (argv_find (argv
, argc
, "A.B.C.D", &idx
) || argv_find (argv
, argc
, "X:X::X:X", &idx
))
8709 else if (argv_find (argv
, argc
, "A.B.C.D/M", &idx
) || argv_find (argv
, argc
, "X:X::X:X/M", &idx
))
8712 if ((argv
[idx
]->type
== IPV6_TKN
|| argv
[idx
]->type
== IPV6_PREFIX_TKN
) && afi
!= AFI_IP6
)
8714 vty_out (vty
, "%% Cannot specify IPv6 address or prefix with IPv4 AFI%s", VTY_NEWLINE
);
8717 if ((argv
[idx
]->type
== IPV4_TKN
|| argv
[idx
]->type
== IPV4_PREFIX_TKN
) && afi
!= AFI_IP
)
8719 vty_out (vty
, "%% Cannot specify IPv4 address or prefix with IPv6 AFI%s", VTY_NEWLINE
);
8723 prefix
= argv
[idx
]->arg
;
8725 /* [<bestpath|multipath>] */
8726 if (argv_find (argv
, argc
, "bestpath", &idx
))
8727 path_type
= BGP_PATH_BESTPATH
;
8728 else if (argv_find (argv
, argc
, "multipath", &idx
))
8729 path_type
= BGP_PATH_MULTIPATH
;
8731 path_type
= BGP_PATH_ALL
;
8733 return bgp_show_route (vty
, bgp
, prefix
, afi
, safi
, NULL
, prefix_check
, path_type
, uj
);
8736 DEFUN (show_ip_bgp_regexp
,
8737 show_ip_bgp_regexp_cmd
,
8738 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]] regexp REGEX...",
8742 BGP_INSTANCE_HELP_STR
8745 "Display routes matching the AS path regular expression\n"
8746 "A regular-expression to match the BGP AS paths\n")
8748 afi_t afi
= AFI_IP6
;
8749 safi_t safi
= SAFI_UNICAST
;
8750 struct bgp
*bgp
= NULL
;
8753 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
8757 // get index of regex
8758 argv_find (argv
, argc
, "regexp", &idx
);
8761 char *regstr
= argv_concat (argv
, argc
, idx
);
8762 int rc
= bgp_show_regexp (vty
, (const char *) regstr
, afi
, safi
, bgp_show_type_regexp
);
8763 XFREE (MTYPE_TMP
, regstr
);
8767 DEFUN (show_ip_bgp_instance_all
,
8768 show_ip_bgp_instance_all_cmd
,
8769 "show [ip] bgp <view|vrf> all ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]] [json]",
8773 BGP_INSTANCE_ALL_HELP_STR
8779 safi_t safi
= SAFI_UNICAST
;
8780 struct bgp
*bgp
= NULL
;
8783 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
8787 int uj
= use_json (argc
, argv
);
8790 bgp_show_all_instances_routes_vty (vty
, afi
, safi
, uj
);
8795 bgp_show_regexp (struct vty
*vty
, const char *regstr
, afi_t afi
,
8796 safi_t safi
, enum bgp_show_type type
)
8801 regex
= bgp_regcomp (regstr
);
8804 vty_out (vty
, "Can't compile regexp %s%s", regstr
, VTY_NEWLINE
);
8808 rc
= bgp_show (vty
, NULL
, afi
, safi
, type
, regex
, 0);
8809 bgp_regex_free (regex
);
8814 bgp_show_prefix_list (struct vty
*vty
, struct bgp
*bgp
,
8815 const char *prefix_list_str
, afi_t afi
,
8816 safi_t safi
, enum bgp_show_type type
)
8818 struct prefix_list
*plist
;
8820 plist
= prefix_list_lookup (afi
, prefix_list_str
);
8823 vty_out (vty
, "%% %s is not a valid prefix-list name%s",
8824 prefix_list_str
, VTY_NEWLINE
);
8828 return bgp_show (vty
, bgp
, afi
, safi
, type
, plist
, 0);
8832 bgp_show_filter_list (struct vty
*vty
, struct bgp
*bgp
,
8833 const char *filter
, afi_t afi
,
8834 safi_t safi
, enum bgp_show_type type
)
8836 struct as_list
*as_list
;
8838 as_list
= as_list_lookup (filter
);
8839 if (as_list
== NULL
)
8841 vty_out (vty
, "%% %s is not a valid AS-path access-list name%s", filter
, VTY_NEWLINE
);
8845 return bgp_show (vty
, bgp
, afi
, safi
, type
, as_list
, 0);
8849 bgp_show_route_map (struct vty
*vty
, struct bgp
*bgp
,
8850 const char *rmap_str
, afi_t afi
,
8851 safi_t safi
, enum bgp_show_type type
)
8853 struct route_map
*rmap
;
8855 rmap
= route_map_lookup_by_name (rmap_str
);
8858 vty_out (vty
, "%% %s is not a valid route-map name%s",
8859 rmap_str
, VTY_NEWLINE
);
8863 return bgp_show (vty
, bgp
, afi
, safi
, type
, rmap
, 0);
8867 bgp_show_community (struct vty
*vty
, struct bgp
*bgp
, int argc
,
8868 struct cmd_token
**argv
, int exact
, afi_t afi
, safi_t safi
)
8870 struct community
*com
;
8876 b
= buffer_new (1024);
8877 for (i
= 0; i
< argc
; i
++)
8880 buffer_putc (b
, ' ');
8883 if ((strcmp (argv
[i
]->arg
, "unicast") == 0) || (strcmp (argv
[i
]->arg
, "multicast") == 0))
8888 buffer_putstr (b
, argv
[i
]->arg
);
8890 buffer_putc (b
, '\0');
8892 str
= buffer_getstr (b
);
8895 com
= community_str2com (str
);
8896 XFREE (MTYPE_TMP
, str
);
8899 vty_out (vty
, "%% Community malformed: %s", VTY_NEWLINE
);
8903 return bgp_show (vty
, bgp
, afi
, safi
,
8904 (exact
? bgp_show_type_community_exact
:
8905 bgp_show_type_community
), com
, 0);
8909 bgp_show_community_list (struct vty
*vty
, struct bgp
*bgp
,
8910 const char *com
, int exact
,
8911 afi_t afi
, safi_t safi
)
8913 struct community_list
*list
;
8915 list
= community_list_lookup (bgp_clist
, com
, COMMUNITY_LIST_MASTER
);
8918 vty_out (vty
, "%% %s is not a valid community-list name%s", com
,
8923 return bgp_show (vty
, bgp
, afi
, safi
,
8924 (exact
? bgp_show_type_community_list_exact
:
8925 bgp_show_type_community_list
), list
, 0);
8929 bgp_show_prefix_longer (struct vty
*vty
, struct bgp
*bgp
,
8930 const char *prefix
, afi_t afi
,
8931 safi_t safi
, enum bgp_show_type type
)
8938 ret
= str2prefix (prefix
, p
);
8941 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
8945 ret
= bgp_show (vty
, bgp
, afi
, safi
, type
, p
, 0);
8950 static struct peer
*
8951 peer_lookup_in_view (struct vty
*vty
, struct bgp
*bgp
,
8952 const char *ip_str
, u_char use_json
)
8958 /* Get peer sockunion. */
8959 ret
= str2sockunion (ip_str
, &su
);
8962 peer
= peer_lookup_by_conf_if (bgp
, ip_str
);
8965 peer
= peer_lookup_by_hostname(bgp
, ip_str
);
8971 json_object
*json_no
= NULL
;
8972 json_no
= json_object_new_object();
8973 json_object_string_add(json_no
, "malformedAddressOrName", ip_str
);
8974 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
8975 json_object_free(json_no
);
8978 vty_out (vty
, "%% Malformed address or name: %s%s", ip_str
, VTY_NEWLINE
);
8985 /* Peer structure lookup. */
8986 peer
= peer_lookup (bgp
, &su
);
8991 json_object
*json_no
= NULL
;
8992 json_no
= json_object_new_object();
8993 json_object_string_add(json_no
, "warning","No such neighbor");
8994 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
8995 json_object_free(json_no
);
8998 vty_out (vty
, "No such neighbor%s", VTY_NEWLINE
);
9007 BGP_STATS_MAXBITLEN
= 0,
9011 BGP_STATS_UNAGGREGATEABLE
,
9012 BGP_STATS_MAX_AGGREGATEABLE
,
9013 BGP_STATS_AGGREGATES
,
9015 BGP_STATS_ASPATH_COUNT
,
9016 BGP_STATS_ASPATH_MAXHOPS
,
9017 BGP_STATS_ASPATH_TOTHOPS
,
9018 BGP_STATS_ASPATH_MAXSIZE
,
9019 BGP_STATS_ASPATH_TOTSIZE
,
9020 BGP_STATS_ASN_HIGHEST
,
9024 static const char *table_stats_strs
[] =
9026 [BGP_STATS_PREFIXES
] = "Total Prefixes",
9027 [BGP_STATS_TOTPLEN
] = "Average prefix length",
9028 [BGP_STATS_RIB
] = "Total Advertisements",
9029 [BGP_STATS_UNAGGREGATEABLE
] = "Unaggregateable prefixes",
9030 [BGP_STATS_MAX_AGGREGATEABLE
] = "Maximum aggregateable prefixes",
9031 [BGP_STATS_AGGREGATES
] = "BGP Aggregate advertisements",
9032 [BGP_STATS_SPACE
] = "Address space advertised",
9033 [BGP_STATS_ASPATH_COUNT
] = "Advertisements with paths",
9034 [BGP_STATS_ASPATH_MAXHOPS
] = "Longest AS-Path (hops)",
9035 [BGP_STATS_ASPATH_MAXSIZE
] = "Largest AS-Path (bytes)",
9036 [BGP_STATS_ASPATH_TOTHOPS
] = "Average AS-Path length (hops)",
9037 [BGP_STATS_ASPATH_TOTSIZE
] = "Average AS-Path size (bytes)",
9038 [BGP_STATS_ASN_HIGHEST
] = "Highest public ASN",
9039 [BGP_STATS_MAX
] = NULL
,
9042 struct bgp_table_stats
9044 struct bgp_table
*table
;
9045 unsigned long long counts
[BGP_STATS_MAX
];
9049 #define TALLY_SIGFIG 100000
9050 static unsigned long
9051 ravg_tally (unsigned long count
, unsigned long oldavg
, unsigned long newval
)
9053 unsigned long newtot
= (count
-1) * oldavg
+ (newval
* TALLY_SIGFIG
);
9054 unsigned long res
= (newtot
* TALLY_SIGFIG
) / count
;
9055 unsigned long ret
= newtot
/ count
;
9057 if ((res
% TALLY_SIGFIG
) > (TALLY_SIGFIG
/2))
9065 bgp_table_stats_walker (struct thread
*t
)
9067 struct bgp_node
*rn
;
9068 struct bgp_node
*top
;
9069 struct bgp_table_stats
*ts
= THREAD_ARG (t
);
9070 unsigned int space
= 0;
9072 if (!(top
= bgp_table_top (ts
->table
)))
9075 switch (top
->p
.family
)
9078 space
= IPV4_MAX_BITLEN
;
9081 space
= IPV6_MAX_BITLEN
;
9085 ts
->counts
[BGP_STATS_MAXBITLEN
] = space
;
9087 for (rn
= top
; rn
; rn
= bgp_route_next (rn
))
9089 struct bgp_info
*ri
;
9090 struct bgp_node
*prn
= bgp_node_parent_nolock (rn
);
9091 unsigned int rinum
= 0;
9099 ts
->counts
[BGP_STATS_PREFIXES
]++;
9100 ts
->counts
[BGP_STATS_TOTPLEN
] += rn
->p
.prefixlen
;
9103 ts
->counts
[BGP_STATS_AVGPLEN
]
9104 = ravg_tally (ts
->counts
[BGP_STATS_PREFIXES
],
9105 ts
->counts
[BGP_STATS_AVGPLEN
],
9109 /* check if the prefix is included by any other announcements */
9110 while (prn
&& !prn
->info
)
9111 prn
= bgp_node_parent_nolock (prn
);
9113 if (prn
== NULL
|| prn
== top
)
9115 ts
->counts
[BGP_STATS_UNAGGREGATEABLE
]++;
9116 /* announced address space */
9118 ts
->counts
[BGP_STATS_SPACE
] += 1 << (space
- rn
->p
.prefixlen
);
9121 ts
->counts
[BGP_STATS_MAX_AGGREGATEABLE
]++;
9123 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
9126 ts
->counts
[BGP_STATS_RIB
]++;
9129 (CHECK_FLAG (ri
->attr
->flag
,
9130 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
))))
9131 ts
->counts
[BGP_STATS_AGGREGATES
]++;
9134 if (ri
->attr
&& ri
->attr
->aspath
)
9136 unsigned int hops
= aspath_count_hops (ri
->attr
->aspath
);
9137 unsigned int size
= aspath_size (ri
->attr
->aspath
);
9138 as_t highest
= aspath_highest (ri
->attr
->aspath
);
9140 ts
->counts
[BGP_STATS_ASPATH_COUNT
]++;
9142 if (hops
> ts
->counts
[BGP_STATS_ASPATH_MAXHOPS
])
9143 ts
->counts
[BGP_STATS_ASPATH_MAXHOPS
] = hops
;
9145 if (size
> ts
->counts
[BGP_STATS_ASPATH_MAXSIZE
])
9146 ts
->counts
[BGP_STATS_ASPATH_MAXSIZE
] = size
;
9148 ts
->counts
[BGP_STATS_ASPATH_TOTHOPS
] += hops
;
9149 ts
->counts
[BGP_STATS_ASPATH_TOTSIZE
] += size
;
9151 ts
->counts
[BGP_STATS_ASPATH_AVGHOPS
]
9152 = ravg_tally (ts
->counts
[BGP_STATS_ASPATH_COUNT
],
9153 ts
->counts
[BGP_STATS_ASPATH_AVGHOPS
],
9155 ts
->counts
[BGP_STATS_ASPATH_AVGSIZE
]
9156 = ravg_tally (ts
->counts
[BGP_STATS_ASPATH_COUNT
],
9157 ts
->counts
[BGP_STATS_ASPATH_AVGSIZE
],
9160 if (highest
> ts
->counts
[BGP_STATS_ASN_HIGHEST
])
9161 ts
->counts
[BGP_STATS_ASN_HIGHEST
] = highest
;
9169 bgp_table_stats (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
, safi_t safi
)
9171 struct bgp_table_stats ts
;
9174 if (!bgp
->rib
[afi
][safi
])
9176 vty_out (vty
, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
9177 afi
, safi
, VTY_NEWLINE
);
9181 memset (&ts
, 0, sizeof (ts
));
9182 ts
.table
= bgp
->rib
[afi
][safi
];
9183 thread_execute (bm
->master
, bgp_table_stats_walker
, &ts
, 0);
9185 vty_out (vty
, "BGP %s RIB statistics%s%s",
9186 afi_safi_print (afi
, safi
), VTY_NEWLINE
, VTY_NEWLINE
);
9188 for (i
= 0; i
< BGP_STATS_MAX
; i
++)
9190 if (!table_stats_strs
[i
])
9196 case BGP_STATS_ASPATH_AVGHOPS
:
9197 case BGP_STATS_ASPATH_AVGSIZE
:
9198 case BGP_STATS_AVGPLEN
:
9199 vty_out (vty
, "%-30s: ", table_stats_strs
[i
]);
9200 vty_out (vty
, "%12.2f",
9201 (float)ts
.counts
[i
] / (float)TALLY_SIGFIG
);
9204 case BGP_STATS_ASPATH_TOTHOPS
:
9205 case BGP_STATS_ASPATH_TOTSIZE
:
9206 vty_out (vty
, "%-30s: ", table_stats_strs
[i
]);
9207 vty_out (vty
, "%12.2f",
9209 (float)ts
.counts
[i
] /
9210 (float)ts
.counts
[BGP_STATS_ASPATH_COUNT
]
9213 case BGP_STATS_TOTPLEN
:
9214 vty_out (vty
, "%-30s: ", table_stats_strs
[i
]);
9215 vty_out (vty
, "%12.2f",
9217 (float)ts
.counts
[i
] /
9218 (float)ts
.counts
[BGP_STATS_PREFIXES
]
9221 case BGP_STATS_SPACE
:
9222 vty_out (vty
, "%-30s: ", table_stats_strs
[i
]);
9223 vty_out (vty
, "%12llu%s", ts
.counts
[i
], VTY_NEWLINE
);
9224 if (ts
.counts
[BGP_STATS_MAXBITLEN
] < 9)
9226 vty_out (vty
, "%30s: ", "%% announced ");
9227 vty_out (vty
, "%12.2f%s",
9228 100 * (float)ts
.counts
[BGP_STATS_SPACE
] /
9229 (float)((uint64_t)1UL << ts
.counts
[BGP_STATS_MAXBITLEN
]),
9231 vty_out (vty
, "%30s: ", "/8 equivalent ");
9232 vty_out (vty
, "%12.2f%s",
9233 (float)ts
.counts
[BGP_STATS_SPACE
] /
9234 (float)(1UL << (ts
.counts
[BGP_STATS_MAXBITLEN
] - 8)),
9236 if (ts
.counts
[BGP_STATS_MAXBITLEN
] < 25)
9238 vty_out (vty
, "%30s: ", "/24 equivalent ");
9239 vty_out (vty
, "%12.2f",
9240 (float)ts
.counts
[BGP_STATS_SPACE
] /
9241 (float)(1UL << (ts
.counts
[BGP_STATS_MAXBITLEN
] - 24)));
9244 vty_out (vty
, "%-30s: ", table_stats_strs
[i
]);
9245 vty_out (vty
, "%12llu", ts
.counts
[i
]);
9248 vty_out (vty
, "%s", VTY_NEWLINE
);
9263 PCOUNT_PFCNT
, /* the figure we display to users */
9267 static const char *pcount_strs
[] =
9269 [PCOUNT_ADJ_IN
] = "Adj-in",
9270 [PCOUNT_DAMPED
] = "Damped",
9271 [PCOUNT_REMOVED
] = "Removed",
9272 [PCOUNT_HISTORY
] = "History",
9273 [PCOUNT_STALE
] = "Stale",
9274 [PCOUNT_VALID
] = "Valid",
9275 [PCOUNT_ALL
] = "All RIB",
9276 [PCOUNT_COUNTED
] = "PfxCt counted",
9277 [PCOUNT_PFCNT
] = "Useable",
9278 [PCOUNT_MAX
] = NULL
,
9283 unsigned int count
[PCOUNT_MAX
];
9284 const struct peer
*peer
;
9285 const struct bgp_table
*table
;
9289 bgp_peer_count_walker (struct thread
*t
)
9291 struct bgp_node
*rn
;
9292 struct peer_pcounts
*pc
= THREAD_ARG (t
);
9293 const struct peer
*peer
= pc
->peer
;
9295 for (rn
= bgp_table_top (pc
->table
); rn
; rn
= bgp_route_next (rn
))
9297 struct bgp_adj_in
*ain
;
9298 struct bgp_info
*ri
;
9300 for (ain
= rn
->adj_in
; ain
; ain
= ain
->next
)
9301 if (ain
->peer
== peer
)
9302 pc
->count
[PCOUNT_ADJ_IN
]++;
9304 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
9306 char buf
[SU_ADDRSTRLEN
];
9308 if (ri
->peer
!= peer
)
9311 pc
->count
[PCOUNT_ALL
]++;
9313 if (CHECK_FLAG (ri
->flags
, BGP_INFO_DAMPED
))
9314 pc
->count
[PCOUNT_DAMPED
]++;
9315 if (CHECK_FLAG (ri
->flags
, BGP_INFO_HISTORY
))
9316 pc
->count
[PCOUNT_HISTORY
]++;
9317 if (CHECK_FLAG (ri
->flags
, BGP_INFO_REMOVED
))
9318 pc
->count
[PCOUNT_REMOVED
]++;
9319 if (CHECK_FLAG (ri
->flags
, BGP_INFO_STALE
))
9320 pc
->count
[PCOUNT_STALE
]++;
9321 if (CHECK_FLAG (ri
->flags
, BGP_INFO_VALID
))
9322 pc
->count
[PCOUNT_VALID
]++;
9323 if (!CHECK_FLAG (ri
->flags
, BGP_INFO_UNUSEABLE
))
9324 pc
->count
[PCOUNT_PFCNT
]++;
9326 if (CHECK_FLAG (ri
->flags
, BGP_INFO_COUNTED
))
9328 pc
->count
[PCOUNT_COUNTED
]++;
9329 if (CHECK_FLAG (ri
->flags
, BGP_INFO_UNUSEABLE
))
9330 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
9332 inet_ntop(rn
->p
.family
, &rn
->p
.u
.prefix
,
9333 buf
, SU_ADDRSTRLEN
),
9339 if (!CHECK_FLAG (ri
->flags
, BGP_INFO_UNUSEABLE
))
9340 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
9342 inet_ntop(rn
->p
.family
, &rn
->p
.u
.prefix
,
9343 buf
, SU_ADDRSTRLEN
),
9353 bgp_peer_counts (struct vty
*vty
, struct peer
*peer
, afi_t afi
, safi_t safi
, u_char use_json
)
9355 struct peer_pcounts pcounts
= { .peer
= peer
};
9357 json_object
*json
= NULL
;
9358 json_object
*json_loop
= NULL
;
9362 json
= json_object_new_object();
9363 json_loop
= json_object_new_object();
9366 if (!peer
|| !peer
->bgp
|| !peer
->afc
[afi
][safi
]
9367 || !peer
->bgp
->rib
[afi
][safi
])
9371 json_object_string_add(json
, "warning", "No such neighbor or address family");
9372 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9373 json_object_free(json
);
9376 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
9381 memset (&pcounts
, 0, sizeof(pcounts
));
9382 pcounts
.peer
= peer
;
9383 pcounts
.table
= peer
->bgp
->rib
[afi
][safi
];
9385 /* in-place call via thread subsystem so as to record execution time
9386 * * stats for the thread-walk (i.e. ensure this can't be blamed on
9387 * * on just vty_read()).
9389 thread_execute (bm
->master
, bgp_peer_count_walker
, &pcounts
, 0);
9393 json_object_string_add(json
, "prefixCountsFor", peer
->host
);
9394 json_object_string_add(json
, "multiProtocol", afi_safi_print (afi
, safi
));
9395 json_object_int_add(json
, "pfxCounter", peer
->pcount
[afi
][safi
]);
9397 for (i
= 0; i
< PCOUNT_MAX
; i
++)
9398 json_object_int_add(json_loop
, pcount_strs
[i
], pcounts
.count
[i
]);
9400 json_object_object_add(json
, "ribTableWalkCounters", json_loop
);
9402 if (pcounts
.count
[PCOUNT_PFCNT
] != peer
->pcount
[afi
][safi
])
9404 json_object_string_add(json
, "pfxctDriftFor", peer
->host
);
9405 json_object_string_add(json
, "recommended", "Please report this bug, with the above command output");
9407 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9408 json_object_free(json
);
9413 if (peer
->hostname
&& bgp_flag_check(peer
->bgp
, BGP_FLAG_SHOW_HOSTNAME
))
9415 vty_out (vty
, "Prefix counts for %s/%s, %s%s",
9416 peer
->hostname
, peer
->host
, afi_safi_print (afi
, safi
),
9421 vty_out (vty
, "Prefix counts for %s, %s%s",
9422 peer
->host
, afi_safi_print (afi
, safi
), VTY_NEWLINE
);
9425 vty_out (vty
, "PfxCt: %ld%s", peer
->pcount
[afi
][safi
], VTY_NEWLINE
);
9426 vty_out (vty
, "%sCounts from RIB table walk:%s%s",
9427 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
9429 for (i
= 0; i
< PCOUNT_MAX
; i
++)
9430 vty_out (vty
, "%20s: %-10d%s", pcount_strs
[i
], pcounts
.count
[i
], VTY_NEWLINE
);
9432 if (pcounts
.count
[PCOUNT_PFCNT
] != peer
->pcount
[afi
][safi
])
9434 vty_out (vty
, "%s [pcount] PfxCt drift!%s",
9435 peer
->host
, VTY_NEWLINE
);
9436 vty_out (vty
, "Please report this bug, with the above command output%s",
9444 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts
,
9445 show_ip_bgp_instance_neighbor_prefix_counts_cmd
,
9446 "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] "
9447 "neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
9451 BGP_INSTANCE_HELP_STR
9454 "Address Family modifier\n"
9455 "Address Family modifier\n"
9456 "Address Family modifier\n"
9457 "Address Family modifier\n"
9458 "Address Family modifier\n"
9459 "Detailed information on TCP and BGP neighbor connections\n"
9460 "Neighbor to display information about\n"
9461 "Neighbor to display information about\n"
9462 "Neighbor on BGP configured interface\n"
9463 "Display detailed prefix count information\n"
9466 afi_t afi
= AFI_IP6
;
9467 safi_t safi
= SAFI_UNICAST
;
9470 struct bgp
*bgp
= NULL
;
9472 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
9476 int uj
= use_json (argc
, argv
);
9479 argv_find (argv
, argc
, "neighbors", &idx
);
9480 peer
= peer_lookup_in_view (vty
, bgp
, argv
[idx
+1]->arg
, uj
);
9484 return bgp_peer_counts (vty
, peer
, AFI_IP
, SAFI_UNICAST
, uj
);
9487 #ifdef KEEP_OLD_VPN_COMMANDS
9488 DEFUN (show_ip_bgp_vpn_neighbor_prefix_counts
,
9489 show_ip_bgp_vpn_neighbor_prefix_counts_cmd
,
9490 "show [ip] bgp <vpnv4|vpnv6> all neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
9495 "Display information about all VPNv4 NLRIs\n"
9496 "Detailed information on TCP and BGP neighbor connections\n"
9497 "Neighbor to display information about\n"
9498 "Neighbor to display information about\n"
9499 "Neighbor on BGP configured interface\n"
9500 "Display detailed prefix count information\n"
9505 u_char uj
= use_json(argc
, argv
);
9507 peer
= peer_lookup_in_view (vty
, NULL
, argv
[idx_peer
]->arg
, uj
);
9511 return bgp_peer_counts (vty
, peer
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
9514 DEFUN (show_ip_bgp_vpn_all_route_prefix
,
9515 show_ip_bgp_vpn_all_route_prefix_cmd
,
9516 "show [ip] bgp <vpnv4|vpnv6> all <A.B.C.D|A.B.C.D/M> [json]",
9521 "Display information about all VPNv4 NLRIs\n"
9522 "Network in the BGP routing table to display\n"
9523 "Network in the BGP routing table to display\n"
9527 char *network
= NULL
;
9528 struct bgp
*bgp
= bgp_get_default();
9531 vty_out (vty
, "Can't find default instance%s", VTY_NEWLINE
);
9535 if (argv_find (argv
, argc
, "A.B.C.D", &idx
))
9536 network
= argv
[idx
]->arg
;
9537 else if (argv_find (argv
, argc
, "A.B.C.D/M", &idx
))
9538 network
= argv
[idx
]->arg
;
9541 vty_out (vty
, "Unable to figure out Network%s", VTY_NEWLINE
);
9545 return bgp_show_route (vty
, bgp
, network
, AFI_IP
, SAFI_MPLS_VPN
, NULL
, 0, BGP_PATH_ALL
, use_json(argc
, argv
));
9547 #endif /* KEEP_OLD_VPN_COMMANDS */
9549 DEFUN (show_ip_bgp_l2vpn_evpn_all_route_prefix
,
9550 show_ip_bgp_l2vpn_evpn_all_route_prefix_cmd
,
9551 "show [ip] bgp l2vpn evpn all <A.B.C.D|A.B.C.D/M> [json]",
9557 "Display information about all EVPN NLRIs\n"
9558 "Network in the BGP routing table to display\n"
9559 "Network in the BGP routing table to display\n"
9563 char *network
= NULL
;
9565 if (argv_find (argv
, argc
, "A.B.C.D", &idx
))
9566 network
= argv
[idx
]->arg
;
9567 else if (argv_find (argv
, argc
, "A.B.C.D/M", &idx
))
9568 network
= argv
[idx
]->arg
;
9571 vty_out (vty
, "Unable to figure out Network%s", VTY_NEWLINE
);
9574 return bgp_show_route (vty
, NULL
, network
, AFI_L2VPN
, SAFI_EVPN
, NULL
, 0, BGP_PATH_ALL
, use_json(argc
, argv
));
9578 show_adj_route (struct vty
*vty
, struct peer
*peer
, afi_t afi
, safi_t safi
,
9579 int in
, const char *rmap_name
, u_char use_json
, json_object
*json
)
9581 struct bgp_table
*table
;
9582 struct bgp_adj_in
*ain
;
9583 struct bgp_adj_out
*adj
;
9584 unsigned long output_count
;
9585 unsigned long filtered_count
;
9586 struct bgp_node
*rn
;
9591 struct attr_extra extra
;
9593 struct update_subgroup
*subgrp
;
9594 json_object
*json_scode
= NULL
;
9595 json_object
*json_ocode
= NULL
;
9596 json_object
*json_ar
= NULL
;
9597 struct peer_af
*paf
;
9601 json_scode
= json_object_new_object();
9602 json_ocode
= json_object_new_object();
9603 json_ar
= json_object_new_object();
9605 json_object_string_add(json_scode
, "suppressed", "s");
9606 json_object_string_add(json_scode
, "damped", "d");
9607 json_object_string_add(json_scode
, "history", "h");
9608 json_object_string_add(json_scode
, "valid", "*");
9609 json_object_string_add(json_scode
, "best", ">");
9610 json_object_string_add(json_scode
, "multipath", "=");
9611 json_object_string_add(json_scode
, "internal", "i");
9612 json_object_string_add(json_scode
, "ribFailure", "r");
9613 json_object_string_add(json_scode
, "stale", "S");
9614 json_object_string_add(json_scode
, "removed", "R");
9616 json_object_string_add(json_ocode
, "igp", "i");
9617 json_object_string_add(json_ocode
, "egp", "e");
9618 json_object_string_add(json_ocode
, "incomplete", "?");
9627 json_object_string_add(json
, "alert", "no BGP");
9628 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9629 json_object_free(json
);
9632 vty_out (vty
, "%% No bgp%s", VTY_NEWLINE
);
9636 table
= bgp
->rib
[afi
][safi
];
9638 output_count
= filtered_count
= 0;
9639 subgrp
= peer_subgroup(peer
, afi
, safi
);
9641 if (!in
&& subgrp
&& CHECK_FLAG (subgrp
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
))
9645 json_object_int_add(json
, "bgpTableVersion", table
->version
);
9646 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
9647 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
9648 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
9649 json_object_string_add(json
, "bgpOriginatingDefaultNetwork", "0.0.0.0");
9653 vty_out (vty
, "BGP table version is %" PRIu64
", local router ID is %s%s", table
->version
, inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
9654 vty_out (vty
, BGP_SHOW_SCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9655 vty_out (vty
, BGP_SHOW_OCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9657 vty_out (vty
, "Originating default network 0.0.0.0%s%s",
9658 VTY_NEWLINE
, VTY_NEWLINE
);
9663 attr
.extra
= &extra
;
9664 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
9668 for (ain
= rn
->adj_in
; ain
; ain
= ain
->next
)
9670 if (ain
->peer
== peer
)
9676 json_object_int_add(json
, "bgpTableVersion", 0);
9677 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
9678 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
9679 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
9683 vty_out (vty
, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
9684 vty_out (vty
, BGP_SHOW_SCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9685 vty_out (vty
, BGP_SHOW_OCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9692 vty_out (vty
, BGP_SHOW_HEADER
, VTY_NEWLINE
);
9697 bgp_attr_dup(&attr
, ain
->attr
);
9698 if (bgp_input_modifier(peer
, &rn
->p
, &attr
, afi
, safi
, rmap_name
) != RMAP_DENY
)
9700 route_vty_out_tmp (vty
, &rn
->p
, &attr
, safi
, use_json
, json_ar
);
9711 for (adj
= rn
->adj_out
; adj
; adj
= adj
->next
)
9712 SUBGRP_FOREACH_PEER(adj
->subgroup
, paf
)
9713 if (paf
->peer
== peer
)
9719 json_object_int_add(json
, "bgpTableVersion", table
->version
);
9720 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
9721 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
9722 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
9726 vty_out (vty
, "BGP table version is %" PRIu64
", local router ID is %s%s", table
->version
,
9727 inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
9728 vty_out (vty
, BGP_SHOW_SCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9729 vty_out (vty
, BGP_SHOW_OCODE_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
);
9737 vty_out (vty
, BGP_SHOW_HEADER
, VTY_NEWLINE
);
9743 bgp_attr_dup(&attr
, adj
->attr
);
9744 ret
= bgp_output_modifier(peer
, &rn
->p
, &attr
, afi
, safi
, rmap_name
);
9745 if (ret
!= RMAP_DENY
)
9747 route_vty_out_tmp (vty
, &rn
->p
, &attr
, safi
, use_json
, json_ar
);
9757 json_object_object_add(json
, "advertisedRoutes", json_ar
);
9759 if (output_count
!= 0)
9762 json_object_int_add(json
, "totalPrefixCounter", output_count
);
9764 vty_out (vty
, "%sTotal number of prefixes %ld%s",
9765 VTY_NEWLINE
, output_count
, VTY_NEWLINE
);
9769 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9770 json_object_free(json
);
9776 peer_adj_routes (struct vty
*vty
, struct peer
*peer
, afi_t afi
, safi_t safi
,
9777 int in
, const char *rmap_name
, u_char use_json
)
9779 json_object
*json
= NULL
;
9782 json
= json_object_new_object();
9784 if (!peer
|| !peer
->afc
[afi
][safi
])
9788 json_object_string_add(json
, "warning", "No such neighbor or address family");
9789 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9790 json_object_free(json
);
9793 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
9798 if (in
&& !CHECK_FLAG(peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
9802 json_object_string_add(json
, "warning", "Inbound soft reconfiguration not enabled");
9803 vty_out (vty
, "%s%s", json_object_to_json_string(json
), VTY_NEWLINE
);
9804 json_object_free(json
);
9807 vty_out (vty
, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE
);
9812 show_adj_route (vty
, peer
, afi
, safi
, in
, rmap_name
, use_json
, json
);
9817 DEFUN (show_ip_bgp_instance_neighbor_advertised_route
,
9818 show_ip_bgp_instance_neighbor_advertised_route_cmd
,
9819 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]] "
9820 "neighbors <A.B.C.D|X:X::X:X|WORD> <received-routes|advertised-routes> [route-map WORD] [json]",
9824 BGP_INSTANCE_HELP_STR
9827 "Detailed information on TCP and BGP neighbor connections\n"
9828 "Neighbor to display information about\n"
9829 "Neighbor to display information about\n"
9830 "Neighbor on BGP configured interface\n"
9831 "Display the received routes from neighbor\n"
9832 "Display the routes advertised to a BGP neighbor\n"
9833 "Route-map to modify the attributes\n"
9834 "Name of the route map\n"
9837 afi_t afi
= AFI_IP6
;
9838 safi_t safi
= SAFI_UNICAST
;
9839 char *rmap_name
= NULL
;
9840 char *peerstr
= NULL
;
9842 struct bgp
*bgp
= NULL
;
9847 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
9851 int uj
= use_json (argc
, argv
);
9854 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
9855 argv_find (argv
, argc
, "neighbors", &idx
);
9856 peerstr
= argv
[++idx
]->arg
;
9858 peer
= peer_lookup_in_view (vty
, bgp
, peerstr
, uj
);
9862 if (argv_find (argv
, argc
, "received-routes", &idx
))
9864 if (argv_find (argv
, argc
, "advertised-routes", &idx
))
9866 if (argv_find (argv
, argc
, "route-map", &idx
))
9867 rmap_name
= argv
[++idx
]->arg
;
9869 return peer_adj_routes (vty
, peer
, afi
, safi
, rcvd
, rmap_name
, uj
);
9872 DEFUN (show_ip_bgp_neighbor_received_prefix_filter
,
9873 show_ip_bgp_neighbor_received_prefix_filter_cmd
,
9874 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
9880 "Address Family modifier\n"
9881 "Detailed information on TCP and BGP neighbor connections\n"
9882 "Neighbor to display information about\n"
9883 "Neighbor to display information about\n"
9884 "Neighbor on BGP configured interface\n"
9885 "Display information received from a BGP neighbor\n"
9886 "Display the prefixlist filter\n"
9889 afi_t afi
= AFI_IP6
;
9890 safi_t safi
= SAFI_UNICAST
;
9891 char *peerstr
= NULL
;
9901 if (argv_find (argv
, argc
, "ip", &idx
))
9903 /* [<ipv4|ipv6> [unicast]] */
9904 if (argv_find (argv
, argc
, "ipv4", &idx
))
9906 if (argv_find (argv
, argc
, "ipv6", &idx
))
9908 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
9909 argv_find (argv
, argc
, "neighbors", &idx
);
9910 peerstr
= argv
[++idx
]->arg
;
9912 u_char uj
= use_json(argc
, argv
);
9914 ret
= str2sockunion (peerstr
, &su
);
9917 peer
= peer_lookup_by_conf_if (NULL
, peerstr
);
9921 vty_out (vty
, "{}%s", VTY_NEWLINE
);
9923 vty_out (vty
, "%% Malformed address or name: %s%s", peerstr
, VTY_NEWLINE
);
9929 peer
= peer_lookup (NULL
, &su
);
9933 vty_out (vty
, "{}%s", VTY_NEWLINE
);
9935 vty_out (vty
, "No peer%s", VTY_NEWLINE
);
9940 sprintf (name
, "%s.%d.%d", peer
->host
, afi
, safi
);
9941 count
= prefix_bgp_show_prefix_list (NULL
, afi
, name
, uj
);
9945 vty_out (vty
, "Address Family: %s%s", afi_safi_print(afi
, safi
), VTY_NEWLINE
);
9946 prefix_bgp_show_prefix_list (vty
, afi
, name
, uj
);
9951 vty_out (vty
, "{}%s", VTY_NEWLINE
);
9953 vty_out (vty
, "No functional output%s", VTY_NEWLINE
);
9960 bgp_show_neighbor_route (struct vty
*vty
, struct peer
*peer
, afi_t afi
,
9961 safi_t safi
, enum bgp_show_type type
, u_char use_json
)
9963 if (! peer
|| ! peer
->afc
[afi
][safi
])
9967 json_object
*json_no
= NULL
;
9968 json_no
= json_object_new_object();
9969 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
9970 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
9971 json_object_free(json_no
);
9974 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
9978 return bgp_show (vty
, peer
->bgp
, afi
, safi
, type
, &peer
->su
, use_json
);
9981 DEFUN (show_ip_bgp_neighbor_routes
,
9982 show_ip_bgp_neighbor_routes_cmd
,
9983 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR
" ["BGP_SAFI_CMD_STR
"]] "
9984 "neighbors <A.B.C.D|X:X::X:X|WORD> <flap-statistics|dampened-routes|routes> [json]",
9988 BGP_INSTANCE_HELP_STR
9991 "Detailed information on TCP and BGP neighbor connections\n"
9992 "Neighbor to display information about\n"
9993 "Neighbor to display information about\n"
9994 "Neighbor on BGP configured interface\n"
9995 "Display flap statistics of the routes learned from neighbor\n"
9996 "Display the dampened routes received from neighbor\n"
9997 "Display routes learned from neighbor\n"
10000 char *peerstr
= NULL
;
10001 struct bgp
*bgp
= NULL
;
10002 afi_t afi
= AFI_IP6
;
10003 safi_t safi
= SAFI_UNICAST
;
10005 enum bgp_show_type sh_type
= bgp_show_type_neighbor
;
10009 bgp_vty_find_and_parse_afi_safi_bgp (vty
, argv
, argc
, &idx
, &afi
, &safi
, &bgp
);
10011 return CMD_WARNING
;
10013 int uj
= use_json (argc
, argv
);
10016 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
10017 argv_find (argv
, argc
, "neighbors", &idx
);
10018 peerstr
= argv
[++idx
]->arg
;
10020 peer
= peer_lookup_in_view (vty
, bgp
, peerstr
, uj
);
10023 vty_out (vty
, "No such neighbor%s", VTY_NEWLINE
);
10024 return CMD_WARNING
;
10027 if (argv_find (argv
, argc
, "flap-statistics", &idx
))
10028 sh_type
= bgp_show_type_flap_neighbor
;
10029 else if (argv_find (argv
, argc
, "dampened-routes", &idx
))
10030 sh_type
= bgp_show_type_damp_neighbor
;
10031 else if (argv_find (argv
, argc
, "routes", &idx
))
10032 sh_type
= bgp_show_type_neighbor
;
10034 return bgp_show_neighbor_route (vty
, peer
, afi
, safi
, sh_type
, uj
);
10037 struct bgp_table
*bgp_distance_table
[AFI_MAX
][SAFI_MAX
];
10039 struct bgp_distance
10041 /* Distance value for the IP source prefix. */
10044 /* Name of the access-list to be matched. */
10048 DEFUN (show_bgp_afi_vpn_rd_route
,
10049 show_bgp_afi_vpn_rd_route_cmd
,
10050 "show bgp "BGP_AFI_CMD_STR
" vpn rd ASN:nn_or_IP-address:nn <A.B.C.D/M|X:X::X:X/M> [json]",
10054 "Address Family modifier\n"
10055 "Display information for a route distinguisher\n"
10056 "Route Distinguisher\n"
10057 "Network in the BGP routing table to display\n"
10058 "Network in the BGP routing table to display\n"
10062 struct prefix_rd prd
;
10063 afi_t afi
= AFI_MAX
;
10066 argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
);
10067 ret
= str2prefix_rd (argv
[5]->arg
, &prd
);
10070 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
10071 return CMD_WARNING
;
10073 return bgp_show_route (vty
, NULL
, argv
[6]->arg
, afi
, SAFI_MPLS_VPN
, &prd
, 0, BGP_PATH_ALL
, use_json (argc
, argv
));
10076 static struct bgp_distance
*
10077 bgp_distance_new (void)
10079 return XCALLOC (MTYPE_BGP_DISTANCE
, sizeof (struct bgp_distance
));
10083 bgp_distance_free (struct bgp_distance
*bdistance
)
10085 XFREE (MTYPE_BGP_DISTANCE
, bdistance
);
10089 bgp_distance_set (struct vty
*vty
, const char *distance_str
,
10090 const char *ip_str
, const char *access_list_str
)
10097 struct bgp_node
*rn
;
10098 struct bgp_distance
*bdistance
;
10100 afi
= bgp_node_afi (vty
);
10101 safi
= bgp_node_safi (vty
);
10103 ret
= str2prefix (ip_str
, &p
);
10106 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
10107 return CMD_WARNING
;
10110 distance
= atoi (distance_str
);
10112 /* Get BGP distance node. */
10113 rn
= bgp_node_get (bgp_distance_table
[afi
][safi
], (struct prefix
*) &p
);
10116 bdistance
= rn
->info
;
10117 bgp_unlock_node (rn
);
10121 bdistance
= bgp_distance_new ();
10122 rn
->info
= bdistance
;
10125 /* Set distance value. */
10126 bdistance
->distance
= distance
;
10128 /* Reset access-list configuration. */
10129 if (bdistance
->access_list
)
10131 XFREE(MTYPE_AS_LIST
, bdistance
->access_list
);
10132 bdistance
->access_list
= NULL
;
10134 if (access_list_str
)
10135 bdistance
->access_list
= XSTRDUP(MTYPE_AS_LIST
, access_list_str
);
10137 return CMD_SUCCESS
;
10141 bgp_distance_unset (struct vty
*vty
, const char *distance_str
,
10142 const char *ip_str
, const char *access_list_str
)
10149 struct bgp_node
*rn
;
10150 struct bgp_distance
*bdistance
;
10152 afi
= bgp_node_afi (vty
);
10153 safi
= bgp_node_safi (vty
);
10155 ret
= str2prefix (ip_str
, &p
);
10158 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
10159 return CMD_WARNING
;
10162 rn
= bgp_node_lookup (bgp_distance_table
[afi
][safi
], (struct prefix
*)&p
);
10165 vty_out (vty
, "Can't find specified prefix%s", VTY_NEWLINE
);
10166 return CMD_WARNING
;
10169 bdistance
= rn
->info
;
10170 distance
= atoi(distance_str
);
10172 if (bdistance
->distance
!= distance
)
10174 vty_out (vty
, "Distance does not match configured%s", VTY_NEWLINE
);
10175 return CMD_WARNING
;
10178 if (bdistance
->access_list
)
10179 XFREE(MTYPE_AS_LIST
, bdistance
->access_list
);
10180 bgp_distance_free (bdistance
);
10183 bgp_unlock_node (rn
);
10184 bgp_unlock_node (rn
);
10186 return CMD_SUCCESS
;
10189 /* Apply BGP information to distance method. */
10191 bgp_distance_apply (struct prefix
*p
, struct bgp_info
*rinfo
, afi_t afi
,
10192 safi_t safi
, struct bgp
*bgp
)
10194 struct bgp_node
*rn
;
10197 struct bgp_distance
*bdistance
;
10198 struct access_list
*alist
;
10199 struct bgp_static
*bgp_static
;
10204 peer
= rinfo
->peer
;
10206 /* Check source address. */
10207 sockunion2hostprefix (&peer
->su
, &q
);
10208 rn
= bgp_node_match (bgp_distance_table
[afi
][safi
], &q
);
10211 bdistance
= rn
->info
;
10212 bgp_unlock_node (rn
);
10214 if (bdistance
->access_list
)
10216 alist
= access_list_lookup (afi
, bdistance
->access_list
);
10217 if (alist
&& access_list_apply (alist
, p
) == FILTER_PERMIT
)
10218 return bdistance
->distance
;
10221 return bdistance
->distance
;
10224 /* Backdoor check. */
10225 rn
= bgp_node_lookup (bgp
->route
[afi
][safi
], p
);
10228 bgp_static
= rn
->info
;
10229 bgp_unlock_node (rn
);
10231 if (bgp_static
->backdoor
)
10233 if (bgp
->distance_local
[afi
][safi
])
10234 return bgp
->distance_local
[afi
][safi
];
10236 return ZEBRA_IBGP_DISTANCE_DEFAULT
;
10240 if (peer
->sort
== BGP_PEER_EBGP
)
10242 if (bgp
->distance_ebgp
[afi
][safi
])
10243 return bgp
->distance_ebgp
[afi
][safi
];
10244 return ZEBRA_EBGP_DISTANCE_DEFAULT
;
10248 if (bgp
->distance_ibgp
[afi
][safi
])
10249 return bgp
->distance_ibgp
[afi
][safi
];
10250 return ZEBRA_IBGP_DISTANCE_DEFAULT
;
10254 DEFUN (bgp_distance
,
10256 "distance bgp (1-255) (1-255) (1-255)",
10257 "Define an administrative distance\n"
10259 "Distance for routes external to the AS\n"
10260 "Distance for routes internal to the AS\n"
10261 "Distance for local routes\n")
10263 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
10264 int idx_number
= 2;
10265 int idx_number_2
= 3;
10266 int idx_number_3
= 4;
10270 afi
= bgp_node_afi (vty
);
10271 safi
= bgp_node_safi (vty
);
10273 bgp
->distance_ebgp
[afi
][safi
] = atoi (argv
[idx_number
]->arg
);
10274 bgp
->distance_ibgp
[afi
][safi
] = atoi (argv
[idx_number_2
]->arg
);
10275 bgp
->distance_local
[afi
][safi
] = atoi (argv
[idx_number_3
]->arg
);
10276 return CMD_SUCCESS
;
10279 DEFUN (no_bgp_distance
,
10280 no_bgp_distance_cmd
,
10281 "no distance bgp [(1-255) (1-255) (1-255)]",
10283 "Define an administrative distance\n"
10285 "Distance for routes external to the AS\n"
10286 "Distance for routes internal to the AS\n"
10287 "Distance for local routes\n")
10289 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
10293 afi
= bgp_node_afi (vty
);
10294 safi
= bgp_node_safi (vty
);
10296 bgp
->distance_ebgp
[afi
][safi
] = 0;
10297 bgp
->distance_ibgp
[afi
][safi
] = 0;
10298 bgp
->distance_local
[afi
][safi
] = 0;
10299 return CMD_SUCCESS
;
10303 DEFUN (bgp_distance_source
,
10304 bgp_distance_source_cmd
,
10305 "distance (1-255) A.B.C.D/M",
10306 "Define an administrative distance\n"
10307 "Administrative distance\n"
10308 "IP source prefix\n")
10310 int idx_number
= 1;
10311 int idx_ipv4_prefixlen
= 2;
10312 bgp_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
10313 return CMD_SUCCESS
;
10316 DEFUN (no_bgp_distance_source
,
10317 no_bgp_distance_source_cmd
,
10318 "no distance (1-255) A.B.C.D/M",
10320 "Define an administrative distance\n"
10321 "Administrative distance\n"
10322 "IP source prefix\n")
10324 int idx_number
= 2;
10325 int idx_ipv4_prefixlen
= 3;
10326 bgp_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
10327 return CMD_SUCCESS
;
10330 DEFUN (bgp_distance_source_access_list
,
10331 bgp_distance_source_access_list_cmd
,
10332 "distance (1-255) A.B.C.D/M WORD",
10333 "Define an administrative distance\n"
10334 "Administrative distance\n"
10335 "IP source prefix\n"
10336 "Access list name\n")
10338 int idx_number
= 1;
10339 int idx_ipv4_prefixlen
= 2;
10341 bgp_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
10342 return CMD_SUCCESS
;
10345 DEFUN (no_bgp_distance_source_access_list
,
10346 no_bgp_distance_source_access_list_cmd
,
10347 "no distance (1-255) A.B.C.D/M WORD",
10349 "Define an administrative distance\n"
10350 "Administrative distance\n"
10351 "IP source prefix\n"
10352 "Access list name\n")
10354 int idx_number
= 2;
10355 int idx_ipv4_prefixlen
= 3;
10357 bgp_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
10358 return CMD_SUCCESS
;
10361 DEFUN (ipv6_bgp_distance_source
,
10362 ipv6_bgp_distance_source_cmd
,
10363 "distance (1-255) X:X::X:X/M",
10364 "Define an administrative distance\n"
10365 "Administrative distance\n"
10366 "IP source prefix\n")
10368 bgp_distance_set (vty
, argv
[1]->arg
, argv
[2]->arg
, NULL
);
10369 return CMD_SUCCESS
;
10372 DEFUN (no_ipv6_bgp_distance_source
,
10373 no_ipv6_bgp_distance_source_cmd
,
10374 "no distance (1-255) X:X::X:X/M",
10376 "Define an administrative distance\n"
10377 "Administrative distance\n"
10378 "IP source prefix\n")
10380 bgp_distance_unset (vty
, argv
[2]->arg
, argv
[3]->arg
, NULL
);
10381 return CMD_SUCCESS
;
10384 DEFUN (ipv6_bgp_distance_source_access_list
,
10385 ipv6_bgp_distance_source_access_list_cmd
,
10386 "distance (1-255) X:X::X:X/M WORD",
10387 "Define an administrative distance\n"
10388 "Administrative distance\n"
10389 "IP source prefix\n"
10390 "Access list name\n")
10392 bgp_distance_set (vty
, argv
[1]->arg
, argv
[2]->arg
, argv
[3]->arg
);
10393 return CMD_SUCCESS
;
10396 DEFUN (no_ipv6_bgp_distance_source_access_list
,
10397 no_ipv6_bgp_distance_source_access_list_cmd
,
10398 "no distance (1-255) X:X::X:X/M WORD",
10400 "Define an administrative distance\n"
10401 "Administrative distance\n"
10402 "IP source prefix\n"
10403 "Access list name\n")
10405 bgp_distance_unset (vty
, argv
[2]->arg
, argv
[3]->arg
, argv
[4]->arg
);
10406 return CMD_SUCCESS
;
10409 DEFUN (bgp_damp_set
,
10411 "bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]",
10412 "BGP Specific commands\n"
10413 "Enable route-flap dampening\n"
10414 "Half-life time for the penalty\n"
10415 "Value to start reusing a route\n"
10416 "Value to start suppressing a route\n"
10417 "Maximum duration to suppress a stable route\n")
10419 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
10420 int idx_half_life
= 2;
10422 int idx_suppress
= 4;
10423 int idx_max_suppress
= 5;
10424 int half
= DEFAULT_HALF_LIFE
* 60;
10425 int reuse
= DEFAULT_REUSE
;
10426 int suppress
= DEFAULT_SUPPRESS
;
10427 int max
= 4 * half
;
10431 half
= atoi (argv
[idx_half_life
]->arg
) * 60;
10432 reuse
= atoi (argv
[idx_reuse
]->arg
);
10433 suppress
= atoi (argv
[idx_suppress
]->arg
);
10434 max
= atoi (argv
[idx_max_suppress
]->arg
) * 60;
10436 else if (argc
== 3)
10438 half
= atoi (argv
[idx_half_life
]->arg
) * 60;
10442 if (suppress
< reuse
)
10444 vty_out (vty
, "Suppress value cannot be less than reuse value %s",
10449 return bgp_damp_enable (bgp
, bgp_node_afi (vty
), bgp_node_safi (vty
),
10450 half
, reuse
, suppress
, max
);
10453 DEFUN (bgp_damp_unset
,
10454 bgp_damp_unset_cmd
,
10455 "no bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]",
10457 "BGP Specific commands\n"
10458 "Enable route-flap dampening\n"
10459 "Half-life time for the penalty\n"
10460 "Value to start reusing a route\n"
10461 "Value to start suppressing a route\n"
10462 "Maximum duration to suppress a stable route\n")
10464 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
10465 return bgp_damp_disable (bgp
, bgp_node_afi (vty
), bgp_node_safi (vty
));
10468 /* Display specified route of BGP table. */
10470 bgp_clear_damp_route (struct vty
*vty
, const char *view_name
,
10471 const char *ip_str
, afi_t afi
, safi_t safi
,
10472 struct prefix_rd
*prd
, int prefix_check
)
10475 struct prefix match
;
10476 struct bgp_node
*rn
;
10477 struct bgp_node
*rm
;
10478 struct bgp_info
*ri
;
10479 struct bgp_info
*ri_temp
;
10481 struct bgp_table
*table
;
10483 /* BGP structure lookup. */
10486 bgp
= bgp_lookup_by_name (view_name
);
10489 vty_out (vty
, "%% Can't find BGP instance %s%s", view_name
, VTY_NEWLINE
);
10490 return CMD_WARNING
;
10495 bgp
= bgp_get_default ();
10498 vty_out (vty
, "%% No BGP process is configured%s", VTY_NEWLINE
);
10499 return CMD_WARNING
;
10503 /* Check IP address argument. */
10504 ret
= str2prefix (ip_str
, &match
);
10507 vty_out (vty
, "%% address is malformed%s", VTY_NEWLINE
);
10508 return CMD_WARNING
;
10511 match
.family
= afi2family (afi
);
10513 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
) || (safi
== SAFI_EVPN
))
10515 for (rn
= bgp_table_top (bgp
->rib
[AFI_IP
][safi
]); rn
; rn
= bgp_route_next (rn
))
10517 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
10520 if ((table
= rn
->info
) != NULL
)
10521 if ((rm
= bgp_node_match (table
, &match
)) != NULL
)
10523 if (! prefix_check
|| rm
->p
.prefixlen
== match
.prefixlen
)
10528 if (ri
->extra
&& ri
->extra
->damp_info
)
10530 ri_temp
= ri
->next
;
10531 bgp_damp_info_free (ri
->extra
->damp_info
, 1);
10539 bgp_unlock_node (rm
);
10545 if ((rn
= bgp_node_match (bgp
->rib
[afi
][safi
], &match
)) != NULL
)
10547 if (! prefix_check
|| rn
->p
.prefixlen
== match
.prefixlen
)
10552 if (ri
->extra
&& ri
->extra
->damp_info
)
10554 ri_temp
= ri
->next
;
10555 bgp_damp_info_free (ri
->extra
->damp_info
, 1);
10563 bgp_unlock_node (rn
);
10567 return CMD_SUCCESS
;
10570 DEFUN (clear_ip_bgp_dampening
,
10571 clear_ip_bgp_dampening_cmd
,
10572 "clear ip bgp dampening",
10576 "Clear route flap dampening information\n")
10578 bgp_damp_info_clean ();
10579 return CMD_SUCCESS
;
10582 DEFUN (clear_ip_bgp_dampening_prefix
,
10583 clear_ip_bgp_dampening_prefix_cmd
,
10584 "clear ip bgp dampening A.B.C.D/M",
10588 "Clear route flap dampening information\n"
10591 int idx_ipv4_prefixlen
= 4;
10592 return bgp_clear_damp_route (vty
, NULL
, argv
[idx_ipv4_prefixlen
]->arg
, AFI_IP
,
10593 SAFI_UNICAST
, NULL
, 1);
10596 DEFUN (clear_ip_bgp_dampening_address
,
10597 clear_ip_bgp_dampening_address_cmd
,
10598 "clear ip bgp dampening A.B.C.D",
10602 "Clear route flap dampening information\n"
10603 "Network to clear damping information\n")
10606 return bgp_clear_damp_route (vty
, NULL
, argv
[idx_ipv4
]->arg
, AFI_IP
,
10607 SAFI_UNICAST
, NULL
, 0);
10610 DEFUN (clear_ip_bgp_dampening_address_mask
,
10611 clear_ip_bgp_dampening_address_mask_cmd
,
10612 "clear ip bgp dampening A.B.C.D A.B.C.D",
10616 "Clear route flap dampening information\n"
10617 "Network to clear damping information\n"
10621 int idx_ipv4_2
= 5;
10623 char prefix_str
[BUFSIZ
];
10625 ret
= netmask_str2prefix_str (argv
[idx_ipv4
]->arg
, argv
[idx_ipv4_2
]->arg
, prefix_str
);
10628 vty_out (vty
, "%% Inconsistent address and mask%s", VTY_NEWLINE
);
10629 return CMD_WARNING
;
10632 return bgp_clear_damp_route (vty
, NULL
, prefix_str
, AFI_IP
,
10633 SAFI_UNICAST
, NULL
, 0);
10636 /* also used for encap safi */
10638 bgp_config_write_network_vpn (struct vty
*vty
, struct bgp
*bgp
,
10639 afi_t afi
, safi_t safi
, int *write
)
10641 struct bgp_node
*prn
;
10642 struct bgp_node
*rn
;
10643 struct bgp_table
*table
;
10645 struct prefix_rd
*prd
;
10646 struct bgp_static
*bgp_static
;
10648 char buf
[SU_ADDRSTRLEN
];
10649 char rdbuf
[RD_ADDRSTRLEN
];
10651 /* Network configuration. */
10652 for (prn
= bgp_table_top (bgp
->route
[afi
][safi
]); prn
; prn
= bgp_route_next (prn
))
10653 if ((table
= prn
->info
) != NULL
)
10654 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
10655 if ((bgp_static
= rn
->info
) != NULL
)
10658 prd
= (struct prefix_rd
*) &prn
->p
;
10660 /* "address-family" display. */
10661 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10663 /* "network" configuration display. */
10664 prefix_rd2str (prd
, rdbuf
, RD_ADDRSTRLEN
);
10665 label
= decode_label (bgp_static
->tag
);
10667 vty_out (vty
, " network %s/%d rd %s tag %d",
10668 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
),
10671 vty_out (vty
, "%s", VTY_NEWLINE
);
10677 bgp_config_write_network_evpn (struct vty
*vty
, struct bgp
*bgp
,
10678 afi_t afi
, safi_t safi
, int *write
)
10680 struct bgp_node
*prn
;
10681 struct bgp_node
*rn
;
10682 struct bgp_table
*table
;
10684 struct prefix_rd
*prd
;
10685 struct bgp_static
*bgp_static
;
10686 char buf
[PREFIX_STRLEN
];
10687 char buf2
[SU_ADDRSTRLEN
];
10688 char rdbuf
[RD_ADDRSTRLEN
];
10690 /* Network configuration. */
10691 for (prn
= bgp_table_top (bgp
->route
[afi
][safi
]); prn
; prn
= bgp_route_next (prn
))
10692 if ((table
= prn
->info
) != NULL
)
10693 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
10694 if ((bgp_static
= rn
->info
) != NULL
)
10696 char *macrouter
= NULL
;
10699 if(bgp_static
->router_mac
)
10700 macrouter
= prefix_mac2str(bgp_static
->router_mac
, NULL
, 0);
10701 if(bgp_static
->eth_s_id
)
10702 esi
= esi2str(bgp_static
->eth_s_id
);
10704 prd
= (struct prefix_rd
*) &prn
->p
;
10706 /* "address-family" display. */
10707 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10709 /* "network" configuration display. */
10710 prefix_rd2str (prd
, rdbuf
, RD_ADDRSTRLEN
);
10712 inet_ntop (AF_INET
, &bgp_static
->igpnexthop
, buf2
, SU_ADDRSTRLEN
);
10714 prefix2str (p
, buf
, sizeof (buf
)),
10715 vty_out (vty
, " network %s rd %s ethtag %u tag %u esi %s gwip %s routermac %s",
10716 buf
, rdbuf
, p
->u
.prefix_evpn
.eth_tag
,
10717 decode_label (bgp_static
->tag
), esi
, buf2
, macrouter
);
10718 vty_out (vty
, "%s", VTY_NEWLINE
);
10720 XFREE (MTYPE_TMP
, macrouter
);
10722 XFREE (MTYPE_TMP
, esi
);
10727 /* Configuration of static route announcement and aggregate
10730 bgp_config_write_network (struct vty
*vty
, struct bgp
*bgp
,
10731 afi_t afi
, safi_t safi
, int *write
)
10733 struct bgp_node
*rn
;
10735 struct bgp_static
*bgp_static
;
10736 struct bgp_aggregate
*bgp_aggregate
;
10737 char buf
[SU_ADDRSTRLEN
];
10739 if ((safi
== SAFI_MPLS_VPN
) || (safi
== SAFI_ENCAP
))
10740 return bgp_config_write_network_vpn (vty
, bgp
, afi
, safi
, write
);
10742 if (afi
== AFI_L2VPN
&& safi
== SAFI_EVPN
)
10743 return bgp_config_write_network_evpn (vty
, bgp
, afi
, safi
, write
);
10745 /* Network configuration. */
10746 for (rn
= bgp_table_top (bgp
->route
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
10747 if ((bgp_static
= rn
->info
) != NULL
)
10751 /* "address-family" display. */
10752 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10754 /* "network" configuration display. */
10755 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
) && afi
== AFI_IP
)
10757 u_int32_t destination
;
10758 struct in_addr netmask
;
10760 destination
= ntohl (p
->u
.prefix4
.s_addr
);
10761 masklen2ip (p
->prefixlen
, &netmask
);
10762 vty_out (vty
, " network %s",
10763 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
));
10765 if ((IN_CLASSC (destination
) && p
->prefixlen
== 24)
10766 || (IN_CLASSB (destination
) && p
->prefixlen
== 16)
10767 || (IN_CLASSA (destination
) && p
->prefixlen
== 8)
10768 || p
->u
.prefix4
.s_addr
== 0)
10770 /* Natural mask is not display. */
10773 vty_out (vty
, " mask %s", inet_ntoa (netmask
));
10777 vty_out (vty
, " network %s/%d",
10778 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
),
10782 if (bgp_static
->label_index
!= BGP_INVALID_LABEL_INDEX
)
10783 vty_out (vty
, " label-index %u", bgp_static
->label_index
);
10785 if (bgp_static
->rmap
.name
)
10786 vty_out (vty
, " route-map %s", bgp_static
->rmap
.name
);
10789 if (bgp_static
->backdoor
)
10790 vty_out (vty
, " backdoor");
10793 vty_out (vty
, "%s", VTY_NEWLINE
);
10796 /* Aggregate-address configuration. */
10797 for (rn
= bgp_table_top (bgp
->aggregate
[afi
][safi
]); rn
; rn
= bgp_route_next (rn
))
10798 if ((bgp_aggregate
= rn
->info
) != NULL
)
10802 /* "address-family" display. */
10803 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10805 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
) && afi
== AFI_IP
)
10807 struct in_addr netmask
;
10809 masklen2ip (p
->prefixlen
, &netmask
);
10810 vty_out (vty
, " aggregate-address %s %s",
10811 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
),
10812 inet_ntoa (netmask
));
10816 vty_out (vty
, " aggregate-address %s/%d",
10817 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, SU_ADDRSTRLEN
),
10821 if (bgp_aggregate
->as_set
)
10822 vty_out (vty
, " as-set");
10824 if (bgp_aggregate
->summary_only
)
10825 vty_out (vty
, " summary-only");
10827 vty_out (vty
, "%s", VTY_NEWLINE
);
10834 bgp_config_write_distance (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
10835 safi_t safi
, int *write
)
10837 struct bgp_node
*rn
;
10838 struct bgp_distance
*bdistance
;
10840 /* Distance configuration. */
10841 if (bgp
->distance_ebgp
[afi
][safi
]
10842 && bgp
->distance_ibgp
[afi
][safi
]
10843 && bgp
->distance_local
[afi
][safi
]
10844 && (bgp
->distance_ebgp
[afi
][safi
] != ZEBRA_EBGP_DISTANCE_DEFAULT
10845 || bgp
->distance_ibgp
[afi
][safi
] != ZEBRA_IBGP_DISTANCE_DEFAULT
10846 || bgp
->distance_local
[afi
][safi
] != ZEBRA_IBGP_DISTANCE_DEFAULT
))
10848 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10849 vty_out (vty
, " distance bgp %d %d %d%s",
10850 bgp
->distance_ebgp
[afi
][safi
], bgp
->distance_ibgp
[afi
][safi
],
10851 bgp
->distance_local
[afi
][safi
], VTY_NEWLINE
);
10854 for (rn
= bgp_table_top (bgp_distance_table
[afi
][safi
]); rn
;
10855 rn
= bgp_route_next (rn
))
10856 if ((bdistance
= rn
->info
) != NULL
)
10858 char buf
[PREFIX_STRLEN
];
10860 bgp_config_write_family_header (vty
, afi
, safi
, write
);
10861 vty_out (vty
, " distance %d %s %s%s", bdistance
->distance
,
10862 prefix2str (&rn
->p
, buf
, sizeof (buf
)),
10863 bdistance
->access_list
? bdistance
->access_list
: "",
10870 /* Allocate routing table structure and install commands. */
10872 bgp_route_init (void)
10877 /* Init BGP distance table. */
10878 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
10879 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
10880 bgp_distance_table
[afi
][safi
] = bgp_table_init (afi
, safi
);
10882 /* IPv4 BGP commands. */
10883 install_element (BGP_NODE
, &bgp_table_map_cmd
);
10884 install_element (BGP_NODE
, &bgp_network_cmd
);
10885 install_element (BGP_NODE
, &bgp_network_mask_cmd
);
10886 install_element (BGP_NODE
, &bgp_network_mask_natural_cmd
);
10887 install_element (BGP_NODE
, &bgp_network_route_map_cmd
);
10888 install_element (BGP_NODE
, &bgp_network_mask_route_map_cmd
);
10889 install_element (BGP_NODE
, &bgp_network_mask_natural_route_map_cmd
);
10890 install_element (BGP_NODE
, &bgp_network_backdoor_cmd
);
10891 install_element (BGP_NODE
, &bgp_network_mask_backdoor_cmd
);
10892 install_element (BGP_NODE
, &bgp_network_mask_natural_backdoor_cmd
);
10893 install_element (BGP_NODE
, &no_bgp_table_map_cmd
);
10894 install_element (BGP_NODE
, &no_bgp_network_cmd
);
10895 install_element (BGP_NODE
, &no_bgp_network_mask_cmd
);
10896 install_element (BGP_NODE
, &no_bgp_network_mask_natural_cmd
);
10898 install_element (BGP_NODE
, &aggregate_address_cmd
);
10899 install_element (BGP_NODE
, &aggregate_address_mask_cmd
);
10900 install_element (BGP_NODE
, &no_aggregate_address_cmd
);
10901 install_element (BGP_NODE
, &no_aggregate_address_mask_cmd
);
10903 /* IPv4 unicast configuration. */
10904 install_element (BGP_IPV4_NODE
, &bgp_table_map_cmd
);
10905 install_element (BGP_IPV4_NODE
, &bgp_network_cmd
);
10906 install_element (BGP_IPV4_NODE
, &bgp_network_mask_cmd
);
10907 install_element (BGP_IPV4_NODE
, &bgp_network_mask_natural_cmd
);
10908 install_element (BGP_IPV4_NODE
, &bgp_network_route_map_cmd
);
10909 install_element (BGP_IPV4_NODE
, &bgp_network_mask_route_map_cmd
);
10910 install_element (BGP_IPV4_NODE
, &bgp_network_mask_natural_route_map_cmd
);
10911 install_element (BGP_IPV4L_NODE
, &no_bgp_network_label_index_cmd
);
10912 install_element (BGP_IPV4L_NODE
, &no_bgp_network_label_index_route_map_cmd
);
10913 install_element (BGP_IPV4_NODE
, &no_bgp_table_map_cmd
);
10914 install_element (BGP_IPV4_NODE
, &no_bgp_network_cmd
);
10915 install_element (BGP_IPV4_NODE
, &no_bgp_network_mask_cmd
);
10916 install_element (BGP_IPV4_NODE
, &no_bgp_network_mask_natural_cmd
);
10918 install_element (BGP_IPV4_NODE
, &aggregate_address_cmd
);
10919 install_element (BGP_IPV4_NODE
, &aggregate_address_mask_cmd
);
10920 install_element (BGP_IPV4_NODE
, &no_aggregate_address_cmd
);
10921 install_element (BGP_IPV4_NODE
, &no_aggregate_address_mask_cmd
);
10923 /* IPv4 multicast configuration. */
10924 install_element (BGP_IPV4M_NODE
, &bgp_table_map_cmd
);
10925 install_element (BGP_IPV4M_NODE
, &bgp_network_cmd
);
10926 install_element (BGP_IPV4M_NODE
, &bgp_network_mask_cmd
);
10927 install_element (BGP_IPV4M_NODE
, &bgp_network_mask_natural_cmd
);
10928 install_element (BGP_IPV4M_NODE
, &bgp_network_route_map_cmd
);
10929 install_element (BGP_IPV4M_NODE
, &bgp_network_mask_route_map_cmd
);
10930 install_element (BGP_IPV4M_NODE
, &bgp_network_mask_natural_route_map_cmd
);
10931 install_element (BGP_IPV4M_NODE
, &no_bgp_table_map_cmd
);
10932 install_element (BGP_IPV4M_NODE
, &no_bgp_network_cmd
);
10933 install_element (BGP_IPV4M_NODE
, &no_bgp_network_mask_cmd
);
10934 install_element (BGP_IPV4M_NODE
, &no_bgp_network_mask_natural_cmd
);
10935 install_element (BGP_IPV4M_NODE
, &aggregate_address_cmd
);
10936 install_element (BGP_IPV4M_NODE
, &aggregate_address_mask_cmd
);
10937 install_element (BGP_IPV4M_NODE
, &no_aggregate_address_cmd
);
10938 install_element (BGP_IPV4M_NODE
, &no_aggregate_address_mask_cmd
);
10940 /* IPv4 labeled-unicast configuration. */
10941 install_element (BGP_IPV4L_NODE
, &bgp_table_map_cmd
);
10942 install_element (BGP_IPV4L_NODE
, &bgp_network_cmd
);
10943 install_element (BGP_IPV4L_NODE
, &bgp_network_mask_cmd
);
10944 install_element (BGP_IPV4L_NODE
, &bgp_network_mask_natural_cmd
);
10945 install_element (BGP_IPV4L_NODE
, &bgp_network_route_map_cmd
);
10946 install_element (BGP_IPV4L_NODE
, &bgp_network_mask_route_map_cmd
);
10947 install_element (BGP_IPV4L_NODE
, &bgp_network_mask_natural_route_map_cmd
);
10948 install_element (BGP_IPV4L_NODE
, &bgp_network_label_index_cmd
);
10949 install_element (BGP_IPV4L_NODE
, &bgp_network_label_index_route_map_cmd
);
10950 install_element (BGP_IPV4L_NODE
, &no_bgp_table_map_cmd
);
10951 install_element (BGP_IPV4L_NODE
, &no_bgp_network_cmd
);
10952 install_element (BGP_IPV4L_NODE
, &no_bgp_network_mask_cmd
);
10953 install_element (BGP_IPV4L_NODE
, &no_bgp_network_mask_natural_cmd
);
10955 install_element (VIEW_NODE
, &show_ip_bgp_instance_all_cmd
);
10956 install_element (VIEW_NODE
, &show_ip_bgp_cmd
);
10957 install_element (VIEW_NODE
, &show_ip_bgp_route_cmd
);
10958 install_element (VIEW_NODE
, &show_ip_bgp_regexp_cmd
);
10960 install_element (VIEW_NODE
, &show_ip_bgp_instance_neighbor_advertised_route_cmd
);
10961 install_element (VIEW_NODE
, &show_ip_bgp_neighbor_routes_cmd
);
10962 install_element (VIEW_NODE
, &show_ip_bgp_neighbor_received_prefix_filter_cmd
);
10963 #ifdef KEEP_OLD_VPN_COMMANDS
10964 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_route_prefix_cmd
);
10965 #endif /* KEEP_OLD_VPN_COMMANDS */
10966 install_element (VIEW_NODE
, &show_bgp_afi_vpn_rd_route_cmd
);
10967 install_element (VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_all_route_prefix_cmd
);
10969 /* BGP dampening clear commands */
10970 install_element (ENABLE_NODE
, &clear_ip_bgp_dampening_cmd
);
10971 install_element (ENABLE_NODE
, &clear_ip_bgp_dampening_prefix_cmd
);
10973 install_element (ENABLE_NODE
, &clear_ip_bgp_dampening_address_cmd
);
10974 install_element (ENABLE_NODE
, &clear_ip_bgp_dampening_address_mask_cmd
);
10977 install_element (ENABLE_NODE
, &show_ip_bgp_instance_neighbor_prefix_counts_cmd
);
10978 #ifdef KEEP_OLD_VPN_COMMANDS
10979 install_element (ENABLE_NODE
, &show_ip_bgp_vpn_neighbor_prefix_counts_cmd
);
10980 #endif /* KEEP_OLD_VPN_COMMANDS */
10982 /* New config IPv6 BGP commands. */
10983 install_element (BGP_IPV6_NODE
, &bgp_table_map_cmd
);
10984 install_element (BGP_IPV6_NODE
, &ipv6_bgp_network_cmd
);
10985 install_element (BGP_IPV6_NODE
, &ipv6_bgp_network_route_map_cmd
);
10986 install_element (BGP_IPV6_NODE
, &no_bgp_table_map_cmd
);
10987 install_element (BGP_IPV6_NODE
, &no_ipv6_bgp_network_cmd
);
10988 install_element (BGP_IPV6_NODE
, &ipv6_bgp_network_label_index_cmd
);
10989 install_element (BGP_IPV6_NODE
, &no_ipv6_bgp_network_label_index_cmd
);
10990 install_element (BGP_IPV6_NODE
, &ipv6_bgp_network_label_index_route_map_cmd
);
10991 install_element (BGP_IPV6_NODE
, &no_ipv6_bgp_network_label_index_route_map_cmd
);
10993 install_element (BGP_IPV6_NODE
, &ipv6_aggregate_address_cmd
);
10994 install_element (BGP_IPV6_NODE
, &no_ipv6_aggregate_address_cmd
);
10996 install_element (BGP_IPV6M_NODE
, &ipv6_bgp_network_cmd
);
10997 install_element (BGP_IPV6M_NODE
, &no_ipv6_bgp_network_cmd
);
10999 install_element (BGP_IPV6L_NODE
, &bgp_table_map_cmd
);
11000 install_element (BGP_IPV6L_NODE
, &ipv6_bgp_network_cmd
);
11001 install_element (BGP_IPV6L_NODE
, &ipv6_bgp_network_route_map_cmd
);
11002 install_element (BGP_IPV6L_NODE
, &no_bgp_table_map_cmd
);
11003 install_element (BGP_IPV6L_NODE
, &no_ipv6_bgp_network_cmd
);
11005 install_element (BGP_NODE
, &bgp_distance_cmd
);
11006 install_element (BGP_NODE
, &no_bgp_distance_cmd
);
11007 install_element (BGP_NODE
, &bgp_distance_source_cmd
);
11008 install_element (BGP_NODE
, &no_bgp_distance_source_cmd
);
11009 install_element (BGP_NODE
, &bgp_distance_source_access_list_cmd
);
11010 install_element (BGP_NODE
, &no_bgp_distance_source_access_list_cmd
);
11011 install_element (BGP_IPV4_NODE
, &bgp_distance_cmd
);
11012 install_element (BGP_IPV4_NODE
, &no_bgp_distance_cmd
);
11013 install_element (BGP_IPV4_NODE
, &bgp_distance_source_cmd
);
11014 install_element (BGP_IPV4_NODE
, &no_bgp_distance_source_cmd
);
11015 install_element (BGP_IPV4_NODE
, &bgp_distance_source_access_list_cmd
);
11016 install_element (BGP_IPV4_NODE
, &no_bgp_distance_source_access_list_cmd
);
11017 install_element (BGP_IPV4M_NODE
, &bgp_distance_cmd
);
11018 install_element (BGP_IPV4M_NODE
, &no_bgp_distance_cmd
);
11019 install_element (BGP_IPV4M_NODE
, &bgp_distance_source_cmd
);
11020 install_element (BGP_IPV4M_NODE
, &no_bgp_distance_source_cmd
);
11021 install_element (BGP_IPV4M_NODE
, &bgp_distance_source_access_list_cmd
);
11022 install_element (BGP_IPV4M_NODE
, &no_bgp_distance_source_access_list_cmd
);
11023 install_element (BGP_IPV6_NODE
, &bgp_distance_cmd
);
11024 install_element (BGP_IPV6_NODE
, &no_bgp_distance_cmd
);
11025 install_element (BGP_IPV6_NODE
, &ipv6_bgp_distance_source_cmd
);
11026 install_element (BGP_IPV6_NODE
, &no_ipv6_bgp_distance_source_cmd
);
11027 install_element (BGP_IPV6_NODE
, &ipv6_bgp_distance_source_access_list_cmd
);
11028 install_element (BGP_IPV6_NODE
, &no_ipv6_bgp_distance_source_access_list_cmd
);
11029 install_element (BGP_IPV6M_NODE
, &bgp_distance_cmd
);
11030 install_element (BGP_IPV6M_NODE
, &no_bgp_distance_cmd
);
11031 install_element (BGP_IPV6M_NODE
, &ipv6_bgp_distance_source_cmd
);
11032 install_element (BGP_IPV6M_NODE
, &no_ipv6_bgp_distance_source_cmd
);
11033 install_element (BGP_IPV6M_NODE
, &ipv6_bgp_distance_source_access_list_cmd
);
11034 install_element (BGP_IPV6M_NODE
, &no_ipv6_bgp_distance_source_access_list_cmd
);
11036 install_element (BGP_NODE
, &bgp_damp_set_cmd
);
11037 install_element (BGP_NODE
, &bgp_damp_unset_cmd
);
11038 install_element (BGP_IPV4_NODE
, &bgp_damp_set_cmd
);
11039 install_element (BGP_IPV4_NODE
, &bgp_damp_unset_cmd
);
11041 /* IPv4 Multicast Mode */
11042 install_element (BGP_IPV4M_NODE
, &bgp_damp_set_cmd
);
11043 install_element (BGP_IPV4M_NODE
, &bgp_damp_unset_cmd
);
11045 /* Large Communities */
11046 install_element (VIEW_NODE
, &show_ip_bgp_large_community_list_cmd
);
11047 install_element (VIEW_NODE
, &show_ip_bgp_large_community_cmd
);
11051 bgp_route_finish (void)
11056 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
11057 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
11059 bgp_table_unlock (bgp_distance_table
[afi
][safi
]);
11060 bgp_distance_table
[afi
][safi
] = NULL
;