From owner-freebsd-net@FreeBSD.ORG Fri Feb 17 13:53:22 2012 Return-Path: Delivered-To: net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0A44C1065675 for ; Fri, 17 Feb 2012 13:53:22 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebius.int.ru (glebius.int.ru [81.19.64.117]) by mx1.freebsd.org (Postfix) with ESMTP id 860E88FC1A for ; Fri, 17 Feb 2012 13:53:21 +0000 (UTC) Received: from cell.glebius.int.ru (localhost [127.0.0.1]) by cell.glebius.int.ru (8.14.5/8.14.5) with ESMTP id q1HDrKbX068694; Fri, 17 Feb 2012 17:53:20 +0400 (MSK) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebius.int.ru (8.14.5/8.14.5/Submit) id q1HDrKkE068693; Fri, 17 Feb 2012 17:53:20 +0400 (MSK) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebius.int.ru: glebius set sender to glebius@FreeBSD.org using -f Date: Fri, 17 Feb 2012 17:53:20 +0400 From: Gleb Smirnoff To: Marcel Moolenaar Message-ID: <20120217135320.GJ55075@FreeBSD.org> References: <338757D1-6B1E-49CF-983F-5D5851066FD3@xcllnt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <338757D1-6B1E-49CF-983F-5D5851066FD3@xcllnt.net> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: net@FreeBSD.org Subject: Re: Abstracting struct ifnet X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 13:53:22 -0000 On Thu, Feb 16, 2012 at 08:16:22PM -0800, Marcel Moolenaar wrote: M> All, M> M> Juniper is in the final phases of creating a clean separation M> between FreeBSD and Junos, so as to make upgrades of FreeBSD M> easier. This also allows Juniper to track -current and be more M> active FreeBSD contributors. M> M> To that end, we have a short-term and hopefully short-lived M> problem to solve, which is the ability to use FreeBSD's network M> drivers against the Junos network stack. As some may know, the M> Junos network stack has split up struct ifnet into a physical M> and logical component, called ifdev and iflogical. M> M> We've tried a few approaches to bridge the gap between ifnet M> on the one hand and ifdev and iflogical on the other and found M> that abstracting ifnet and using accessor functions is the M> best way to allow us to use FreeBSD drivers with the Junos M> network stack, while retaining the ability to use them with M> the FreeBSD stack. M> M> FreeBSD is also looking at breaking up ifnet and with that in M> mind, I was wondering if there would be any resistance to M> changing network drivers to use accessor functions or macros M> instead of direct pointer dereferences? M> M> For example, do something like: M> M> Index: if_fxp.c M> =================================================================== M> --- if_fxp.c (revision 231178) M> +++ if_fxp.c (working copy) M> @@ -823,13 +823,14 @@ M> } M> M> if_initname(ifp, device_get_name(dev), device_get_unit(dev)); M> - ifp->if_init = fxp_init; M> - ifp->if_softc = sc; M> - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; M> - ifp->if_ioctl = fxp_ioctl; M> - ifp->if_start = fxp_start; M> + if_set_init(ifp, fxp_init); M> + if_set_softc(ifp, sc); M> + if_set_flags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST, 0); M> + if_set_ioctl(ifp, fxp_ioctl); M> + if_set_start(ifp, fxp_start); M> M> - ifp->if_capabilities = ifp->if_capenable = 0; M> + if_set_capabilities(ifp, 0); M> + if_set_capenable(ifp, 0); M> M> /* Enable checksum offload/TSO for 82550 or better chips */ M> if (sc->flags & FXP_FLAG_EXT_RFA) { M> M> Such a scheme, while initially touching a lot of driver, M> would make it easier to break up ifnet *and* also make it M> easier to hide ABI/API changes from driver vendors (esp. M> when the accessor functions are non-inlined functions and M> not macros or inlines). This is particularly useful for M> Juniper, where we have worked towards network stacks as M> (pre-)loadable modules so as to help with migration and M> validation. M> M> Thoughts, feedback and suggestion are welcome, Is it possible to make the structure the driver points to opaque? Once made, that would allow us to hack on the ifnet (or on its successor - iflogical) more aggressively without breaking ABI/API. -- Totus tuus, Glebius.