Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-all

*: fix usage of if_lookup_by_name_all_vrf
This commit is contained in:
Russ White 2021-10-27 15:29:39 -04:00 committed by GitHub
commit f727c6ae8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 90 additions and 47 deletions

View File

@ -315,45 +315,28 @@ int bfd_session_enable(struct bfd_session *bs)
vrf = vrf_lookup_by_name(bs->key.vrfname);
if (vrf == NULL) {
zlog_err(
"session-enable: specified VRF doesn't exists.");
"session-enable: specified VRF %s doesn't exists.",
bs->key.vrfname);
return 0;
}
} else {
vrf = vrf_lookup_by_id(VRF_DEFAULT);
}
if (!vrf_is_backend_netns() && vrf && vrf->vrf_id != VRF_DEFAULT
&& !if_lookup_by_name(vrf->name, vrf->vrf_id)) {
zlog_err("session-enable: vrf interface %s not available yet",
vrf->name);
return 0;
}
assert(vrf);
if (bs->key.ifname[0]) {
if (vrf)
ifp = if_lookup_by_name(bs->key.ifname, vrf->vrf_id);
else
ifp = if_lookup_by_name_all_vrf(bs->key.ifname);
if (ifp == NULL) {
zlog_err(
"session-enable: specified interface %s (VRF %s) doesn't exist.",
bs->key.ifname, vrf ? vrf->name : "<all>");
bs->key.ifname, vrf->name);
return 0;
}
if (bs->key.ifname[0] && !vrf) {
vrf = vrf_lookup_by_id(ifp->vrf_id);
if (vrf == NULL) {
zlog_err(
"session-enable: specified VRF %u doesn't exist.",
ifp->vrf_id);
return 0;
}
}
}
/* Assign interface/VRF pointers. */
bs->vrf = vrf;
if (bs->vrf == NULL)
bs->vrf = vrf_lookup_by_id(VRF_DEFAULT);
assert(bs->vrf);
/* Assign interface pointer (if any). */
bs->ifp = ifp;

View File

@ -1688,10 +1688,10 @@ route_match_interface(void *rule, const struct prefix *prefix, void *object)
path = object;
if (!path)
if (!path || !path->peer || !path->peer->bgp)
return RMAP_NOMATCH;
ifp = if_lookup_by_name_all_vrf((char *)rule);
ifp = if_lookup_by_name((char *)rule, path->peer->bgp->vrf_id);
if (ifp == NULL || ifp->ifindex != path->attr->nh_ifindex)
return RMAP_NOMATCH;

View File

@ -3547,7 +3547,7 @@ void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh,
/* create default route with interface <VRF>
* with nexthop-vrf <VRF>
*/
ifp = if_lookup_by_name_all_vrf(vrf->name);
ifp = if_lookup_by_name_vrf(vrf->name, vrf);
if (!ifp)
return;
api_nh->vrf_id = nh->vrf_id;

View File

@ -423,7 +423,7 @@ struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf)
return RB_FIND(if_name_head, &vrf->ifaces_by_name, &if_tmp);
}
struct interface *if_lookup_by_name_all_vrf(const char *name)
static struct interface *if_lookup_by_name_all_vrf(const char *name)
{
struct vrf *vrf;
struct interface *ifp;

View File

@ -526,7 +526,6 @@ size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
struct interface ***result, vrf_id_t vrf_id);
struct vrf;
extern struct interface *if_lookup_by_name_all_vrf(const char *ifname);
extern struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf);
extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id,

View File

@ -953,12 +953,6 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
nhg_hooks.add_nexthop(nhgc, nh);
}
if (intf) {
struct interface *ifp = if_lookup_by_name_all_vrf(intf);
if (ifp)
ifp->configured = true;
}
return CMD_SUCCESS;
}
@ -1265,7 +1259,6 @@ void nexthop_group_interface_state_change(struct interface *ifp,
if (ifp->ifindex != nhop.ifindex)
continue;
ifp->configured = true;
nh = nexthop_new();
memcpy(nh, &nhop, sizeof(nhop));

View File

@ -2041,10 +2041,12 @@ ospf6_routemap_rule_match_interface(void *rule, const struct prefix *prefix,
void *object)
{
struct interface *ifp;
struct ospf6_route *route;
struct ospf6_external_info *ei;
ei = ((struct ospf6_route *)object)->route_option;
ifp = if_lookup_by_name_all_vrf((char *)rule);
route = object;
ei = route->route_option;
ifp = if_lookup_by_name((char *)rule, route->ospf6->vrf_id);
if (ifp != NULL && ei->ifindex == ifp->ifindex)
return RMAP_MATCH;

View File

@ -72,12 +72,13 @@ void ospf_external_route_remove(struct ospf *ospf, struct prefix_ipv4 *p)
}
/* Add an External info for AS-external-LSA. */
struct external_info *ospf_external_info_new(uint8_t type,
struct external_info *ospf_external_info_new(struct ospf *ospf, uint8_t type,
unsigned short instance)
{
struct external_info *new;
new = XCALLOC(MTYPE_OSPF_EXTERNAL_INFO, sizeof(struct external_info));
new->ospf = ospf;
new->type = type;
new->instance = instance;
new->to_be_processed = 0;
@ -138,7 +139,7 @@ ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance,
}
/* Create new External info instance. */
new = ospf_external_info_new(type, instance);
new = ospf_external_info_new(ospf, type, instance);
new->p = p;
new->ifindex = ifindex;
new->nexthop = nexthop;

View File

@ -29,6 +29,8 @@ struct route_map_set_values {
/* Redistributed external information. */
struct external_info {
struct ospf *ospf;
/* Type of source protocol. */
uint8_t type;
@ -107,7 +109,8 @@ struct ospf_external_aggr_rt {
#define OSPF_ASBR_NSSA_REDIST_UPDATE_DELAY 9
extern void ospf_external_route_remove(struct ospf *, struct prefix_ipv4 *);
extern struct external_info *ospf_external_info_new(uint8_t, unsigned short);
extern struct external_info *ospf_external_info_new(struct ospf *, uint8_t,
unsigned short);
extern void ospf_reset_route_map_set_values(struct route_map_set_values *);
extern int ospf_route_map_set_compare(struct route_map_set_values *,
struct route_map_set_values *);

View File

@ -320,7 +320,7 @@ route_match_interface(void *rule, const struct prefix *prefix, void *object)
struct external_info *ei;
ei = object;
ifp = if_lookup_by_name_all_vrf((char *)rule);
ifp = if_lookup_by_name((char *)rule, ei->ospf->vrf_id);
if (ifp == NULL || ifp->ifindex != ei->ifindex)
return RMAP_NOMATCH;

View File

@ -561,14 +561,37 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd,
nhop.vrf_id = vrf->vrf_id;
if (intf) {
struct interface *ifp;
struct interface *ifp = NULL;
struct interface *ifptmp;
struct vrf *vrftmp;
int count = 0;
if (vrf_is_backend_netns() && vrf_name) {
ifp = if_lookup_by_name_vrf(intf, vrf);
} else {
RB_FOREACH (vrftmp, vrf_name_head, &vrfs_by_name) {
ifptmp = if_lookup_by_name_vrf(intf, vrftmp);
if (ifptmp) {
ifp = ifptmp;
count++;
if (!vrf_is_backend_netns())
break;
}
}
}
ifp = if_lookup_by_name_all_vrf(intf);
if (!ifp) {
vty_out(vty, "Specified Intf %s does not exist\n",
intf);
return CMD_WARNING_CONFIG_FAILED;
}
if (count > 1) {
vty_out(vty,
"Specified Intf %s exists in multiple VRFs\n",
intf);
vty_out(vty, "You must specify the nexthop-vrf\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (ifp->vrf_id != vrf->vrf_id) {
struct vrf *actual;

View File

@ -2481,12 +2481,24 @@ DEFPY (show_interface_name_vrf_all,
VRF_ALL_CMD_HELP_STR
JSON_STR)
{
struct interface *ifp;
struct interface *ifp = NULL;
struct interface *ifptmp;
struct vrf *vrf;
json_object *json = NULL;
int count = 0;
interface_update_stats();
ifp = if_lookup_by_name_all_vrf(ifname);
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
ifptmp = if_lookup_by_name_vrf(ifname, vrf);
if (ifptmp) {
ifp = ifptmp;
count++;
if (!vrf_is_backend_netns())
break;
}
}
if (ifp == NULL) {
if (uj)
vty_out(vty, "{}\n");
@ -2494,6 +2506,17 @@ DEFPY (show_interface_name_vrf_all,
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
if (count > 1) {
if (uj) {
vty_out(vty, "{}\n");
} else {
vty_out(vty,
"%% There are multiple interfaces with name %s\n",
ifname);
vty_out(vty, "%% You must specify the VRF name\n");
}
return CMD_WARNING;
}
if (uj)
json = json_object_new_object();

View File

@ -609,7 +609,17 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt)
}
if (strcmp(ZEBRA_PTM_INVALID_PORT_NAME, port_str)) {
ifp = if_lookup_by_name_all_vrf(port_str);
struct vrf *vrf;
int count = 0;
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
ifp = if_lookup_by_name_vrf(ifname, vrf);
if (ifp) {
count++;
if (!vrf_is_backend_netns())
break;
}
}
if (!ifp) {
flog_warn(EC_ZEBRA_UNKNOWN_INTERFACE,
@ -617,6 +627,12 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt)
__func__, port_str);
return -1;
}
if (count > 1) {
flog_warn(EC_ZEBRA_UNKNOWN_INTERFACE,
"%s: multiple interface with name %s",
__func__, port_str);
return -1;
}
}
ptm_lib_find_key_in_msg(in_ctxt, ZEBRA_PTM_CBL_STR, cbl_str);