From owner-svn-src-head@freebsd.org Sun Jun 21 22:02:50 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 24F563367EF; Sun, 21 Jun 2020 22:02:50 +0000 (UTC) (envelope-from mmacy@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49qmkL04hyz3Tty; Sun, 21 Jun 2020 22:02:50 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F1F1724197; Sun, 21 Jun 2020 22:02:49 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05LM2n27071590; Sun, 21 Jun 2020 22:02:49 GMT (envelope-from mmacy@FreeBSD.org) Received: (from mmacy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05LM2n3n071588; Sun, 21 Jun 2020 22:02:49 GMT (envelope-from mmacy@FreeBSD.org) Message-Id: <202006212202.05LM2n3n071588@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmacy set sender to mmacy@FreeBSD.org using -f From: Matt Macy Date: Sun, 21 Jun 2020 22:02:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362471 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: mmacy X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 362471 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Jun 2020 22:02:50 -0000 Author: mmacy Date: Sun Jun 21 22:02:49 2020 New Revision: 362471 URL: https://svnweb.freebsd.org/changeset/base/362471 Log: iflib: fix cloneattach fail and generalize pseudo device handling - a cloneattach failure will not currently be handled correctly, jump to the right target - pseudo devices are all treat as if they're ethernet devices - this often doesn't make sense MFC after: 1 week Sponsored by: Netgate, Inc. Differential Revision: https://reviews.freebsd.org/D25083 Modified: head/sys/net/iflib.c head/sys/net/iflib.h Modified: head/sys/net/iflib.c ============================================================================== --- head/sys/net/iflib.c Sun Jun 21 20:30:11 2020 (r362470) +++ head/sys/net/iflib.c Sun Jun 21 22:02:49 2020 (r362471) @@ -4874,12 +4874,8 @@ iflib_pseudo_register(device_t dev, if_shared_ctx_t sc if ((err = IFDI_CLONEATTACH(ctx, clctx->cc_ifc, clctx->cc_name, clctx->cc_params)) != 0) { device_printf(dev, "IFDI_CLONEATTACH failed %d\n", err); - goto fail_ctx_free; + goto fail_unlock; } - ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); - ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO, 0, NULL); - ifmedia_set(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO); - #ifdef INVARIANTS if (scctx->isc_capabilities & IFCAP_TXCSUM) MPASS(scctx->isc_tx_csum_flags); @@ -4890,7 +4886,14 @@ iflib_pseudo_register(device_t dev, if_shared_ctx_t sc ifp->if_flags |= IFF_NOGROUP; if (sctx->isc_flags & IFLIB_PSEUDO) { - ether_ifattach(ctx->ifc_ifp, ctx->ifc_mac.octet); + ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO, 0, NULL); + ifmedia_set(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO); + if (sctx->isc_flags & IFLIB_PSEUDO_ETHER) { + ether_ifattach(ctx->ifc_ifp, ctx->ifc_mac.octet); + } else { + if_attach(ctx->ifc_ifp); + bpfattach(ctx->ifc_ifp, DLT_NULL, sizeof(u_int32_t)); + } if ((err = IFDI_ATTACH_POST(ctx)) != 0) { device_printf(dev, "IFDI_ATTACH_POST failed %d\n", err); @@ -4913,6 +4916,10 @@ iflib_pseudo_register(device_t dev, if_shared_ctx_t sc CTX_UNLOCK(ctx); return (0); } + ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); + ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO, 0, NULL); + ifmedia_set(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO); + _iflib_pre_assert(scctx); ctx->ifc_txrx = *scctx->isc_txrx; @@ -5028,6 +5035,7 @@ int iflib_pseudo_deregister(if_ctx_t ctx) { if_t ifp = ctx->ifc_ifp; + if_shared_ctx_t sctx = ctx->ifc_sctx; iflib_txq_t txq; iflib_rxq_t rxq; int i, j; @@ -5037,7 +5045,13 @@ iflib_pseudo_deregister(if_ctx_t ctx) /* Unregister VLAN event handlers early */ iflib_unregister_vlan_handlers(ctx); - ether_ifdetach(ifp); + if ((sctx->isc_flags & IFLIB_PSEUDO) && + (sctx->isc_flags & IFLIB_PSEUDO_ETHER) == 0) { + bpfdetach(ifp); + if_detach(ifp); + } else { + ether_ifdetach(ifp); + } /* XXX drain any dependent tasks */ tqg = qgroup_if_io_tqg; for (txq = ctx->ifc_txqs, i = 0; i < NTXQSETS(ctx); i++, txq++) { @@ -5362,13 +5376,22 @@ iflib_register(if_ctx_t ctx) driver_t *driver = sctx->isc_driver; device_t dev = ctx->ifc_dev; if_t ifp; + u_char type; + int iflags; if ((sctx->isc_flags & IFLIB_PSEUDO) == 0) _iflib_assert(sctx); CTX_LOCK_INIT(ctx); STATE_LOCK_INIT(ctx, device_get_nameunit(ctx->ifc_dev)); - ifp = ctx->ifc_ifp = if_alloc(IFT_ETHER); + if (sctx->isc_flags & IFLIB_PSEUDO) { + if (sctx->isc_flags & IFLIB_PSEUDO_ETHER) + type = IFT_ETHER; + else + type = IFT_PPP; + } else + type = IFT_ETHER; + ifp = ctx->ifc_ifp = if_alloc(type); if (ifp == NULL) { device_printf(dev, "can not allocate ifnet structure\n"); return (ENOMEM); @@ -5393,9 +5416,14 @@ iflib_register(if_ctx_t ctx) if_settransmitfn(ifp, iflib_if_transmit); #endif if_setqflushfn(ifp, iflib_if_qflush); - if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST | - IFF_KNOWSEPOCH); + iflags = IFF_MULTICAST | IFF_KNOWSEPOCH; + if ((sctx->isc_flags & IFLIB_PSEUDO) && + (sctx->isc_flags & IFLIB_PSEUDO_ETHER) == 0) + iflags |= IFF_POINTOPOINT; + else + iflags |= IFF_BROADCAST | IFF_SIMPLEX; + if_setflags(ifp, iflags); ctx->ifc_vlan_attach_event = EVENTHANDLER_REGISTER(vlan_config, iflib_vlan_register, ctx, EVENTHANDLER_PRI_FIRST); Modified: head/sys/net/iflib.h ============================================================================== --- head/sys/net/iflib.h Sun Jun 21 20:30:11 2020 (r362470) +++ head/sys/net/iflib.h Sun Jun 21 22:02:49 2020 (r362471) @@ -375,6 +375,12 @@ typedef enum { * interrupts instead of doing combined RX/TX processing. */ #define IFLIB_SINGLE_IRQ_RX_ONLY 0x40000 +/* + * Don't need/want most of the niceties of + * emulating ethernet + */ +#define IFLIB_PSEUDO_ETHER 0x80000 + /* * These enum values are used in iflib_needs_restart to indicate to iflib