From nobody Wed Mar 15 13:55:58 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PcBkR2FZrz3yYVf; Wed, 15 Mar 2023 13:55:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PcBkR1jfVz4QsV; Wed, 15 Mar 2023 13:55:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678888559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lBaK6hD7Yw17Smk+jhpYKuYk8kf4mQcYyC/A+3nMmxQ=; b=JuPJUUZoQqikP6rBr9DktUTH55kY71P511nG5igkJ3ZcOwGrYF/VhD1mNoJ8KSaWDG1ttS KnuICbq1HekmBtZw8HvMkVfeirMwbC1aH52MFdYNsshPY7iWy4vErZ9FiThWwDQsGkRdPd Fe8POF816gfuhpKFKpaRNhNmf5sHAj3/MBjHPhmz9Y834YhIzryh+CwgTkQKZDGNgEZRkB JbYdWDUNzNdzs8p++LKHarlaXVrOWdeCAKFgc0ykoU0J1d87qd5M6a1Femzw07iQKXnfo9 HdUBw6gfzctENxR78YJk/N5glYQ6/NHGyacjBG0STUh6n20cIS310MgkgT1kpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678888559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lBaK6hD7Yw17Smk+jhpYKuYk8kf4mQcYyC/A+3nMmxQ=; b=Cb4uBkd7sezINFuF1O9Ctgz/+iHgrFlnbOW8whcgTSPurha1KsqguA66LbUpt2rAVu2guZ 3b9M5Is5ynrLqSqZ45M7W08vWeQhr7wKKhRDuTEyzOL1a6d/Gr8ZxHF1lmLDq38lhzyuPv 33+xE1b8HhCFFq0CP/0x7AIz56ohEPEoHIS+3477mZ5tefM1EG4iBVpTqGcQAuNmaBEOFe jOK3EbfjpzPZBILN6Nr9ulWiN8F+WuTeRgPEBRd8bcyVfe4HDFxXSaJlfhLSfxHD/5vuvP N8huQYiaEdTJEsuraEwmAzGI7Auo9ZWcw/YXT+/jJW86qKP5eIjPFB1UhtZ/JA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678888559; a=rsa-sha256; cv=none; b=HZpr9BzL3wTEU4dfOmSkT3p/C0nOGT1XC1aWU+5qKQzP+79VDquxOaVpamZvVMpquGO/jo xUGpk/LYycehT04XuzzntRyen6ad/RBX2otmeXi3vIf3XPEGDK7LQqCdf7ZV1ZMk1fXv6P AAE9VvlhbNGq8NPICeQpdfSgbjO3kOWHm+ToEiAnWHh5RqFZHxRzxXfux87tRXzNQ7mGow LjLT0bva2iFZ6ukQfZL93nD1Lr3t9HLqnLBcb5pa5eFo5nvlhehXaIoFgvrcEl4IdTRFV/ cU4cnbIRf97GuEHmgtcNOBUODffAF7u47RYCpI15HcFWtb01X2pV2kgGrMzNEQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PcBkR0RPfz1JMf; Wed, 15 Mar 2023 13:55:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32FDtw2r078579; Wed, 15 Mar 2023 13:55:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32FDtw0e078577; Wed, 15 Mar 2023 13:55:58 GMT (envelope-from git) Date: Wed, 15 Mar 2023 13:55:58 GMT Message-Id: <202303151355.32FDtw0e078577@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 83b5c80c6923 - main - net: refactor if_clone.c #1 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 83b5c80c69232da4254250fcd94b2d377356acd7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=83b5c80c69232da4254250fcd94b2d377356acd7 commit 83b5c80c69232da4254250fcd94b2d377356acd7 Author: Alexander V. Chernikov AuthorDate: 2023-03-13 10:41:58 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-03-15 13:54:22 +0000 net: refactor if_clone.c #1 * 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 --- sys/net/if_clone.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 7dcb3c271e42..59d60645cb89 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -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, @@ -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); @@ -266,11 +262,25 @@ 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) { @@ -278,6 +288,15 @@ ifc_find_cloner(const char *name, struct vnet *vnet) } } 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); @@ -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);