From nobody Fri Mar 29 19:36:05 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 4V5rHV0q0bz5FYR6; Fri, 29 Mar 2024 19:36:06 +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 4V5rHV0Czvz44pq; Fri, 29 Mar 2024 19:36:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711740966; 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=lqS+f7plaVlaJVrCqgToF9wAUvlP5i9nJ4HpVtWJ3iM=; b=rjfW3FHTLYxzK7xnCdce53CCAsYWzzx0523cMTccc7GONBs+EfofsRFIKvlCNMHLziN/7K WRrhG3ZsWeZffDtfE+GBev+4q+1+MemjQ2E3G7WYTHkqvMh6F4J5X+Xm1/zMLvyF5Dnqph lontuYghO+ZCrGprohuI+k4I7yOTeODc26MN7Sq53u6EhZ4k+weVEY4c4g3YfMpw7+AiJk J00YSSAaraq2eEkMF6GraEjiAm+c1cTSmnG15Z83t54HGMJS6CfvArlZea2qeu7T6BWzZL e9Qaod3dMfNVbWW9v6hu4Uc/eogfU20h/NTgbOYkauFkkbfoyePOj+nunF9PAQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711740966; a=rsa-sha256; cv=none; b=GCJZ7tI7ZXxdU6B3mXnC/LN1W3OONE9/sJQDVtT3I2o8AxzvWDzcWcd0YWJ6q8t+R0oWfu fnn9lBWgXj255D8cK5C6mSMwCTu640ES5jFQ+W0rASR9VmtYafHQZFlKWS6ao+Bc99oURh tYPr5QrE2KUMsL5VyFJNHbVEDptGJO0um9/JUWF0c2l40tQwnYfnHJphELCpZ1PAIKLD7S GiukQQd26vKQmB135bQXR3hOfxQqOHufOpeco1YL3H97usmBodQKKpTH2O/CAAW11L8ePT 7hrkb0+K5j/xZRuX+dFkwqbXi0+Pjzc/lFkLLvYQiyPjDgmdYHGEUPOILe3h6w== 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=1711740966; 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=lqS+f7plaVlaJVrCqgToF9wAUvlP5i9nJ4HpVtWJ3iM=; b=Mre4mfE5vmbcKG0kMMdmJWDZTG7rhnLcEi5wzcGO02HxSCRil7aGflcxIWjRrryqHiFGWD AiKSoIDeu3nOQW+aciwtHpx2d3nHzD1o92GhGTyFMrXAH08GovZWY/DnQgTXK4+NL/YKc7 gtppThi6I585+gM7iSOd1IhoeA/mVCa8a1ttbOGQbPBAl2Vv0ZVfRBKVFvE0nJkdUtbqI3 JGytiSejrMYgJxkLZCgpPJzKFSxUJf/7YsL0CCxUV/U7Dkn2krNyAcSTTtI2w0oVMooCfw 4MzhjWD8EulhJMkDKa1Pnmom2L5b3lBabE8M7VWNlhDnC2dJ1itB3an+XSz5EA== 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 4V5rHT6wzTzNmB; Fri, 29 Mar 2024 19:36:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42TJa5YE020728; Fri, 29 Mar 2024 19:36:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42TJa52d020725; Fri, 29 Mar 2024 19:36:05 GMT (envelope-from git) Date: Fri, 29 Mar 2024 19:36:05 GMT Message-Id: <202403291936.42TJa52d020725@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: fa93ba4097f0 - main - if_tuntap: simplify storage of per-vnet cloners 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fa93ba4097f0db31b8f1b3d081979a4e6f34c191 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=fa93ba4097f0db31b8f1b3d081979a4e6f34c191 commit fa93ba4097f0db31b8f1b3d081979a4e6f34c191 Author: Gleb Smirnoff AuthorDate: 2024-03-29 19:35:41 +0000 Commit: Gleb Smirnoff CommitDate: 2024-03-29 19:35:41 +0000 if_tuntap: simplify storage of per-vnet cloners There is no need for a separate structure neither for a linked list. Provide each VNET with an array of pointers to if_clone that has the same size as the driver list. Reviewed by: zlei, kevans, kp Differential Revision: https://reviews.freebsd.org/D44307 --- sys/net/if_tuntap.c | 68 ++++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/sys/net/if_tuntap.c b/sys/net/if_tuntap.c index 4cb219dc92b6..1009dc7b3806 100644 --- a/sys/net/if_tuntap.c +++ b/sys/net/if_tuntap.c @@ -328,16 +328,9 @@ static struct tuntap_driver { .clone_destroy_fn = tun_clone_destroy, }, }; +#define NDRV nitems(tuntap_drivers) -struct tuntap_driver_cloner { - SLIST_ENTRY(tuntap_driver_cloner) link; - struct tuntap_driver *drv; - struct if_clone *cloner; -}; - -VNET_DEFINE_STATIC(SLIST_HEAD(, tuntap_driver_cloner), tuntap_driver_cloners) = - SLIST_HEAD_INITIALIZER(tuntap_driver_cloners); - +VNET_DEFINE_STATIC(struct if_clone *, tuntap_driver_cloners[NDRV]); #define V_tuntap_driver_cloners VNET(tuntap_driver_cloners) /* @@ -406,7 +399,6 @@ static int tuntap_name2info(const char *name, int *outunit, int *outflags) { struct tuntap_driver *drv; - struct tuntap_driver_cloner *drvc; char *dname; int flags, unit; bool found; @@ -422,12 +414,8 @@ tuntap_name2info(const char *name, int *outunit, int *outflags) dname = __DECONST(char *, name); found = false; - KASSERT(!SLIST_EMPTY(&V_tuntap_driver_cloners), - ("tuntap_driver_cloners failed to initialize")); - SLIST_FOREACH(drvc, &V_tuntap_driver_cloners, link) { - KASSERT(drvc->drv != NULL, - ("tuntap_driver_cloners entry not properly initialized")); - drv = drvc->drv; + for (u_int i = 0; i < NDRV; i++) { + drv = &tuntap_drivers[i]; if (strcmp(name, drv->cdevsw.d_name) == 0) { found = true; @@ -456,23 +444,16 @@ tuntap_name2info(const char *name, int *outunit, int *outflags) /* * Get driver information from a set of flags specified. Masks the identifying * part of the flags and compares it against all of the available - * tuntap_drivers. Must be called with correct vnet context. + * tuntap_drivers. */ static struct tuntap_driver * tuntap_driver_from_flags(int tun_flags) { - struct tuntap_driver *drv; - struct tuntap_driver_cloner *drvc; - - KASSERT(!SLIST_EMPTY(&V_tuntap_driver_cloners), - ("tuntap_driver_cloners failed to initialize")); - SLIST_FOREACH(drvc, &V_tuntap_driver_cloners, link) { - KASSERT(drvc->drv != NULL, - ("tuntap_driver_cloners entry not properly initialized")); - drv = drvc->drv; - if ((tun_flags & TUN_DRIVER_IDENT_MASK) == drv->ident_flags) - return (drv); - } + + for (u_int i = 0; i < NDRV; i++) + if ((tun_flags & TUN_DRIVER_IDENT_MASK) == + tuntap_drivers[i].ident_flags) + return (&tuntap_drivers[i]); return (NULL); } @@ -674,22 +655,15 @@ tun_clone_destroy(struct if_clone *ifc __unused, struct ifnet *ifp, uint32_t fla static void vnet_tun_init(const void *unused __unused) { - struct tuntap_driver *drv; - struct tuntap_driver_cloner *drvc; - int i; - for (i = 0; i < nitems(tuntap_drivers); ++i) { - drv = &tuntap_drivers[i]; - drvc = malloc(sizeof(*drvc), M_TUN, M_WAITOK | M_ZERO); - - drvc->drv = drv; + for (u_int i = 0; i < NDRV; ++i) { struct if_clone_addreq req = { - .match_f = drv->clone_match_fn, - .create_f = drv->clone_create_fn, - .destroy_f = drv->clone_destroy_fn, + .match_f = tuntap_drivers[i].clone_match_fn, + .create_f = tuntap_drivers[i].clone_create_fn, + .destroy_f = tuntap_drivers[i].clone_destroy_fn, }; - drvc->cloner = ifc_attach_cloner(drv->cdevsw.d_name, &req); - SLIST_INSERT_HEAD(&V_tuntap_driver_cloners, drvc, link); + V_tuntap_driver_cloners[i] = + ifc_attach_cloner(tuntap_drivers[i].cdevsw.d_name, &req); }; } VNET_SYSINIT(vnet_tun_init, SI_SUB_PROTO_IF, SI_ORDER_ANY, @@ -698,15 +672,9 @@ VNET_SYSINIT(vnet_tun_init, SI_SUB_PROTO_IF, SI_ORDER_ANY, static void vnet_tun_uninit(const void *unused __unused) { - struct tuntap_driver_cloner *drvc; - - while (!SLIST_EMPTY(&V_tuntap_driver_cloners)) { - drvc = SLIST_FIRST(&V_tuntap_driver_cloners); - SLIST_REMOVE_HEAD(&V_tuntap_driver_cloners, link); - if_clone_detach(drvc->cloner); - free(drvc, M_TUN); - } + for (u_int i = 0; i < NDRV; ++i) + if_clone_detach(V_tuntap_driver_cloners[i]); } VNET_SYSUNINIT(vnet_tun_uninit, SI_SUB_PROTO_IF, SI_ORDER_ANY, vnet_tun_uninit, NULL);