Re: usb network detach safety
On Sat, Oct 23, 2010 at 04:20:12PM +, Jacob Meuser wrote: > like the timeout(9) diff, but for network interfaces. I discussed this > a bit with damien@ when I ran into this with rum(4), and he suggested > testing if_flags. I don't work on network drivers ... new version after feedback from deraadt. check ifp->if_softc instead of ifp->if_flags and just skip net detach instead of returning early. ok? fwiw, the previous version was in snaps, along with some other diffs, for a while, maybe the first two weeks of oct or so. -- jake...@sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org Index: if_atu.c === RCS file: /cvs/src/sys/dev/usb/if_atu.c,v retrieving revision 1.95 diff -u -p -r1.95 if_atu.c --- if_atu.c23 Oct 2010 15:42:09 - 1.95 +++ if_atu.c23 Oct 2010 16:53:44 - @@ -1504,8 +1504,10 @@ atu_detach(struct device *self, int flag if (sc->atu_ep[ATU_ENDPT_RX] != NULL) usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]); - ieee80211_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_softc != NULL) { + ieee80211_ifdetach(ifp); + if_detach(ifp); + } } return(0); Index: if_aue.c === RCS file: /cvs/src/sys/dev/usb/if_aue.c,v retrieving revision 1.81 diff -u -p -r1.81 if_aue.c --- if_aue.c23 Oct 2010 16:14:06 - 1.81 +++ if_aue.c23 Oct 2010 16:53:45 - @@ -872,8 +872,10 @@ aue_detach(struct device *self, int flag mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_softc != NULL) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->aue_ep[AUE_ENDPT_TX] != NULL || Index: if_axe.c === RCS file: /cvs/src/sys/dev/usb/if_axe.c,v retrieving revision 1.101 diff -u -p -r1.101 if_axe.c --- if_axe.c23 Oct 2010 16:14:07 - 1.101 +++ if_axe.c23 Oct 2010 16:53:45 - @@ -864,8 +864,10 @@ axe_detach(struct device *self, int flag mii_detach(&sc->axe_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->axe_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_softc != NULL) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->axe_ep[AXE_ENDPT_TX] != NULL || Index: if_cdce.c === RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v retrieving revision 1.46 diff -u -p -r1.46 if_cdce.c --- if_cdce.c 24 Sep 2010 08:33:58 - 1.46 +++ if_cdce.c 23 Oct 2010 16:53:46 - @@ -380,9 +380,10 @@ cdce_detach(struct device *self, int fla if (ifp->if_flags & IFF_RUNNING) cdce_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_softc != NULL) { + ether_ifdetach(ifp); + if_detach(ifp); + } sc->cdce_attached = 0; splx(s); Index: if_cue.c === RCS file: /cvs/src/sys/dev/usb/if_cue.c,v retrieving revision 1.55 diff -u -p -r1.55 if_cue.c --- if_cue.c23 Oct 2010 16:14:07 - 1.55 +++ if_cue.c23 Oct 2010 16:53:46 - @@ -576,9 +576,10 @@ cue_detach(struct device *self, int flag if (ifp->if_flags & IFF_RUNNING) cue_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_softc != NULL) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->cue_ep[CUE_ENDPT_TX] != NULL || Index: if_kue.c === RCS file: /cvs/src/sys/dev/usb/if_kue.c,v retrieving revision 1.60 diff -u -p -r1.60 if_kue.c --- if_kue.c24 Sep 2010 08:33:58 - 1.60 +++ if_kue.c23 Oct 2010 16:53:46 - @@ -570,9 +570,10 @@ kue_detach(struct device *self, int flag if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_softc != NULL) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->kue_ep[KUE_ENDPT_TX] != NULL || Index: if_mos.c === RCS file: /cvs/src/sys/dev/usb/if_mos.c,v retrieving revision 1.10 diff -u -p -r1.10 if_mos.c --- if_mos.c23 Oct 2010 16:14:07 - 1.10 +++ if_mos.c23 Oct 2010 16:53:47 - @@ -799,8 +799,10 @@ mos_detac
usb network detach safety
like the timeout(9) diff, but for network interfaces. I discussed this a bit with damien@ when I ran into this with rum(4), and he suggested testing if_flags. I don't work on network drivers ... ok? -- jake...@sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org Index: if_atu.c === RCS file: /cvs/src/sys/dev/usb/if_atu.c,v retrieving revision 1.95 diff -u -p -r1.95 if_atu.c --- if_atu.c23 Oct 2010 15:42:09 - 1.95 +++ if_atu.c23 Oct 2010 16:16:02 - @@ -1504,6 +1504,9 @@ atu_detach(struct device *self, int flag if (sc->atu_ep[ATU_ENDPT_RX] != NULL) usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]); + if (ifp->if_flags == 0) + return(0); + ieee80211_ifdetach(ifp); if_detach(ifp); } Index: if_aue.c === RCS file: /cvs/src/sys/dev/usb/if_aue.c,v retrieving revision 1.81 diff -u -p -r1.81 if_aue.c --- if_aue.c23 Oct 2010 16:14:06 - 1.81 +++ if_aue.c23 Oct 2010 16:16:02 - @@ -872,8 +872,10 @@ aue_detach(struct device *self, int flag mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->aue_ep[AUE_ENDPT_TX] != NULL || Index: if_axe.c === RCS file: /cvs/src/sys/dev/usb/if_axe.c,v retrieving revision 1.101 diff -u -p -r1.101 if_axe.c --- if_axe.c23 Oct 2010 16:14:07 - 1.101 +++ if_axe.c23 Oct 2010 16:16:02 - @@ -864,8 +864,10 @@ axe_detach(struct device *self, int flag mii_detach(&sc->axe_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->axe_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->axe_ep[AXE_ENDPT_TX] != NULL || Index: if_cdce.c === RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v retrieving revision 1.46 diff -u -p -r1.46 if_cdce.c --- if_cdce.c 24 Sep 2010 08:33:58 - 1.46 +++ if_cdce.c 23 Oct 2010 16:16:03 - @@ -380,9 +380,10 @@ cdce_detach(struct device *self, int fla if (ifp->if_flags & IFF_RUNNING) cdce_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } sc->cdce_attached = 0; splx(s); Index: if_cue.c === RCS file: /cvs/src/sys/dev/usb/if_cue.c,v retrieving revision 1.55 diff -u -p -r1.55 if_cue.c --- if_cue.c23 Oct 2010 16:14:07 - 1.55 +++ if_cue.c23 Oct 2010 16:16:03 - @@ -576,9 +576,10 @@ cue_detach(struct device *self, int flag if (ifp->if_flags & IFF_RUNNING) cue_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->cue_ep[CUE_ENDPT_TX] != NULL || Index: if_kue.c === RCS file: /cvs/src/sys/dev/usb/if_kue.c,v retrieving revision 1.60 diff -u -p -r1.60 if_kue.c --- if_kue.c24 Sep 2010 08:33:58 - 1.60 +++ if_kue.c23 Oct 2010 16:16:04 - @@ -570,9 +570,10 @@ kue_detach(struct device *self, int flag if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); - ether_ifdetach(ifp); - - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->kue_ep[KUE_ENDPT_TX] != NULL || Index: if_mos.c === RCS file: /cvs/src/sys/dev/usb/if_mos.c,v retrieving revision 1.10 diff -u -p -r1.10 if_mos.c --- if_mos.c23 Oct 2010 16:14:07 - 1.10 +++ if_mos.c23 Oct 2010 16:16:04 - @@ -799,8 +799,10 @@ mos_detach(struct device *self, int flag mii_detach(&sc->mos_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->mos_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + if (ifp->if_flags != 0) { + ether_ifdetach(ifp); + if_detach(ifp); + } #ifdef DIAGNOSTIC if (sc->mos_ep[MOS_ENDPT_TX] != NULL || Index: if_ral.c ===