PERFORCE change 81444 for review

Robert Watson rwatson at FreeBSD.org
Thu Aug 4 13:01:58 GMT 2005


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

Change 81444 by rwatson at rwatson_zoo on 2005/08/04 13:01:38

	Supporting paperwork for _DRV_ changes on flags: inspect, annotate,
	assert in various if.c flag-related activities, especially for
	functions that simply expect a variable flag argument.
	
	Annotate that currently all _DRV_ flags are not changeable from
	user space, so don't require special handling.  However, for
	monitoring purposes, mix them into the flags returned to user
	space.

Affected files ...

.. //depot/projects/netsmp/src/sys/net/if.c#8 edit
.. //depot/projects/netsmp/src/sys/net/if.h#3 edit

Differences ...

==== //depot/projects/netsmp/src/sys/net/if.c#8 (text+ko) ====

@@ -1030,6 +1030,8 @@
 {
 	struct ifaddr *ifa;
 
+	KASSERT(flag == IFF_UP, ("if_unroute: flag != IFF_UP"));
+
 	ifp->if_flags &= ~flag;
 	getmicrotime(&ifp->if_lastchange);
 	TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
@@ -1053,6 +1055,8 @@
 {
 	struct ifaddr *ifa;
 
+	KASSERT(flag == IFF_UP, ("if_route: flag != IFF_UP"));
+
 	ifp->if_flags |= flag;
 	getmicrotime(&ifp->if_lastchange);
 	TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
@@ -1230,7 +1234,7 @@
 	struct ifreq *ifr;
 	struct ifstat *ifs;
 	int error = 0;
-	int new_flags;
+	int new_flags, temp_flags;
 	size_t namelen, onamelen;
 	char new_name[IFNAMSIZ];
 	struct ifaddr *ifa;
@@ -1243,8 +1247,9 @@
 		break;
 
 	case SIOCGIFFLAGS:
-		ifr->ifr_flags = ifp->if_flags & 0xffff;
-		ifr->ifr_flagshigh = ifp->if_flags >> 16;
+		temp_flags = ifp->if_flags | ifp->if_drv_flags;
+		ifr->ifr_flags = temp_flags & 0xffff;
+		ifr->ifr_flagshigh = temp_flags >> 16;
 		break;
 
 	case SIOCGIFCAP:
@@ -1274,6 +1279,11 @@
 		error = suser(td);
 		if (error)
 			return (error);
+		/*
+		 * XXXRW: Currently, no driver owned flags pass the
+		 * IFF_CANTCHANGE check, so we don't need special handling
+		 * here yet.
+		 */
 		new_flags = (ifr->ifr_flags & 0xffff) |
 		    (ifr->ifr_flagshigh << 16);
 		if (ifp->if_flags & IFF_SMART) {
@@ -1611,10 +1621,12 @@
 }
 
 /*
- * The code common to hadling reference counted flags,
+ * The code common to handling reference counted flags,
  * e.g., in ifpromisc() and if_allmulti().
  * The "pflag" argument can specify a permanent mode flag,
  * such as IFF_PPROMISC for promiscuous mode; should be 0 if none.
+ *
+ * XXXRW: Only to be used on stack-owned flags, not driver-owned flags.
  */
 static int
 if_setflag(struct ifnet *ifp, int flag, int pflag, int *refcount, int onswitch)
@@ -1623,6 +1635,9 @@
 	int error;
 	int oldflags, oldcount;
 
+	KASSERT((flag & (IFF_DRV_OACTIVE|IFF_DRV_RUNNING)) == 0,
+	    ("if_setflag: setting driver-ownded flag %d", flag));
+
 	/* Sanity checks to catch programming errors */
 	if (onswitch) {
 		if (*refcount < 0) {
@@ -2259,7 +2274,11 @@
 		ifp->if_obytes += m->m_pkthdr.len + adjust;
 		if (m->m_flags & (M_BCAST|M_MCAST))
 			ifp->if_omcasts++;
-		active = ifp->if_flags & IFF_OACTIVE;
+		/*
+		 * XXXRW: Technically, we'd like the driver to do this to
+		 * avoid races.
+		 */
+		active = ifp->if_drv_flags & IFF_DRV_OACTIVE;
 	}
 	_IF_ENQUEUE(ifq, m);
 	IF_UNLOCK(ifq);

==== //depot/projects/netsmp/src/sys/net/if.h#3 (text+ko) ====

@@ -159,7 +159,7 @@
 
 /* flags set internally only: */
 #define	IFF_CANTCHANGE \
-	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
+	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\
 	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
 	    IFF_POLLING)
 


More information about the p4-projects mailing list