PERFORCE change 64829 for review

Sam Leffler sam at FreeBSD.org
Wed Nov 10 10:01:05 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=64829

Change 64829 by sam at sam_ebb on 2004/11/10 18:00:15

	Fix if link state change handling:
	
	o move code from mii to if where it belongs
	o remove internal glop about mapping a link state change ot a knote
	o remove bogus link state change stuff from net80211
	o add proper link state change notification to net80211 where it belongs
	
	With these changes dhclient no longer tries to get an ip address too
	soon and correctly re-acquires a lease when changing ap's.

Affected files ...

.. //depot/projects/wifi/sys/dev/mii/mii.c#2 edit
.. //depot/projects/wifi/sys/net/if.c#3 edit
.. //depot/projects/wifi/sys/net/if_var.h#4 edit
.. //depot/projects/wifi/sys/net80211/ieee80211.c#4 edit
.. //depot/projects/wifi/sys/net80211/ieee80211_freebsd.c#2 edit

Differences ...

==== //depot/projects/wifi/sys/dev/mii/mii.c#2 (text+ko) ====

@@ -228,47 +228,30 @@
 	return;
 }
 
-void	(*vlan_link_state_p)(struct ifnet *, int);	/* XXX: private from if_vlan */
-
 static void
 miibus_linkchg(dev)
-	device_t dev;
+	device_t		dev;
 {
-	struct mii_data *mii;
-	struct ifnet *ifp;
-	device_t parent;
-	int link, link_state;
+	struct mii_data		*mii;
+	device_t		parent;
+	int			link_state;
 
 	parent = device_get_parent(dev);
 	MIIBUS_LINKCHG(parent);
 
 	mii = device_get_softc(dev);
-	/*
-	 * Note that each NIC's softc must start with an ifnet structure.
-	 */
-	ifp = device_get_softc(parent);
 	
 	if (mii->mii_media_status & IFM_AVALID) {
-		if (mii->mii_media_status & IFM_ACTIVE) {
-			link = NOTE_LINKUP;
+		if (mii->mii_media_status & IFM_ACTIVE)
 			link_state = LINK_STATE_UP;
-		} else {
-			link = NOTE_LINKDOWN;
+		else
 			link_state = LINK_STATE_DOWN;
-		}
-	} else {
-		link = NOTE_LINKINV;
+	} else
 		link_state = LINK_STATE_UNKNOWN;
-	}
-
-	/* Notify that the link state has changed. */
-	if (ifp->if_link_state != link_state) {
-		ifp->if_link_state = link_state;
-		rt_ifmsg(ifp);
-		KNOTE_UNLOCKED(&ifp->if_klist, link);
-		if (ifp->if_nvlans != 0)
-			(*vlan_link_state_p)(ifp, link);
-	}
+	/*
+	 * Note that each NIC's softc must start with an ifnet structure.
+	 */
+	if_link_state_change(device_get_softc(parent), link_state);
 }
 
 static void

==== //depot/projects/wifi/sys/net/if.c#3 (text+ko) ====

@@ -953,6 +953,32 @@
 #endif
 }
 
+void	(*vlan_link_state_p)(struct ifnet *, int);	/* XXX: private from if_vlan */
+
+/*
+ * Handle a change in the interface link state.
+ */
+void
+if_link_state_change(struct ifnet *ifp, int link_state)
+{
+	int link;
+
+	/* Notify that the link state has changed. */
+	if (ifp->if_link_state != link_state) {
+		ifp->if_link_state = link_state;
+		rt_ifmsg(ifp);
+		if (link_state == LINK_STATE_UP)
+			link = NOTE_LINKUP;
+		else if (link_state == LINK_STATE_DOWN)
+			link = NOTE_LINKDOWN;
+		else
+			link = NOTE_LINKINV;
+		KNOTE_UNLOCKED(&ifp->if_klist, link);
+		if (ifp->if_nvlans != 0)
+			(*vlan_link_state_p)(ifp, link);
+	}
+}
+
 /*
  * Mark an interface down and notify protocols of
  * the transition.

==== //depot/projects/wifi/sys/net/if_var.h#4 (text+ko) ====

@@ -663,6 +663,7 @@
 void	if_detach(struct ifnet *);
 void	if_down(struct ifnet *);
 void	if_initname(struct ifnet *, const char *, int);
+void	if_link_state_change(struct ifnet *, int, int);
 int	if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
 int	if_setlladdr(struct ifnet *, const u_char *, int);
 void	if_up(struct ifnet *);

==== //depot/projects/wifi/sys/net80211/ieee80211.c#4 (text+ko) ====

@@ -590,11 +590,8 @@
 	}
 	imr->ifm_status = IFM_AVALID;
 	imr->ifm_active = IFM_IEEE80211;
-	if (ic->ic_state == IEEE80211_S_RUN) {
-		ifp->if_link_state = LINK_STATE_UP;
+	if (ic->ic_state == IEEE80211_S_RUN)
 		imr->ifm_status |= IFM_ACTIVE;
-	} else
-		ifp->if_link_state = LINK_STATE_DOWN;
 	/*
 	 * Calculate a current rate if possible.
 	 */

==== //depot/projects/wifi/sys/net80211/ieee80211_freebsd.c#2 (text+ko) ====

@@ -121,6 +121,7 @@
 		rt_ieee80211msg(ifp, newassoc ?
 			RTM_IEEE80211_ASSOC : RTM_IEEE80211_REASSOC,
 			&iev, sizeof(iev));
+		if_link_state_change(ifp, LINK_STATE_UP);
 	} else if (newassoc) {
 		/* fire off wireless event only for new station */
 		memset(&iev, 0, sizeof(iev));
@@ -137,6 +138,7 @@
 
 	if (ni == ic->ic_bss) {
 		rt_ieee80211msg(ifp, RTM_IEEE80211_DISASSOC, NULL, 0);
+		if_link_state_change(ifp, LINK_STATE_DOWN);
 	} else {
 		/* fire off wireless event station leaving */
 		memset(&iev, 0, sizeof(iev));


More information about the p4-projects mailing list