From nobody Sat Oct 12 13:38:45 2024 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 4XQl2F35fpz5YQ1g; Sat, 12 Oct 2024 13:38:45 +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 4XQl2F2Y2Kz4kQQ; Sat, 12 Oct 2024 13:38:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728740325; 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=SlIlcEIKUSM9GomrxHyThhyKNm596AsgeZbenOSzROs=; b=wrxZSi2zfk86+jic3B1GoX6kJVJeHy72FrKehOH9h65zj4eu94a/I2B5e7IHqTn+4HVOkw hOzyzobxdtJptzZW5fmloKPrbPX86Mpe8EWErpBisfhgsVGKy4JEbxzmReameciqm5PawP SLgpngTXTKDGLxbBuLr3SkrbVCOp885ykKn3qopNeGorNsXjA1xsSTGFP2VaNA+PcROGsj LegpTsOvr1oM/Ix5xOudbIPU5waxDTBqa5ClvzcWUufIirZ30qC9LxqmosaynsoSFhDg0I cwwaVoKWisaqVPM6Fi2k9xV8ek8CblrfV8jmDAXl812oTWdD2+S7wmwB35ryHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728740325; 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=SlIlcEIKUSM9GomrxHyThhyKNm596AsgeZbenOSzROs=; b=ehh+x1CqeLx8Ukx60JadKTce5nt+ZiQEJTHRklkD8WSm6EPz9uydn+LqGkV63y0BPTZXF8 anpl5kdQTLM4qLgXn5IOGbkBjRZ/qTG3lF1I97JFR1kCNwuxRrZtNgTMcHQQAR6s7h5ZuN BS1UjzcmW5XnyjROmQ/2SMFETKtAPR0jpoDof9enbhbRWznyJFlIVSX3NLpoRDA4dbfufn WWDnI/0e2v2pURliN0xxn8Gn7d0P8EC4Y5B5LaCWJ0KBXQ11k8jEnDMuLrvxIlZX1sX8ND xpJNhzaHHhh9urR/PwdV6fH8YkdUA4dSt0831XE/k4pHA2qKI20XHUahjV5swg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728740325; a=rsa-sha256; cv=none; b=wPCMRPGejMMGau64WbnUIVMPUZwCz6MGW3JuR9BEull5kRrQ51u9Z7CMqmdx+Jd9Z4PWpC Km68Vv2twcnk5KA8RglHhCxtcBFRjk64dNVuS7zkbYwOY4cMys3yZ+TkEs9TApi4tOBMC2 xSNMIvG3GsItpu0Xpds7oUauAJWBYMTReRBLGt/Sg00xO9CozUoVrOeQ89AnRVzC0keEdV 1KVgdsDAagMZx0sH5ugH2ifk/oO9CGDSbyLZF0+xgeX4UZJXqRqetlFB6SFOZOUIvSSAp3 Mm1ZFuwX3EBG8s5lXNAk1htN/271Ew29JDHYzYl+0r146bLnSJnFntUz8M6yjg== 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 4XQl2F1wdMz1QsP; Sat, 12 Oct 2024 13:38:45 +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 49CDcjcp092296; Sat, 12 Oct 2024 13:38:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49CDcjqV092293; Sat, 12 Oct 2024 13:38:45 GMT (envelope-from git) Date: Sat, 12 Oct 2024 13:38:45 GMT Message-Id: <202410121338.49CDcjqV092293@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: eacad82f3ad0 - main - if_enc(4): Use new KPI to create enc interface 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: eacad82f3ad0af7d74968e73ed383fc4531d1924 Auto-Submitted: auto-generated The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=eacad82f3ad0af7d74968e73ed383fc4531d1924 commit eacad82f3ad0af7d74968e73ed383fc4531d1924 Author: Zhenlei Huang AuthorDate: 2024-06-27 09:22:37 +0000 Commit: Zhenlei Huang CommitDate: 2024-10-12 13:37:53 +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 --- 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);