From nobody Sun Oct 20 13:43:43 2024 X-Original-To: dev-commits-src-branches@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 4XWfmH4cLmz5ZKWW; Sun, 20 Oct 2024 13:43:43 +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 4XWfmH3y2kz4tyB; Sun, 20 Oct 2024 13:43:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729431823; 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=I9p7s2jj9lmuBK3HKJknIE6VMHSdijaffYIMXgIg0Y8=; b=jU4aSlrBXuFsVvzLTIxAzaog8WMyvFIKaDAuHIA2L9IineR4cNGRbC3C9vi3Y9QQVmhb0j 2k15khwaW76NZsden9f4Mvq6ssMbsT/PnoIT8ecGy9JUhR6AHSPMRnNAheCmKCZgum70b0 or72dRWD7lzWKBOYAEzjIlLEPS7hWHR1LyD/b3hEWzOIxju0ecyxWgwdkfs2Gu1CyhTxqa hSyYjPpcIr+bq6o98gKFLq03nrxoNHWkxVpsXkYPCR2Up21/p0K7eiXJ6n0YeiF6ruD3E7 jlWeNB0LY04hFxzLCD9eXVb4tUEycnlZW1X8HYiEDFwlLfMm+fVEwBpF6ZzrTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729431823; 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=I9p7s2jj9lmuBK3HKJknIE6VMHSdijaffYIMXgIg0Y8=; b=Nc+iJArWbuWRT/fQ5gg3mUepWozCrQWqiB7gCENAYSfBYCTFUwqMlNRBWFP7h2QW51369j 1Pc6TVQmBdmQ8WsUZ1jtLKWCtYCKcJ3Xv9l1I0M4H7JPZIqldmXUDrfdByke2GSFiFlEfP mt05J+45VMNuURcfAzy4Wgf3xBUAp25QWBO8xUP/Dy2aer1D3eo/384HvpCu94yFV5yceF oO08ZfpxmdKRGPw2ZtUSbZnmfOaPqDDtAKz+UbKA6mekciRGcAAYWUxyNzPYixfh1UIWKJ k0TsKqUncP1/E+I9j4ghFC/UAOlUBwd2FK37l2e4UX7xHBKKWTrtsY2egSzA3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729431823; a=rsa-sha256; cv=none; b=ZdRE4TkEOAZ0bcLdve9mudyG7WrdjFFnJgXWJx4tZoYGAJ7OwzieCf26pg5RD9tyw8socz dTmhvf1UiwDhqwZc6v2mqKQwxzw3+4MFk8h8iMlIci2CejvsWTWgzybleliP/Zp83/U7QJ qAIGhtvB0zHK4QSN8afjj2AuwbVJkzwD/ykVB4yHb8bfJc5mqOQhLB10XrWj9ghdacsL20 XqyeCvXC/eShcJwVmCGz87h+d3ypPXhxX1Xk4onwVAx8urEc/FBg1Uux1gAO6Xxgg8XlQj evCNE12hbVnCuH5I3BAzNE8ZALPLbnGZRSNT4mdJLROtcI2U1WLSZTD/+3cyNQ== 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 4XWfmH3FRBz148m; Sun, 20 Oct 2024 13:43:43 +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 49KDhhj5024169; Sun, 20 Oct 2024 13:43:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49KDhhcK024166; Sun, 20 Oct 2024 13:43:43 GMT (envelope-from git) Date: Sun, 20 Oct 2024 13:43:43 GMT Message-Id: <202410201343.49KDhhcK024166@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: 03f7680517c8 - stable/14 - if_enc(4): Use new KPI to create enc interface List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: 03f7680517c88ec9b656f73e5382bcaf07791d2c Auto-Submitted: auto-generated The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=03f7680517c88ec9b656f73e5382bcaf07791d2c commit 03f7680517c88ec9b656f73e5382bcaf07791d2c Author: Zhenlei Huang AuthorDate: 2024-06-27 09:22:37 +0000 Commit: Zhenlei Huang CommitDate: 2024-10-20 13:43:01 +0000 if_enc(4): Use new KPI to create enc interface This driver allows only exactly one instance to be created. Clone creating additional interfaces, e.g. `ifconfig enc1 create`, will get error EEXIST which is somewhat confusing. Convert to new KPI for less confusing error ENOSPC. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45758 (cherry picked from commit eacad82f3ad0af7d74968e73ed383fc4531d1924) --- sys/net/if_enc.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/sys/net/if_enc.c b/sys/net/if_enc.c index 3c7ae38324c3..3c3f19661063 100644 --- a/sys/net/if_enc.c +++ b/sys/net/if_enc.c @@ -94,8 +94,9 @@ VNET_DEFINE_STATIC(struct if_clone *, enc_cloner); static int enc_ioctl(struct ifnet *, u_long, caddr_t); static int enc_output(struct ifnet *, struct mbuf *, const struct sockaddr *, struct route *); -static int enc_clone_create(struct if_clone *, int, caddr_t); -static void enc_clone_destroy(struct ifnet *); +static int enc_clone_create(struct if_clone *, char *, size_t, + struct ifc_data *, struct ifnet **); +static int enc_clone_destroy(struct if_clone *, struct ifnet *, uint32_t); static void enc_add_hhooks(struct enc_softc *); static void enc_remove_hhooks(struct enc_softc *); @@ -139,11 +140,14 @@ SYSCTL_INT(_net_enc_out, OID_AUTO, ipsec_bpf_mask, CTLFLAG_RW | CTLFLAG_VNET, &VNET_NAME(bpf_mask_out), 0, "IPsec output bpf mask"); -static void -enc_clone_destroy(struct ifnet *ifp) +static int +enc_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) { struct enc_softc *sc; + if (ifp->if_dunit == 0 && (flags & IFC_F_FORCE) == 0) + return (EINVAL); + sc = ifp->if_softc; KASSERT(sc == V_enc_sc, ("sc != ifp->if_softc")); @@ -151,31 +155,26 @@ enc_clone_destroy(struct ifnet *ifp) if_detach(ifp); if_free(ifp); free(sc, M_DEVBUF); - V_enc_sc = NULL; + return (0); } static int -enc_clone_create(struct if_clone *ifc, int unit, caddr_t params) +enc_clone_create(struct if_clone *ifc, char *name, size_t len, + struct ifc_data *ifd, struct ifnet **ifpp) { struct ifnet *ifp; struct enc_softc *sc; - sc = malloc(sizeof(struct enc_softc), M_DEVBUF, - M_WAITOK | M_ZERO); + sc = malloc(sizeof(struct enc_softc), M_DEVBUF, M_WAITOK | M_ZERO); ifp = sc->sc_ifp = if_alloc(IFT_ENC); - if (V_enc_sc != NULL) { - if_free(ifp); - free(sc, M_DEVBUF); - return (EEXIST); - } - V_enc_sc = sc; - if_initname(ifp, encname, unit); + if_initname(ifp, encname, ifd->unit); ifp->if_mtu = ENCMTU; ifp->if_ioctl = enc_ioctl; ifp->if_output = enc_output; ifp->if_softc = sc; if_attach(ifp); bpfattach(ifp, DLT_ENC, sizeof(struct enchdr)); + *ifpp = ifp; return (0); } @@ -375,10 +374,18 @@ enc_remove_hhooks(struct enc_softc *sc) static void vnet_enc_init(const void *unused __unused) { + struct ifnet *ifp; - V_enc_sc = NULL; - V_enc_cloner = if_clone_simple(encname, enc_clone_create, - enc_clone_destroy, 1); + struct if_clone_addreq req = { + .create_f = enc_clone_create, + .destroy_f = enc_clone_destroy, + .flags = IFC_F_AUTOUNIT | IFC_F_LIMITUNIT, + .maxunit = 0, + }; + V_enc_cloner = ifc_attach_cloner(encname, &req); + struct ifc_data ifd = { .unit = 0 }; + ifc_create_ifp(encname, &ifd, &ifp); + V_enc_sc = ifp->if_softc; } VNET_SYSINIT(vnet_enc_init, SI_SUB_PSEUDO, SI_ORDER_ANY, vnet_enc_init, NULL); @@ -398,7 +405,8 @@ vnet_enc_uninit(const void *unused __unused) { KASSERT(V_enc_sc != NULL, ("%s: V_enc_sc is %p\n", __func__, V_enc_sc)); - if_clone_detach(V_enc_cloner); + ifc_detach_cloner(V_enc_cloner); + V_enc_sc = NULL; } VNET_SYSUNINIT(vnet_enc_uninit, SI_SUB_INIT_IF, SI_ORDER_ANY, vnet_enc_uninit, NULL);