From nobody Sat Jul 20 14:44:28 2024 X-Original-To: dev-commits-src-all@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 4WR8Ss2MYxz5Rnsk; Sat, 20 Jul 2024 14:44:29 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WR8Ss1Vhnz4Lc6; Sat, 20 Jul 2024 14:44:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721486669; 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=6j7xZ4xx+CnOJklbI01ZWe5F/YTjy15zbsjgC00xBiU=; b=wOJw7TQeSkaEcIsyqKEfU+bpJcntWnNilyBeu4ekUR0SNAX0lena4rtn6oqzzaA+5A/4kV mPp5V0gwhBNnoNGzhFra1h6AznkwdsL6S8/Qe5z3xSyP9vfjGOvqQgEvglxKLKxK7fXGwn DjDv3rXl20PYm+DdTMHYOeHnxP4c8kPaYuWD0CTxLSOr62bLfYUmJGNl7hft4BpfBjQWL5 1WnpvELs/eJNQSr6/ERoJ6DqnCsxS9NIvWVsW2Umht4q2RGoqzXqOAnokZN/YsH7UU0lGZ C0pJKIABEwegboCSreJMP0WUjIpxR/f1FCZfmvEvlOsJoDSBwFB7sR+5gOdxrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721486669; a=rsa-sha256; cv=none; b=bbZ9NQCSOhSCA+LpKbtDU76piVeIpWlG1CSNeGu1D1SbkctGbz5wjXs3FndtMh8MvQ53FB htm1FNU5Fnh0WEfq9GpHtudtrzXiOUi9QD6pyDebDTMMmK0cA4sTTX+6ufY1QLMk74nH/f Q+xWZCi2rk9c2q8dRw5nphfjG4aGZ6Bh9G5QOvjr09R5aNH8FF3fxS2DcHYhqGROydsD+T 9ssfPGBeYpBAgw0HBHLGDypmdWWZlSr2huhQGFJVHpGQ0lU5luNc647355QD/SG0ZHO+FB Zg0PvFVqEu8JmTbepJ1G50yIDjloYHo/kcf8pgTJnm7PSsbF5Vjwbr2kf0toBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721486669; 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=6j7xZ4xx+CnOJklbI01ZWe5F/YTjy15zbsjgC00xBiU=; b=g3E9eyTuPsh49uYO1NOQ6FTOkQKRTrFgmlQsX7sLNpD/E+d2b7z4g8JuMSlyCSJs97fZeT POps6J+JNtIRL0Igxo3DwXsN0nox1KLZDROc22ymEBt3iMPWuSKWWY/USSWZ+yQ18mSsyz xiLEd2RDwx6o5ldl6JxkGFLkuRZGjVR4p5oa27ikGbZ2hJ1pVfJENS7QnRQ07Y7QsESLhu pHhsX6Dh8ZFjB33REFGSZBPamnK5Eg8/WsaHrI5mv+LLbGBEj5suWKyMnGo+YnB1sXPpKI waGgV3MI+kq69j9wNNP3cK3p6gil8pbXKNuau6K6X74XR3WYB9mmX29iaBqnxA== 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 4WR8Ss101szKLl; Sat, 20 Jul 2024 14:44:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46KEiTwS028169; Sat, 20 Jul 2024 14:44:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46KEiSSx028166; Sat, 20 Jul 2024 14:44:28 GMT (envelope-from git) Date: Sat, 20 Jul 2024 14:44:28 GMT Message-Id: <202407201444.46KEiSSx028166@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 0d0999fe3137 - stable/14 - if_clone: Allow maxunit to be zero List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0d0999fe313779ea51ef4178dff76bb572fdb09f Auto-Submitted: auto-generated The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=0d0999fe313779ea51ef4178dff76bb572fdb09f commit 0d0999fe313779ea51ef4178dff76bb572fdb09f Author: Zhenlei Huang AuthorDate: 2024-07-03 13:14:08 +0000 Commit: Zhenlei Huang CommitDate: 2024-07-20 14:42:59 +0000 if_clone: Allow maxunit to be zero Some drivers, e.g. if_enc(4), only allow one instance to be created, but the KPI ifc_attach_cloner() treat zero value of maxunit as not limited, aka IF_MAXUNIT. Introduce a new flag IFC_F_LIMITUNIT to indicate that the requested maxunit is limited and should be respected. Consumers should use the new flag if there is an intended limit. Reviewed by: glebius MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D45757 (cherry picked from commit a2cac544a668d2834ed41986aca32b44b9819c89) --- sys/net/if_clone.c | 13 +++++++++---- sys/net/if_clone.h | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 5345d613f9d6..50ebed285d28 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -485,12 +485,13 @@ if_clone_alloc(const char *name, int maxunit) struct if_clone *ifc; KASSERT(name != NULL, ("%s: no name\n", __func__)); + MPASS(maxunit >= 0); ifc = malloc(sizeof(struct if_clone), M_CLONE, M_WAITOK | M_ZERO); strncpy(ifc->ifc_name, name, IFCLOSIZ-1); IF_CLONE_LOCK_INIT(ifc); IF_CLONE_ADDREF(ifc); - ifc->ifc_maxunit = maxunit ? maxunit : IF_MAXUNIT; + ifc->ifc_maxunit = maxunit; ifc->ifc_unrhdr = new_unrhdr(0, ifc->ifc_maxunit, &ifc->ifc_mtx); LIST_INIT(&ifc->ifc_iflist); @@ -523,12 +524,16 @@ if_clone_attach(struct if_clone *ifc) struct if_clone * ifc_attach_cloner(const char *name, struct if_clone_addreq *req) { + int maxunit; + struct if_clone *ifc; + if (req->create_f == NULL || req->destroy_f == NULL) return (NULL); if (strnlen(name, IFCLOSIZ) >= (IFCLOSIZ - 1)) return (NULL); - struct if_clone *ifc = if_clone_alloc(name, req->maxunit); + maxunit = (req->flags & IFC_F_LIMITUNIT) ? req->maxunit : IF_MAXUNIT; + ifc = if_clone_alloc(name, maxunit); ifc->ifc_match = req->match_f != NULL ? req->match_f : ifc_simple_match; ifc->ifc_create = req->create_f; ifc->ifc_destroy = req->destroy_f; @@ -586,7 +591,7 @@ if_clone_advanced(const char *name, u_int maxunit, ifc_match_t match, { struct if_clone *ifc; - ifc = if_clone_alloc(name, maxunit); + ifc = if_clone_alloc(name, maxunit ? maxunit : IF_MAXUNIT); ifc->ifc_match = match; ifc->ifc_create = ifc_advanced_create_wrapper; ifc->ifc_destroy = ifc_advanced_destroy_wrapper; @@ -631,7 +636,7 @@ if_clone_simple(const char *name, ifcs_create_t create, ifcs_destroy_t destroy, struct if_clone *ifc; u_int unit; - ifc = if_clone_alloc(name, 0); + ifc = if_clone_alloc(name, IF_MAXUNIT); ifc->ifc_match = ifc_simple_match; ifc->ifc_create = ifc_simple_create_wrapper; ifc->ifc_destroy = ifc_simple_destroy_wrapper; diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h index d44f7021299c..86aa52c0ed25 100644 --- a/sys/net/if_clone.h +++ b/sys/net/if_clone.h @@ -103,6 +103,11 @@ struct if_clone_addreq_v2 { #define IFC_F_SYSSPACE 0x04 /* Cloner callback: params pointer is in kernel memory */ #define IFC_F_FORCE 0x08 /* Deletion flag: force interface deletion */ #define IFC_F_CREATE 0x10 /* Creation flag: indicate creation request */ +#define IFC_F_LIMITUNIT 0x20 /* Creation flag: the unit number is limited */ + +_Static_assert(offsetof(struct if_clone_addreq, destroy_f) == + offsetof(struct if_clone_addreq_v2, destroy_f), + "destroy_f in if_clone_addreq and if_clone_addreq_v2 are at different offset"); struct if_clone *ifc_attach_cloner(const char *name, struct if_clone_addreq *req); void ifc_detach_cloner(struct if_clone *ifc);