diff options
| author | dyoung <dyoung@NetBSD.org> | 2008-11-07 00:20:01 +0000 |
|---|---|---|
| committer | dyoung <dyoung@NetBSD.org> | 2008-11-07 00:20:01 +0000 |
| commit | de87fe677d8a6a5550686a03f180df394da699dc (patch) | |
| tree | 5e781f3364b7131f35f9647c107b6bc403752ba2 /sys/dev/usb | |
| parent | f455f7ee91e885925403e221d2f303a56ef60395 (diff) | |
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
Diffstat (limited to 'sys/dev/usb')
| -rw-r--r-- | sys/dev/usb/if_aue.c | 10 | ||||
| -rw-r--r-- | sys/dev/usb/if_axe.c | 10 | ||||
| -rw-r--r-- | sys/dev/usb/if_cdce.c | 27 | ||||
| -rw-r--r-- | sys/dev/usb/if_cue.c | 10 | ||||
| -rw-r--r-- | sys/dev/usb/if_kue.c | 10 | ||||
| -rw-r--r-- | sys/dev/usb/if_rum.c | 27 | ||||
| -rw-r--r-- | sys/dev/usb/if_upl.c | 27 | ||||
| -rw-r--r-- | sys/dev/usb/if_ural.c | 27 | ||||
| -rw-r--r-- | sys/dev/usb/if_zyd.c | 24 |
9 files changed, 105 insertions, 67 deletions
diff --git a/sys/dev/usb/if_aue.c b/sys/dev/usb/if_aue.c index 7f873f02e77..275fdd0b557 100644 --- a/sys/dev/usb/if_aue.c +++ b/sys/dev/usb/if_aue.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_aue.c,v 1.111 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_aue.c,v 1.112 2008/11/07 00:20:12 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.111 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.112 2008/11/07 00:20:12 dyoung Exp $"); #if defined(__NetBSD__) #include "opt_inet.h" @@ -1587,7 +1587,7 @@ aue_ioctl(struct ifnet *ifp, u_long command, void *data) s = splnet(); switch(command) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; aue_init(sc); @@ -1612,6 +1612,8 @@ aue_ioctl(struct ifnet *ifp, u_long command, void *data) break; case SIOCSIFFLAGS: + if ((error = ifioctl_common(ifp, command, data)) != 0) + break; if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && @@ -1647,7 +1649,7 @@ aue_ioctl(struct ifnet *ifp, u_long command, void *data) } break; default: - error = EINVAL; + error = ether_ioctl(ifp, command, data); break; } diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c index a56df4c9589..70724331af7 100644 --- a/sys/dev/usb/if_axe.c +++ b/sys/dev/usb/if_axe.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_axe.c,v 1.25 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_axe.c,v 1.26 2008/11/07 00:20:12 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000-2003 @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.25 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.26 2008/11/07 00:20:12 dyoung Exp $"); #if defined(__NetBSD__) #include "opt_inet.h" @@ -1134,7 +1134,7 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, void *data) int error = 0; switch(cmd) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; axe_init(sc); @@ -1159,6 +1159,8 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, void *data) break; case SIOCSIFFLAGS: + if ((error = ifioctl_common(ifp, cmd, data)) != 0) + break; if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && @@ -1209,7 +1211,7 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, void *data) } break; default: - error = EINVAL; + error = ether_ioctl(ifp, cmd, data); break; } diff --git a/sys/dev/usb/if_cdce.c b/sys/dev/usb/if_cdce.c index 9dccf439906..073a694930c 100644 --- a/sys/dev/usb/if_cdce.c +++ b/sys/dev/usb/if_cdce.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_cdce.c,v 1.18 2008/09/24 07:19:18 ws Exp $ */ +/* $NetBSD: if_cdce.c,v 1.19 2008/11/07 00:20:12 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul@windriver.com> @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.18 2008/09/24 07:19:18 ws Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.19 2008/11/07 00:20:12 dyoung Exp $"); #include "bpfilter.h" #ifdef __NetBSD__ #include "opt_inet.h" @@ -434,7 +434,7 @@ cdce_ioctl(struct ifnet *ifp, u_long command, void *data) s = splnet(); switch(command) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; cdce_init(sc); switch (ifa->ifa_addr->sa_family) { @@ -458,18 +458,23 @@ cdce_ioctl(struct ifnet *ifp, u_long command, void *data) break; case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (!(ifp->if_flags & IFF_RUNNING)) - cdce_init(sc); - } else { - if (ifp->if_flags & IFF_RUNNING) - cdce_stop(sc); + if ((error = ifioctl_common(ifp, command, data)) != 0) + break; + /* XXX re-use ether_ioctl() */ + switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + case IFF_UP: + cdce_init(sc); + break; + case IFF_RUNNING: + cdce_stop(sc); + break; + default: + break; } - error = 0; break; default: - error = EINVAL; + error = ether_ioctl(ifp, command, data); break; } diff --git a/sys/dev/usb/if_cue.c b/sys/dev/usb/if_cue.c index 807adcbec2e..1bd431d5a39 100644 --- a/sys/dev/usb/if_cue.c +++ b/sys/dev/usb/if_cue.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_cue.c,v 1.53 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_cue.c,v 1.54 2008/11/07 00:20:12 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. @@ -56,7 +56,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.53 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.54 2008/11/07 00:20:12 dyoung Exp $"); #if defined(__NetBSD__) #include "opt_inet.h" @@ -1162,7 +1162,7 @@ cue_ioctl(struct ifnet *ifp, u_long command, void *data) s = splnet(); switch(command) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; cue_init(sc); @@ -1187,6 +1187,8 @@ cue_ioctl(struct ifnet *ifp, u_long command, void *data) break; case SIOCSIFFLAGS: + if ((error = ifioctl_common(ifp, command, data)) != 0) + break; if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && @@ -1213,7 +1215,7 @@ cue_ioctl(struct ifnet *ifp, u_long command, void *data) error = 0; break; default: - error = EINVAL; + error = ether_ioctl(ifp, command, data); break; } diff --git a/sys/dev/usb/if_kue.c b/sys/dev/usb/if_kue.c index ea63e36935c..e340fd53f2d 100644 --- a/sys/dev/usb/if_kue.c +++ b/sys/dev/usb/if_kue.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_kue.c,v 1.63 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_kue.c,v 1.64 2008/11/07 00:20:12 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.63 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.64 2008/11/07 00:20:12 dyoung Exp $"); #if defined(__NetBSD__) #include "opt_inet.h" @@ -1069,7 +1069,7 @@ kue_ioctl(struct ifnet *ifp, u_long command, void *data) s = splnet(); switch(command) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; kue_init(sc); @@ -1094,6 +1094,8 @@ kue_ioctl(struct ifnet *ifp, u_long command, void *data) break; case SIOCSIFFLAGS: + if ((error = ifioctl_common(ifp, command, data)) != 0) + break; if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && @@ -1122,7 +1124,7 @@ kue_ioctl(struct ifnet *ifp, u_long command, void *data) error = 0; break; default: - error = EINVAL; + error = ether_ioctl(ifp, command, data); break; } diff --git a/sys/dev/usb/if_rum.c b/sys/dev/usb/if_rum.c index fc5b7e70701..8483b0a3717 100644 --- a/sys/dev/usb/if_rum.c +++ b/sys/dev/usb/if_rum.c @@ -1,5 +1,5 @@ /* $OpenBSD: if_rum.c,v 1.40 2006/09/18 16:20:20 damien Exp $ */ -/* $NetBSD: if_rum.c,v 1.23 2008/10/21 12:21:46 jun Exp $ */ +/* $NetBSD: if_rum.c,v 1.24 2008/11/07 00:20:12 dyoung Exp $ */ /*- * Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr> @@ -24,7 +24,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_rum.c,v 1.23 2008/10/21 12:21:46 jun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_rum.c,v 1.24 2008/11/07 00:20:12 dyoung Exp $"); #include "bpfilter.h" @@ -1373,14 +1373,21 @@ rum_ioctl(struct ifnet *ifp, u_long cmd, void *data) switch (cmd) { case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (ifp->if_flags & IFF_RUNNING) - rum_update_promisc(sc); - else - rum_init(ifp); - } else { - if (ifp->if_flags & IFF_RUNNING) - rum_stop(ifp, 1); + if ((error = ifioctl_common(ifp, cmd, data)) != 0) + break; + /* XXX re-use ether_ioctl() */ + switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + case IFF_UP|IFF_RUNNING: + rum_update_promisc(sc); + break; + case IFF_UP: + rum_init(ifp); + break; + case IFF_RUNNING: + rum_stop(ifp, 1); + break; + case 0: + break; } break; diff --git a/sys/dev/usb/if_upl.c b/sys/dev/usb/if_upl.c index 3a810983fac..fb7288fe15f 100644 --- a/sys/dev/usb/if_upl.c +++ b/sys/dev/usb/if_upl.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_upl.c,v 1.32 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_upl.c,v 1.33 2008/11/07 00:20:13 dyoung Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.32 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.33 2008/11/07 00:20:13 dyoung Exp $"); #include "opt_inet.h" #include "bpfilter.h" @@ -856,7 +856,7 @@ upl_ioctl(struct ifnet *ifp, u_long command, void *data) s = splnet(); switch(command) { - case SIOCSIFADDR: + case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; upl_init(sc); @@ -876,17 +876,22 @@ upl_ioctl(struct ifnet *ifp, u_long command, void *data) break; case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (!(ifp->if_flags & IFF_RUNNING)) - upl_init(sc); - } else { - if (ifp->if_flags & IFF_RUNNING) - upl_stop(sc); + if ((error = ifioctl_common(ifp, command, data)) != 0) + break; + /* XXX re-use ether_ioctl() */ + switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + case IFF_UP: + upl_init(sc); + break; + case IFF_RUNNING: + upl_stop(sc); + break; + default: + break; } - error = 0; break; default: - error = EINVAL; + error = ifioctl_common(ifp, command, data); break; } diff --git a/sys/dev/usb/if_ural.c b/sys/dev/usb/if_ural.c index 7e746794318..8da6bb10d77 100644 --- a/sys/dev/usb/if_ural.c +++ b/sys/dev/usb/if_ural.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_ural.c,v 1.30 2008/05/24 16:40:58 cube Exp $ */ +/* $NetBSD: if_ural.c,v 1.31 2008/11/07 00:20:13 dyoung Exp $ */ /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/if_ural.c,v 1.40 2006/06/02 23:14:40 sam Exp $ */ /*- @@ -24,7 +24,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.30 2008/05/24 16:40:58 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.31 2008/11/07 00:20:13 dyoung Exp $"); #include "bpfilter.h" @@ -1505,14 +1505,21 @@ ural_ioctl(struct ifnet *ifp, u_long cmd, void *data) switch (cmd) { case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (ifp->if_flags & IFF_RUNNING) - ural_update_promisc(sc); - else - ural_init(ifp); - } else { - if (ifp->if_flags & IFF_RUNNING) - ural_stop(ifp, 1); + if ((error = ifioctl_common(ifp, cmd, data)) != 0) + break; + /* XXX re-use ether_ioctl() */ + switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + case IFF_UP|IFF_RUNNING: + ural_update_promisc(sc); + break; + case IFF_UP: + ural_init(ifp); + break; + case IFF_RUNNING: + ural_stop(ifp, 1); + break; + case 0: + break; } break; diff --git a/sys/dev/usb/if_zyd.c b/sys/dev/usb/if_zyd.c index 429d5422047..c324b313ba1 100644 --- a/sys/dev/usb/if_zyd.c +++ b/sys/dev/usb/if_zyd.c @@ -1,5 +1,5 @@ /* $OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $ */ -/* $NetBSD: if_zyd.c,v 1.14 2008/09/21 09:38:27 freza Exp $ */ +/* $NetBSD: if_zyd.c,v 1.15 2008/11/07 00:20:13 dyoung Exp $ */ /*- * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr> @@ -22,7 +22,7 @@ * ZyDAS ZD1211/ZD1211B USB WLAN driver. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.14 2008/09/21 09:38:27 freza Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.15 2008/11/07 00:20:13 dyoung Exp $"); #include "bpfilter.h" @@ -2419,18 +2419,24 @@ zyd_ioctl(struct ifnet *ifp, u_long cmd, void *data) switch (cmd) { case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (!(ifp->if_flags & IFF_RUNNING)) - zyd_init(ifp); - } else { - if (ifp->if_flags & IFF_RUNNING) - zyd_stop(ifp, 1); + if ((error = ifioctl_common(ifp, cmd, data)) != 0) + break; + /* XXX re-use ether_ioctl() */ + switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) { + case IFF_UP: + zyd_init(ifp); + break; + case IFF_RUNNING: + zyd_stop(ifp, 1); + break; + default: + break; } break; default: if (!sc->attached) - error = ENOTTY; + error = ENXIO; else error = ieee80211_ioctl(ic, cmd, data); } |
