Abstracting struct ifnet

Gleb Smirnoff glebius at FreeBSD.org
Fri Feb 17 13:53:22 UTC 2012

On Thu, Feb 16, 2012 at 08:16:22PM -0800, Marcel Moolenaar wrote:
M> All,
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> 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> 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> 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> For example, do something like:
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>  	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_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> -	ifp->if_capabilities = ifp->if_capenable = 0;
M> +	if_set_capabilities(ifp, 0);
M> +	if_set_capenable(ifp, 0);
M>  	/* Enable checksum offload/TSO for 82550 or better chips */
M>  	if (sc->flags & FXP_FLAG_EXT_RFA) {
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> 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.

More information about the freebsd-net mailing list