Skip to content

Commit

Permalink
net: refactor if_clone.c #1
Browse files Browse the repository at this point in the history
* Add ifc_find_cloner()
* Rename current ifc_find_cloner() to ifc_find_cloner_in_vnet()
* Add ifc_find_cloner_match()

This change simplifies the code a bit and reduces the diff to
 the netlink interface cloners merge (D39032).

Reviewed by:	glebius, kp
Differential Revision: https://reviews.freebsd.org/D39046
MFC after:	2 weeks
  • Loading branch information
AlexanderChernikov committed Mar 15, 2023
1 parent 6419b48 commit 83b5c80
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions sys/net/if_clone.c
Expand Up @@ -109,6 +109,8 @@ static int if_clone_createif(struct if_clone *ifc, char *name, size_t len,

static int ifc_simple_match(struct if_clone *ifc, const char *name);
static int ifc_handle_unit(struct if_clone *ifc, char *name, size_t len, int *punit);
static struct if_clone *ifc_find_cloner(const char *name);
static struct if_clone *ifc_find_cloner_match(const char *name);

#ifdef CLONE_COMPAT_13
static int ifc_simple_create_wrapper(struct if_clone *ifc, char *name, size_t maxlen,
Expand Down Expand Up @@ -195,13 +197,7 @@ ifc_create_ifp(const char *name, struct ifc_data *ifd,
int error;

/* Try to find an applicable cloner for this request */
IF_CLONERS_LOCK();
LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
if (ifc->ifc_match(ifc, name))
break;
}
IF_CLONERS_UNLOCK();

ifc = ifc_find_cloner_match(name);
if (ifc == NULL)
return (EINVAL);

Expand Down Expand Up @@ -266,18 +262,41 @@ ifc_unlink_ifp(struct if_clone *ifc, struct ifnet *ifp)
}

static struct if_clone *
ifc_find_cloner(const char *name, struct vnet *vnet)
ifc_find_cloner_match(const char *name)
{
struct if_clone *ifc;

IF_CLONERS_LOCK();
LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
if (ifc->ifc_match(ifc, name))
break;
}
IF_CLONERS_UNLOCK();

return (ifc);
}

static struct if_clone *
ifc_find_cloner(const char *name)
{
struct if_clone *ifc;

CURVNET_SET_QUIET(vnet);
IF_CLONERS_LOCK();
LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
if (strcmp(ifc->ifc_name, name) == 0) {
break;
}
}
IF_CLONERS_UNLOCK();

return (ifc);
}

static struct if_clone *
ifc_find_cloner_in_vnet(const char *name, struct vnet *vnet)
{
CURVNET_SET_QUIET(vnet);
struct if_clone *ifc = ifc_find_cloner(name);
CURVNET_RESTORE();

return (ifc);
Expand Down Expand Up @@ -326,7 +345,7 @@ if_clone_destroy(const char *name)
if (ifp == NULL)
return (ENXIO);

ifc = ifc_find_cloner(ifp->if_dname, ifp->if_home_vnet);
ifc = ifc_find_cloner_in_vnet(ifp->if_dname, ifp->if_home_vnet);
if (ifc == NULL) {
if_rele(ifp);
return (EINVAL);
Expand Down

0 comments on commit 83b5c80

Please sign in to comment.