Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: Auto vrf instance (backports) #17983

Open
wants to merge 3 commits into
base: stable/10.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bgpd/bgp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int bgp_vrf_disable(struct vrf *vrf)
if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug("VRF disable %s id %d", vrf->name, vrf->vrf_id);

bgp = bgp_lookup_by_name(vrf->name);
bgp = bgp_lookup_by_name_filter(vrf->name, false);
if (bgp) {

vpn_leak_zebra_vrf_label_withdraw(bgp, AFI_IP);
Expand Down
20 changes: 11 additions & 9 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,13 +1507,12 @@ DEFUN_NOSH (router_bgp,
int idx_asn = 2;
int idx_view_vrf = 3;
int idx_vrf = 4;
int is_new_bgp = 0;
int idx_asnotation = 3;
int idx_asnotation_kind = 4;
enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
int ret;
as_t as;
struct bgp *bgp;
struct bgp *bgp = NULL;
const char *name = NULL;
enum bgp_instance_type inst_type;

Expand Down Expand Up @@ -1575,11 +1574,14 @@ DEFUN_NOSH (router_bgp,
asnotation = ASNOTATION_PLAIN;
}

if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
is_new_bgp = (bgp_lookup(as, name) == NULL);

ret = bgp_get_vty(&bgp, &as, name, inst_type,
argv[idx_asn]->arg, asnotation);
ret = bgp_lookup_by_as_name_type(&bgp, &as, argv[idx_asn]->arg, asnotation, name,
inst_type, true);
if (bgp && ret == BGP_INSTANCE_EXISTS)
ret = CMD_SUCCESS;
else if (bgp == NULL && ret == CMD_SUCCESS)
/* SUCCESS and bgp is NULL */
ret = bgp_get_vty(&bgp, &as, name, inst_type, argv[idx_asn]->arg,
asnotation);
switch (ret) {
case BGP_ERR_AS_MISMATCH:
vty_out(vty, "BGP is already running; AS is %s\n",
Expand All @@ -1599,7 +1601,7 @@ DEFUN_NOSH (router_bgp,
* any pending VRF-VPN leaking that was configured via
* earlier "router bgp X vrf FOO" blocks.
*/
if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
if (bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
vpn_leak_postchange_all();

if (inst_type == BGP_INSTANCE_TYPE_VRF ||
Expand Down Expand Up @@ -10554,7 +10556,7 @@ DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
SET_FLAG(bgp_default->flags, BGP_FLAG_INSTANCE_HIDDEN);
}

vrf_bgp = bgp_lookup_by_name(import_name);
vrf_bgp = bgp_lookup_by_name_filter(import_name, false);
if (!vrf_bgp) {
if (strcmp(import_name, VRF_DEFAULT_NAME) == 0) {
vrf_bgp = bgp_default;
Expand Down
24 changes: 14 additions & 10 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3671,13 +3671,13 @@ struct bgp *bgp_lookup(as_t as, const char *name)
}

/* Lookup BGP structure by view name. */
struct bgp *bgp_lookup_by_name(const char *name)
struct bgp *bgp_lookup_by_name_filter(const char *name, bool filter_auto)
{
struct bgp *bgp;
struct listnode *node, *nnode;

for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
if (filter_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
continue;
if ((bgp->name == NULL && name == NULL)
|| (bgp->name && name && strcmp(bgp->name, name) == 0))
Expand All @@ -3686,6 +3686,11 @@ struct bgp *bgp_lookup_by_name(const char *name)
return NULL;
}

struct bgp *bgp_lookup_by_name(const char *name)
{
return bgp_lookup_by_name_filter(name, true);
}

/* Lookup BGP instance based on VRF id. */
/* Note: Only to be used for incoming messages from Zebra. */
struct bgp *bgp_lookup_by_vrf_id(vrf_id_t vrf_id)
Expand Down Expand Up @@ -3771,10 +3776,9 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id,
return bgp_check_main_socket(create, bgp);
}

int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as,
const char *as_pretty,
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)
enum bgp_instance_type inst_type, bool force_config)
{
struct bgp *bgp;
struct peer *peer = NULL;
Expand All @@ -3783,7 +3787,7 @@ int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as,

/* Multiple instance check. */
if (name)
bgp = bgp_lookup_by_name(name);
bgp = bgp_lookup_by_name_filter(name, !force_config);
else
bgp = bgp_get_default();

Expand All @@ -3793,15 +3797,16 @@ int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as,
/* Handle AS number change */
if (bgp->as != *as) {
if (hidden || CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
if (hidden) {
if (force_config == false && hidden) {
bgp_create(as, name, inst_type,
as_pretty, asnotation, bgp,
hidden);
UNSET_FLAG(bgp->flags,
BGP_FLAG_INSTANCE_HIDDEN);
} else {
bgp->as = *as;
UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
if (force_config == false)
UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
}

/* Set all peer's local AS with this ASN */
Expand Down Expand Up @@ -3838,8 +3843,7 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
struct vrf *vrf = NULL;
int ret = 0;

ret = bgp_lookup_by_as_name_type(bgp_val, as, as_pretty, asnotation,
name, inst_type);
ret = bgp_lookup_by_as_name_type(bgp_val, as, as_pretty, asnotation, name, inst_type, false);
if (ret || *bgp_val)
return ret;

Expand Down
9 changes: 4 additions & 5 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,7 @@ extern void bgp_zclient_reset(void);
extern struct bgp *bgp_get_default(void);
extern struct bgp *bgp_lookup(as_t, const char *);
extern struct bgp *bgp_lookup_by_name(const char *);
extern struct bgp *bgp_lookup_by_name_filter(const char *name, bool filter_auto);
extern struct bgp *bgp_lookup_by_vrf_id(vrf_id_t);
extern struct bgp *bgp_get_evpn(void);
extern void bgp_set_evpn(struct bgp *bgp);
Expand Down Expand Up @@ -2828,11 +2829,9 @@ extern struct peer *peer_new(struct bgp *bgp);

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);
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, bool force_config);

/* Hooks */
DECLARE_HOOK(bgp_vrf_status_changed, (struct bgp *bgp, struct interface *ifp),
Expand Down
Loading