From owner-freebsd-net@FreeBSD.ORG Fri Feb 17 04:30:09 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 96F27106566B for ; Fri, 17 Feb 2012 04:30:09 +0000 (UTC) (envelope-from marcel@xcllnt.net) Received: from mail.xcllnt.net (mail.xcllnt.net [70.36.220.4]) by mx1.freebsd.org (Postfix) with ESMTP id 46E3A8FC19 for ; Fri, 17 Feb 2012 04:30:09 +0000 (UTC) Received: from [172.23.7.53] (natint3.juniper.net [66.129.224.36]) (authenticated bits=0) by mail.xcllnt.net (8.14.5/8.14.5) with ESMTP id q1H4GPqB099172 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Thu, 16 Feb 2012 20:16:32 -0800 (PST) (envelope-from marcel@xcllnt.net) From: Marcel Moolenaar Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 16 Feb 2012 20:16:22 -0800 Message-Id: <338757D1-6B1E-49CF-983F-5D5851066FD3@xcllnt.net> To: net@FreeBSD.org Mime-Version: 1.0 (Apple Message framework v1257) X-Mailer: Apple Mail (2.1257) Cc: Subject: 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 04:30:09 -0000 All, Juniper is in the final phases of creating a clean separation between FreeBSD and Junos, so as to make upgrades of FreeBSD easier. This also allows Juniper to track -current and be more active FreeBSD contributors. To that end, we have a short-term and hopefully short-lived problem to solve, which is the ability to use FreeBSD's network drivers against the Junos network stack. As some may know, the Junos network stack has split up struct ifnet into a physical and logical component, called ifdev and iflogical. We've tried a few approaches to bridge the gap between ifnet on the one hand and ifdev and iflogical on the other and found that abstracting ifnet and using accessor functions is the best way to allow us to use FreeBSD drivers with the Junos network stack, while retaining the ability to use them with the FreeBSD stack. FreeBSD is also looking at breaking up ifnet and with that in mind, I was wondering if there would be any resistance to changing network drivers to use accessor functions or macros instead of direct pointer dereferences? For example, do something like: Index: if_fxp.c =================================================================== --- if_fxp.c (revision 231178) +++ if_fxp.c (working copy) @@ -823,13 +823,14 @@ } if_initname(ifp, device_get_name(dev), device_get_unit(dev)); - ifp->if_init = fxp_init; - ifp->if_softc = sc; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_ioctl = fxp_ioctl; - ifp->if_start = fxp_start; + if_set_init(ifp, fxp_init); + if_set_softc(ifp, sc); + if_set_flags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST, 0); + if_set_ioctl(ifp, fxp_ioctl); + if_set_start(ifp, fxp_start); - ifp->if_capabilities = ifp->if_capenable = 0; + if_set_capabilities(ifp, 0); + if_set_capenable(ifp, 0); /* Enable checksum offload/TSO for 82550 or better chips */ if (sc->flags & FXP_FLAG_EXT_RFA) { Such a scheme, while initially touching a lot of driver, would make it easier to break up ifnet *and* also make it easier to hide ABI/API changes from driver vendors (esp. when the accessor functions are non-inlined functions and not macros or inlines). This is particularly useful for Juniper, where we have worked towards network stacks as (pre-)loadable modules so as to help with migration and validation. Thoughts, feedback and suggestion are welcome, -- Marcel Moolenaar marcel@xcllnt.net