Brooks Davis *nix forums addict
Joined: 14 Jun 2002
Posts: 97
|
Posted: Sat Jul 27, 2002 2:10 am Post subject:
switching to if_xname from if_name and if_unit
|
|
|
[Bcc to -arch for interested people not on -net]
NetBSD and OpenBSD have replaced the "char *if_name" and "int if_unit"
members of struct ifnet with "char if_xname[IFNAMESIZ]". I propose that
we follow suit.
Pros:
- Better source compatibility with NetBSD and OpenBSD.
- The ability to handle free-form device names. This could allow
things like and advanced cloning interface for vlans that let you
configure vlan X on interface nameY with "ifconfig nameY.X create".
- Most uses of if_name and if_unit together really just want the full
name of the device and the same with the majority of if_unit
entries. The remaining if_unit usages are usually the result of
sloppy code with hard wired limits on the number of devices that
should be fixed.
- We can implement the if_name() function without the current gross
hacks.
- Well defined maximum name size simplifies code.
Cons:
- Lost of source compatibility between 5.x and previous versions.
[We've already lost it with the spls and in most drivers it's
a two line change that you could handle with __FreeBSD_version if
you wanted to.]
- A few devices do have a legitimate use for use for the unit. [They
can use the softc to store it. That's what NetBSD did.]
- Well defined maximum name size limits length of name. [It's 16
bytes with is more then I'd want to type in to ifconfig.]
- It touches 140-150 files. [Most of the changes are minor in nature
and I'm about halfway through with 2-3hrs of work.]
- Slight bloating of struct ifnet (8 bytes on normal 32-bit
architectures). [None on 64-bit arches.]
- We've resisted for 8 years, we can't stop now. :-)
What do other people think?
-- Brooks
PS. Here the diff for a typical interface (around half have only the
initialization change and most others have more, but similar debugging
output changes):
RCS file: /usr/cvs/src/sys/dev/ep/if_ep.c,v
retrieving revision 1.109
diff -u -p -r1.109 if_ep.c
--- ep/if_ep.c 20 Mar 2002 02:07:19 -0000 1.109
+++ ep/if_ep.c 26 Jul 2002 06:55:58 -0000
@@ -280,8 +280,7 @@ ep_attach(sc)
attached = (ifp->if_softc != 0);
ifp->if_softc = sc;
- ifp->if_unit = sc->unit;
- ifp->if_name = "ep";
+ sprintf(ifp->if_xname, "ep%d", sc->unit);
ifp->if_mtu = ETHERMTU;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_output = ether_output;
@@ -917,7 +916,7 @@ ep_if_watchdog(ifp)
/*
printf("ep: watchdog\n");
- log(LOG_ERR, "ep%d: watchdog\n", ifp->if_unit);
+ log(LOG_ERR, "%s: watchdog\n", ifp->if_xname);
ifp->if_oerrors++;
*/
--
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 |
|