From: Chirag Shah Date: Thu, 6 Aug 2020 18:18:42 +0000 (-0700) Subject: zebra: fix crash in vrf-vni mapping X-Git-Tag: base_7.5~95^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F6874%2Fhead;p=mirror%2Ffrr.git zebra: fix crash in vrf-vni mapping As part of PR 6758 vrf vni converted to transactional cli. Handle a scenario where vrf is not created yet (inactive) and vni is mapped to the inactive vrf. Testing Done: bharat(config-vrf)# do show vrf vrf vrf1 id 11 table 1001 vrf vrf5 inactive (configured) bharat(config)# vrf vrf5 bharat(config-vrf)# vni 5005 bharat(config-vrf)# do show vrf vni VRF VNI VxLAN IF L3-SVI State Rmac vrf5 5005 None None Down None bharat(config-vrf)# no vni 5005 bharat(config-vrf)# do show vrf vni VRF VNI VxLAN IF L3-SVI State Rmac Signed-off-by: Chirag Shah --- diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index e4501273bd..b4ed910b4d 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -1204,12 +1204,14 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) switch (args->event) { case NB_EV_PREPARE: case NB_EV_ABORT: - break; + return NB_OK; case NB_EV_VALIDATE: zvrf_evpn = zebra_vrf_get_evpn(); - if (!zvrf_evpn) + if (!zvrf_evpn) { + snprintf(args->errmsg, args->errmsg_len, + "evpn vrf is not present."); return NB_ERR_VALIDATION; - + } vni = yang_dnode_get_uint32(args->dnode, NULL); /* Get vrf info from parent node, reject configuration * if zebra vrf already mapped to different vni id. @@ -1217,10 +1219,16 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) pn_dnode = yang_dnode_get_parent(args->dnode, "vrf"); if (pn_dnode) { vrfname = yang_dnode_get_string(pn_dnode, "./name"); - vrf = vrf_lookup_by_name(vrfname); - zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + zvrf = zebra_vrf_lookup_by_name(vrfname); + if (!zvrf) { + snprintf(args->errmsg, args->errmsg_len, + "zebra vrf info not found for vrf:%s.", + vrfname); + return NB_ERR_VALIDATION; + } if (zvrf->l3vni && zvrf->l3vni != vni) { - zlog_debug( + snprintf( + args->errmsg, args->errmsg_len, "vni %u cannot be configured as vni %u is already configured under the vrf", vni, zvrf->l3vni); return NB_ERR_VALIDATION; @@ -1230,10 +1238,8 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) /* Check if this VNI is already present in the system */ zl3vni = zl3vni_lookup(vni); if (zl3vni) { - if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "VNI %u is already configured as L3-VNI", - vni); + snprintf(args->errmsg, args->errmsg_len, + "VNI %u is already configured as L3-VNI", vni); return NB_ERR_VALIDATION; } @@ -1241,7 +1247,7 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) case NB_EV_APPLY: vrf = nb_running_get_entry(args->dnode, NULL, true); - zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + zvrf = zebra_vrf_lookup_by_name(vrf->name); vni = yang_dnode_get_uint32(args->dnode, NULL); /* Note: This covers lib_vrf_zebra_prefix_only_modify() config * along with l3vni config @@ -1252,7 +1258,8 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) pfx_only ? 1 : 0, 1) != 0) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( + snprintf( + args->errmsg, args->errmsg_len, "vrf vni %u mapping failed with error: %s", vni, err); return NB_ERR; @@ -1279,17 +1286,21 @@ int lib_vrf_zebra_l3vni_id_destroy(struct nb_cb_destroy_args *args) case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_VALIDATE: - break; + return NB_OK; case NB_EV_APPLY: vrf = nb_running_get_entry(args->dnode, NULL, true); - zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + zvrf = zebra_vrf_lookup_by_name(vrf->name); vni = yang_dnode_get_uint32(args->dnode, NULL); if (!zl3vni_lookup(vni)) return NB_OK; - if (zvrf->l3vni != vni) + if (zvrf->l3vni != vni) { + snprintf(args->errmsg, args->errmsg_len, + "vrf %s has different vni %u mapped", + vrf->name, zvrf->l3vni); return NB_ERR; + } if (is_l3vni_for_prefix_routes_only(zvrf->l3vni)) filter = 1; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 2ea04eee2e..6390b30f5a 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2434,7 +2434,7 @@ DEFUN (no_vrf_vni_mapping, int filter = 0; ZEBRA_DECLVAR_CONTEXT(vrf, zvrf); - vni_t vni = strtoul(argv[1]->arg, NULL, 10); + vni_t vni = strtoul(argv[2]->arg, NULL, 10); assert(vrf); assert(zvrf);