From nobody Sat Sep 24 20:14:48 2022 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 4MZgGw2yp0z4dRDC; Sat, 24 Sep 2022 20:14:48 +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 4MZgGw2QKNz3cpg; Sat, 24 Sep 2022 20:14:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664050488; 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=OWEygKqBxKC0nOW32t7NAYe9IKbIK4PWKx8I0skE7Sg=; b=LB++sxPqYUHcfPU+vhe8GCfxb2Bd/A62On6xxjJ9bUTWQoVodPHFfw40CP//HywtfQsWSk mFKHNF/mJ1Q0mpiyxp+p5ERacWvnivSfkdowFD2yomqfoZVtKL6M99k/9G3eQuo04EGVO4 Ynrog6ozpt4WAVb6Oyg9EklLmAmysX1CNasfXSo8eI7ulAg8OZkMpwDJZ9rB2Hr7YSbiRf TCd9DuCsfmAH7TKXWqdAuCHsvtPheYqJDvy1uRcWDbSXpzY0xks+b011wNxoztYb43yiDc H+5Q8ri9tCy2xRPQldr+RrSiCv2yl54QhrDBhr7Ob9R+QtTBULfX6iMKqLEQ/g== 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 4MZgGw1Rg1z1BK6; Sat, 24 Sep 2022 20:14:48 +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 28OKEmJR018909; Sat, 24 Sep 2022 20:14:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28OKEmTQ018908; Sat, 24 Sep 2022 20:14:48 GMT (envelope-from git) Date: Sat, 24 Sep 2022 20:14:48 GMT Message-Id: <202209242014.28OKEmTQ018908@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: 26c190d2802e - main - if_clone: add ifc_link_ifp() / ifc_unlink_ifp() to the KPI 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: 26c190d2802ebc17563c8fc467c8bb74eab6a2d9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664050488; 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=OWEygKqBxKC0nOW32t7NAYe9IKbIK4PWKx8I0skE7Sg=; b=F+xh3dSsWFoGYgCMP5lvj64L2U5gDO7PhiPdrzaJnCthzdrTtwmzNSz+xniWgnfJfZLxJn K4CBG4y/gkBglNWN4OP6WI/r+/Lj3IUpj7pWc3iF+gyIwW3j1to1eaHIMU0N69UH8UEtmW HzkmEtYwFJP5IuP+Yh4SMcz8rQY1QSfJe6Gt/FCe+J0APgnH3qDoufwDqDK1X7y7A9b6F6 se7tGYAhAd92Nky8eOqqFmnxkz6UtLyswkN+yJXkQX2quET+NLvZnq7PjADywF8MSATqMi 9XTog8TlFL8CQ1wJf41EU1zbR2Q0oofuEgjr6NqaPN2s0wqqtmOogL6nhkhcrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664050488; a=rsa-sha256; cv=none; b=VFN9LDoiaz1oaZ8cfBR4Z0ZvK3vaxtKpS25CkETeCo49HF0BXbKMGQH24E5aUkVLbwvZQR bYYecuQMAs7Vk5A8lEUR4Ueluwc6EthwlsHOiZfwj6Y/Jm+8/JI0+crr8f55E9/yiED0FD vussrPNcgW9RgowdtGusiZmf0+CUoakdcDkah/xIz5saGaWbPrkirnwfJA1UqeEOLeuWuq 8C2uHkoyFdmo9pmD3D6yMgf0pgMNxokaWF3dI3tCjHQ1Hz9JlW805bzAOpMVBWddOFrbA+ cTyC0eNv1n91OGGCGMvuBNgulCQbX7EHirOWdq7ETwDbTN1sYgrzwscRoZLpYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=26c190d2802ebc17563c8fc467c8bb74eab6a2d9 commit 26c190d2802ebc17563c8fc467c8bb74eab6a2d9 Author: Alexander V. Chernikov AuthorDate: 2022-09-24 19:17:27 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-09-24 19:42:42 +0000 if_clone: add ifc_link_ifp() / ifc_unlink_ifp() to the KPI Factor cloner ifp addition/deletion into separate functions and make them public. This change simlifies the current cloner code and paves the way to the other upcoming cloner / epair changes. MFC after: 2 weeks --- sys/net/if_clone.c | 81 +++++++++++++++++++++++++++++++++--------------------- sys/net/if_clone.h | 3 ++ 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 50664c28ff88..8360fb4d1d27 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -227,7 +227,7 @@ if_clone_create(char *name, size_t len, caddr_t params) } void -if_clone_addif(struct if_clone *ifc, struct ifnet *ifp) +ifc_link_ifp(struct if_clone *ifc, struct ifnet *ifp) { if ((ifc->ifc_flags & IFC_NOGROUP) == 0) @@ -238,6 +238,50 @@ if_clone_addif(struct if_clone *ifc, struct ifnet *ifp) IF_CLONE_UNLOCK(ifc); } +void +if_clone_addif(struct if_clone *ifc, struct ifnet *ifp) +{ + ifc_link_ifp(ifc, ifp); +} + +bool +ifc_unlink_ifp(struct if_clone *ifc, struct ifnet *ifp) +{ + struct ifnet *ifcifp; + + IF_CLONE_LOCK(ifc); + LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) { + if (ifcifp == ifp) { + IFC_IFLIST_REMOVE(ifc, ifp); + break; + } + } + IF_CLONE_UNLOCK(ifc); + + if (ifcifp != NULL && (ifc->ifc_flags & IFC_F_NOGROUP) == 0) + if_delgroup(ifp, ifc->ifc_name); + + return (ifcifp != NULL); +} + +static struct if_clone * +ifc_find_cloner(const char *name, struct vnet *vnet) +{ + 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(); + CURVNET_RESTORE(); + + return (ifc); +} + /* * Create a clone network interface. */ @@ -281,16 +325,7 @@ if_clone_destroy(const char *name) if (ifp == NULL) return (ENXIO); - /* Find the cloner for this interface */ - CURVNET_SET_QUIET(ifp->if_home_vnet); - IF_CLONERS_LOCK(); - LIST_FOREACH(ifc, &V_if_cloners, ifc_list) { - if (strcmp(ifc->ifc_name, ifp->if_dname) == 0) { - break; - } - } - IF_CLONERS_UNLOCK(); - CURVNET_RESTORE(); + ifc = ifc_find_cloner(ifp->if_dname, ifp->if_home_vnet); if (ifc == NULL) { if_rele(ifp); return (EINVAL); @@ -308,7 +343,6 @@ static int if_clone_destroyif_flags(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) { int err; - struct ifnet *ifcifp; /* * Given that the cloned ifnet might be attached to a different @@ -317,32 +351,17 @@ if_clone_destroyif_flags(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags */ CURVNET_SET_QUIET(ifp->if_vnet); - IF_CLONE_LOCK(ifc); - LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) { - if (ifcifp == ifp) { - IFC_IFLIST_REMOVE(ifc, ifp); - break; - } - } - IF_CLONE_UNLOCK(ifc); - if (ifcifp == NULL) { + if (!ifc_unlink_ifp(ifc, ifp)) { CURVNET_RESTORE(); return (ENXIO); /* ifp is not on the list. */ } - if ((ifc->ifc_flags & IFC_F_NOGROUP) == 0) - if_delgroup(ifp, ifc->ifc_name); int unit = ifp->if_dunit; err = (*ifc->ifc_destroy)(ifc, ifp, flags); - if (err != 0) { - if ((ifc->ifc_flags & IFC_F_NOGROUP) == 0) - if_addgroup(ifp, ifc->ifc_name); - - IF_CLONE_LOCK(ifc); - IFC_IFLIST_INSERT(ifc, ifp); - IF_CLONE_UNLOCK(ifc); - } else if (ifc->ifc_flags & IFC_F_AUTOUNIT) + if (err != 0) + ifc_link_ifp(ifc, ifp); + else if (ifc->ifc_flags & IFC_F_AUTOUNIT) ifc_free_unit(ifc, unit); CURVNET_RESTORE(); return (err); diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h index de20eef993f4..1d918a012a5b 100644 --- a/sys/net/if_clone.h +++ b/sys/net/if_clone.h @@ -78,6 +78,9 @@ void ifc_detach_cloner(struct if_clone *ifc); int ifc_create_ifp(const char *name, struct ifc_data *ifd, struct ifnet **ifpp); +void ifc_link_ifp(struct if_clone *ifc, struct ifnet *ifp); +bool ifc_unlink_ifp(struct if_clone *ifc, struct ifnet *ifp); + int ifc_copyin(const struct ifc_data *ifd, void *target, size_t len); #ifdef CLONE_COMPAT_13