bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
bgp = bgp_get_default();
- if (bgp == NULL) {
+
+ if (bgp == NULL || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "No BGP process is configured\n");
return CMD_WARNING;
}
bool is_vrf_leak_bind;
int debug;
- if (from_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
+ if (from_bgp->inst_type != BGP_INSTANCE_TYPE_VRF &&
+ from_bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
return;
debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
struct bgp_path_info_pair old_and_new;
int debug = 0;
- if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
+ /*
+ * For default bgp instance, which is deleted i.e. marked hidden
+ * we are skipping SAFI_MPLS_VPN route table deletion
+ * in bgp_cleanup_routes.
+ * So, we need to delete routes from VPNV4 table.
+ * Here for !IS_BGP_INSTANCE_HIDDEN,
+ * !(SAFI_MPLS_VPN && AF_IP/AF_IP6),
+ * we ignore the event for the prefix.
+ */
+ if (BGP_INSTANCE_HIDDEN_DELETE_IN_PROGRESS(bgp, afi, safi)) {
if (dest)
debug = bgp_debug_bestpath(dest);
if (debug)
if (afi != AFI_L2VPN) {
safi_t safi;
safi = SAFI_MPLS_VPN;
- for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
- dest = bgp_route_next(dest)) {
- table = bgp_dest_get_bgp_table_info(dest);
- if (table != NULL) {
- bgp_cleanup_table(bgp, table, afi, safi);
- bgp_table_finish(&table);
- bgp_dest_set_bgp_table_info(dest, NULL);
- dest = bgp_dest_unlock_node(dest);
-
- assert(dest);
+ if (!IS_BGP_INSTANCE_HIDDEN(bgp)) {
+ for (dest = bgp_table_top(bgp->rib[afi][safi]);
+ dest; dest = bgp_route_next(dest)) {
+ table = bgp_dest_get_bgp_table_info(
+ dest);
+ if (table != NULL) {
+ bgp_cleanup_table(bgp, table,
+ afi, safi);
+ bgp_table_finish(&table);
+ bgp_dest_set_bgp_table_info(dest,
+ NULL);
+ dest = bgp_dest_unlock_node(
+ dest);
+ assert(dest);
+ }
}
}
safi = SAFI_ENCAP;
bgp = bgp_get_default();
}
- if (bgp == NULL) {
+ if (bgp == NULL || IS_BGP_INSTANCE_HIDDEN(bgp)) {
if (!use_json)
vty_out(vty, "No BGP process is configured\n");
else
vty_out(vty, "{\n");
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ continue;
route_output = true;
if (use_json) {
if (!is_first)
{
if (!bgp) {
bgp = bgp_get_default();
- if (!bgp) {
+ if (!bgp || IS_BGP_INSTANCE_HIDDEN(bgp)) {
if (!use_json)
vty_out(vty, "No BGP process is configured\n");
else
int idx = 0;
char *network = NULL;
struct bgp *bgp = bgp_get_default();
- if (!bgp) {
+ if (!bgp || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "Can't find default instance\n");
return CMD_WARNING;
}
/* BGP structure lookup. */
if (view_name) {
bgp = bgp_lookup_by_name(view_name);
- if (bgp == NULL) {
+ if (bgp == NULL || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "%% Can't find BGP instance %s\n",
view_name);
return CMD_WARNING;
switch (ret) {
case BGP_SUCCESS:
case BGP_CREATED:
+ case BGP_INSTANCE_EXISTS:
case BGP_GR_NO_OPERATION:
break;
case BGP_ERR_INVALID_VALUE:
seq = strtoul(argv[7]->arg, NULL, 10);
bgp = bgp_get_default();
- if (!bgp) {
+ if (!bgp || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "Default BGP instance is not there\n");
return CMD_WARNING;
}
memset(&ip, 0, sizeof(ip));
bgp = bgp_get_default();
- if (!bgp) {
+ if (!bgp || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "Default BGP instance is not there\n");
return CMD_WARNING;
}
if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
vpn_leak_postchange_all();
- if (inst_type == BGP_INSTANCE_TYPE_VRF)
+ if (inst_type == BGP_INSTANCE_TYPE_VRF ||
+ IS_BGP_INSTANCE_HIDDEN(bgp)) {
bgp_vpn_leak_export(bgp);
+ UNSET_FLAG(bgp->flags, BGP_FLAG_INSTANCE_HIDDEN);
+ UNSET_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS);
+ }
/* Pending: handle when user tries to change a view to vrf n vv.
*/
/* for pre-existing bgp instance,
argv[idx_asn]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
- if (argc > 4) {
+ if (argc > 4 && strncmp(argv[4]->arg, "vrf", 3) == 0) {
name = argv[idx_vrf]->arg;
if (strmatch(argv[idx_vrf - 1]->text, "vrf")
&& strmatch(name, VRF_DEFAULT_NAME))
bgp_default = bgp_get_default();
if (!bgp_default) {
int32_t ret;
- as_t as = bgp->as;
+ as_t as = AS_UNSPECIFIED;
- /* Auto-create assuming the same AS */
+ /* Auto-create with AS_UNSPECIFIED, to be filled in later */
ret = bgp_get_vty(&bgp_default, &as, NULL,
BGP_INSTANCE_TYPE_DEFAULT, NULL,
ASNOTATION_UNDEFINED);
"VRF default is not configured as a bgp instance\n");
return CMD_WARNING;
}
+
+ SET_FLAG(bgp_default->flags, BGP_FLAG_INSTANCE_HIDDEN);
}
vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bgp_default = bgp_get_default();
if (!bgp_default) {
- /* Auto-create assuming the same AS */
+ as = AS_UNSPECIFIED;
+
+ /* Auto-create with AS_UNSPECIFIED, to be filled in later */
ret = bgp_get_vty(&bgp_default, &as, NULL,
BGP_INSTANCE_TYPE_DEFAULT, NULL,
ASNOTATION_UNDEFINED);
"VRF default is not configured as a bgp instance\n");
return CMD_WARNING;
}
+
+ SET_FLAG(bgp_default->flags, BGP_FLAG_INSTANCE_HIDDEN);
}
vrf_bgp = bgp_lookup_by_name(import_name);
if (strcmp(import_name, VRF_DEFAULT_NAME) == 0) {
vrf_bgp = bgp_default;
} else {
- /* Auto-create assuming the same AS */
+ as = AS_UNSPECIFIED;
+
+ /* Auto-create with AS_UNSPECIFIED, fill in later */
ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
NULL, ASNOTATION_UNDEFINED);
+ if (ret) {
+ vty_out(vty,
+ "VRF %s is not configured as a bgp instance\n",
+ import_name);
+ return CMD_WARNING;
+ }
+
+ SET_FLAG(vrf_bgp->flags, BGP_FLAG_INSTANCE_HIDDEN);
/* Auto created VRF instances should be marked
* properly, otherwise we have a state after bgpd
else
bgp = bgp_get_default();
- if (!bgp) {
+ if (!bgp || IS_BGP_INSTANCE_HIDDEN(bgp)) {
vty_out(vty, "%% No BGP process is configured\n");
return CMD_WARNING;
}
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
continue;
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ continue;
+
nbr_output = true;
if (use_json) {
if (!is_first)
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
continue;
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ continue;
+
nbr_output = true;
if (use_json) {
if (!(json = json_object_new_object())) {
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
continue;
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ continue;
+
if (!uj)
vty_out(vty, "\nInstance %s:\n",
(bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
struct bgp *bgp;
bgp = bgp_get_default();
- if (bgp)
+ if (bgp && !IS_BGP_INSTANCE_HIDDEN(bgp))
update_group_show_stats(bgp, vty);
return CMD_SUCCESS;
char *addr;
bool flag_scomm, flag_secomm, flag_slcomm;
+ /* skip hidden default vrf bgp instance */
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ return;
+
/* Skip dynamic neighbors. */
if (peer_dynamic_neighbor(peer))
return;
struct peer_group *group;
struct listnode *node, *nnode;
+ /* skip hidden default vrf bgp instance */
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ return;
vty_frame(vty, " !\n address-family ");
if (afi == AFI_IP) {
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
continue;
+ /* skip hidden default vrf bgp instance */
+ if (IS_BGP_INSTANCE_HIDDEN(bgp))
+ continue;
+
/* Router bgp ASN */
vty_out(vty, "router bgp %s", bgp->as_pretty);
static struct bgp *bgp_create(as_t *as, const char *name,
enum bgp_instance_type inst_type,
const char *as_pretty,
- enum asnotation_mode asnotation)
+ enum asnotation_mode asnotation,
+ struct bgp *bgp_old, bool hidden)
{
struct bgp *bgp;
afi_t afi;
safi_t safi;
+ if (hidden) {
+ bgp = bgp_old;
+ goto peer_init;
+ }
+
bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp));
bgp->as = *as;
if (as_pretty)
bgp->peer_self->domainname =
XSTRDUP(MTYPE_BGP_PEER_HOST, cmd_domainname_get());
bgp->peer = list_new();
+
+peer_init:
bgp->peer->cmp = (int (*)(void *, void *))peer_cmp;
bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_same,
"BGP Peer Hash");
bgp->peerhash->max_size = BGP_PEER_MAX_HASH_SIZE;
- bgp->group = list_new();
+ if (!hidden)
+ bgp->group = list_new();
bgp->group->cmp = (int (*)(void *, void *))peer_group_cmp;
FOREACH_AFI_SAFI (afi, safi) {
- bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi);
- bgp->aggregate[afi][safi] = bgp_table_init(bgp, afi, safi);
- bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi);
+ if (!hidden) {
+ bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi);
+ bgp->aggregate[afi][safi] = bgp_table_init(bgp, afi,
+ safi);
+ bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi);
+ }
/* Enable maximum-paths */
bgp_maximum_paths_set(bgp, afi, safi, BGP_PEER_EBGP,
bgp->rmap_def_originate_eval_timer = 0;
#ifdef ENABLE_BGP_VNC
- if (inst_type != BGP_INSTANCE_TYPE_VRF) {
+ if (inst_type != BGP_INSTANCE_TYPE_VRF && !hidden) {
bgp->rfapi = bgp_rfapi_new(bgp);
assert(bgp->rfapi);
assert(bgp->rfapi_cfg);
bgp->vpn_policy[afi].import_vrf = list_new();
bgp->vpn_policy[afi].import_vrf->del =
bgp_vrf_string_name_delete;
- bgp->vpn_policy[afi].export_vrf = list_new();
- bgp->vpn_policy[afi].export_vrf->del =
- bgp_vrf_string_name_delete;
+ if (!hidden) {
+ bgp->vpn_policy[afi].export_vrf = list_new();
+ bgp->vpn_policy[afi].export_vrf->del =
+ bgp_vrf_string_name_delete;
+ }
SET_FLAG(bgp->af_flags[afi][SAFI_MPLS_VPN],
BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
}
bgp->restart_time, &bgp->t_startup);
/* printable name we can use in debug messages */
- if (inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
+ if (inst_type == BGP_INSTANCE_TYPE_DEFAULT && !hidden) {
bgp->name_pretty = XSTRDUP(MTYPE_BGP_NAME, "VRF default");
} else {
const char *n;
bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
bgp->default_af[AFI_IP][SAFI_UNICAST] = true;
- QOBJ_REG(bgp, bgp);
+ if (!hidden)
+ QOBJ_REG(bgp, bgp);
update_bgp_group_init(bgp);
- /* assign a unique rd id for auto derivation of vrf's RD */
- bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id);
+ if (!hidden) {
+ /* assign a unique rd id for auto derivation of vrf's RD */
+ bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id);
- bgp_evpn_init(bgp);
- bgp_evpn_vrf_es_init(bgp);
- bgp_pbr_init(bgp);
- bgp_srv6_init(bgp);
+ bgp_evpn_init(bgp);
+ bgp_evpn_vrf_es_init(bgp);
+ bgp_pbr_init(bgp);
+ bgp_srv6_init(bgp);
+ }
/*initilize global GR FSM */
bgp_global_gr_init(bgp);
return bgp_check_main_socket(create, bgp);
}
-int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, const char *name,
+int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as,
+ const char *as_pretty,
+ enum asnotation_mode asnotation, const char *name,
enum bgp_instance_type inst_type)
{
struct bgp *bgp;
+ struct peer *peer = NULL;
+ struct listnode *node, *nnode;
+ bool hidden = false;
/* Multiple instance check. */
if (name)
bgp = bgp_get_default();
if (bgp) {
- *bgp_val = bgp;
+ if (IS_BGP_INSTANCE_HIDDEN(bgp) && *as != AS_UNSPECIFIED)
+ hidden = true;
+ /* Handle AS number change */
if (bgp->as != *as) {
- *as = bgp->as;
- return BGP_ERR_AS_MISMATCH;
+ if (hidden)
+ bgp_create(as, name, inst_type, as_pretty,
+ asnotation, bgp, hidden);
+
+ /* Set all peer's local as number with this ASN */
+ for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer))
+ peer->local_as = *as;
+ UNSET_FLAG(bgp->flags, BGP_FLAG_INSTANCE_HIDDEN);
+ *bgp_val = bgp;
+ return BGP_INSTANCE_EXISTS;
}
if (bgp->inst_type != inst_type)
return BGP_ERR_INSTANCE_MISMATCH;
- return BGP_SUCCESS;
+ if (hidden)
+ bgp_create(as, name, inst_type, as_pretty, asnotation,
+ bgp, hidden);
+ *bgp_val = bgp;
+ return BGP_INSTANCE_EXISTS;
}
*bgp_val = NULL;
struct vrf *vrf = NULL;
int ret = 0;
- ret = bgp_lookup_by_as_name_type(bgp_val, as, name, inst_type);
+ ret = bgp_lookup_by_as_name_type(bgp_val, as, as_pretty, asnotation,
+ name, inst_type);
if (ret || *bgp_val)
return ret;
- bgp = bgp_create(as, name, inst_type, as_pretty, asnotation);
+ bgp = bgp_create(as, name, inst_type, as_pretty, asnotation, NULL,
+ false);
/*
* view instances will never work inside of a vrf
bgp_damp_disable(bgp, afi, safi);
}
+ if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT &&
+ (bgp_table_top(bgp->rib[AFI_IP][SAFI_MPLS_VPN]) ||
+ bgp_table_top(bgp->rib[AFI_IP6][SAFI_MPLS_VPN]))) {
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug(
+ "Marking the deleting default bgp instance as hidden");
+ SET_FLAG(bgp->flags, BGP_FLAG_INSTANCE_HIDDEN);
+ }
+
if (BGP_DEBUG(zebra, ZEBRA)) {
if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
zlog_debug("Deleting Default VRF");
peer_delete(peer);
}
- if (bgp->peer_self) {
+ if (bgp->peer_self && !IS_BGP_INSTANCE_HIDDEN(bgp)) {
peer_delete(bgp->peer_self);
bgp->peer_self = NULL;
}
/* TODO - Other memory may need to be freed - e.g., NHT */
#ifdef ENABLE_BGP_VNC
- rfapi_delete(bgp);
+ if (!IS_BGP_INSTANCE_HIDDEN(bgp))
+ rfapi_delete(bgp);
#endif
/* Free memory allocated with aggregate address configuration. */
}
/* Deregister from Zebra, if needed */
- if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) {
+ if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp) && !IS_BGP_INSTANCE_HIDDEN(bgp)) {
if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug(
"%s: deregistering this bgp %s instance from zebra",
bgp_zebra_instance_deregister(bgp);
}
- /* Remove visibility via the master list - there may however still be
- * routes to be processed still referencing the struct bgp.
- */
- listnode_delete(bm->bgp, bgp);
-
- /* Free interfaces in this instance. */
- bgp_if_finish(bgp);
+ if (!IS_BGP_INSTANCE_HIDDEN(bgp)) {
+ /* Remove visibility via the master list -
+ * there may however still be routes to be processed
+ * still referencing the struct bgp.
+ */
+ listnode_delete(bm->bgp, bgp);
+ /* Free interfaces in this instance. */
+ bgp_if_finish(bgp);
+ }
vrf = bgp_vrf_lookup_by_instance_type(bgp);
bgp_handle_socket(bgp, vrf, VRF_UNKNOWN, false);
- if (vrf)
+ if (vrf && !IS_BGP_INSTANCE_HIDDEN(bgp))
bgp_vrf_unlink(bgp, vrf);
/* Update EVPN VRF pointer */
work_queue_free_and_null(&bgp->process_queue);
event_master_free_unused(bm->master);
- bgp_unlock(bgp); /* initial reference */
+
+ if (!IS_BGP_INSTANCE_HIDDEN(bgp))
+ bgp_unlock(bgp); /* initial reference */
+ else {
+ for (afi = AFI_IP; afi < AFI_MAX; afi++) {
+ enum vpn_policy_direction dir;
+
+ if (bgp->vpn_policy[afi].import_vrf)
+ list_delete(&bgp->vpn_policy[afi].import_vrf);
+
+ dir = BGP_VPN_POLICY_DIR_FROMVPN;
+ if (bgp->vpn_policy[afi].rtlist[dir])
+ ecommunity_free(
+ &bgp->vpn_policy[afi].rtlist[dir]);
+ }
+ }
return 0;
}
#define BGP_FLAG_ENFORCE_FIRST_AS (1ULL << 36)
#define BGP_FLAG_DYNAMIC_CAPABILITY (1ULL << 37)
#define BGP_FLAG_VNI_DOWN (1ULL << 38)
+#define BGP_FLAG_INSTANCE_HIDDEN (1ULL << 39)
/* BGP default address-families.
* New peers inherit enabled afi/safis from bgp instance.
enum bgp_create_error_code {
BGP_SUCCESS = 0,
BGP_CREATED = 1,
+ BGP_INSTANCE_EXISTS = 2,
BGP_ERR_INVALID_VALUE = -1,
BGP_ERR_INVALID_FLAG = -2,
BGP_ERR_INVALID_AS = -3,
extern struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,
const char *ip_str, bool use_json);
extern int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as,
+ const char *as_pretty,
+ enum asnotation_mode asnotation,
const char *name,
enum bgp_instance_type inst_type);
/* clang-format on */
#endif
+/* Macro to check if default bgp instance is hidden */
+#define IS_BGP_INSTANCE_HIDDEN(_bgp) \
+ (CHECK_FLAG(_bgp->flags, BGP_FLAG_INSTANCE_HIDDEN) && \
+ (_bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT || \
+ _bgp->inst_type == BGP_INSTANCE_TYPE_VRF))
+
+/* Macro to check if bgp instance delete in-progress and !hidden */
+#define BGP_INSTANCE_HIDDEN_DELETE_IN_PROGRESS(_bgp, _afi, _safi) \
+ (CHECK_FLAG(_bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) && \
+ !IS_BGP_INSTANCE_HIDDEN(_bgp) && \
+ !(_afi == AFI_IP && _safi == SAFI_MPLS_VPN) && \
+ !(_afi == AFI_IP6 && _safi == SAFI_MPLS_VPN))
+
#endif /* _QUAGGA_BGPD_H */