Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Oct 2010 16:20:49 +0000 (UTC)
From:      Sergey Kandaurov <pluknet@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r214136 - in head/sys: net sys
Message-ID:  <201010211620.o9LGKnmT096042@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pluknet
Date: Thu Oct 21 16:20:48 2010
New Revision: 214136
URL: http://svn.freebsd.org/changeset/base/214136

Log:
  Reshuffle SIOCGIFCONF32 handler from r155224.
  
  - move all the chunks into one file, which allows to hide SIOCGIFCONF32
    global definition as well.
  - replace __amd64__ with proper COMPAT_FREEBSD32 around.
  - handle 32bit capacity before going into the handler itself instead of
    doing internal 32bit specific changes within it (e.g. as it's done for
    SIOCGDEFIFACE32_IN6).
  - use explicitely sized types for ABI compat.
  
  Approved by:	kib (mentor)
  MFC after:	2 weeks

Modified:
  head/sys/net/if.c
  head/sys/net/if.h
  head/sys/sys/sockio.h

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Thu Oct 21 16:08:31 2010	(r214135)
+++ head/sys/net/if.c	Thu Oct 21 16:20:48 2010	(r214136)
@@ -92,6 +92,11 @@
 
 #include <security/mac/mac_framework.h>
 
+#ifdef COMPAT_FREEBSD32
+#include <sys/mount.h>
+#include <compat/freebsd32/freebsd32.h>
+#endif
+
 struct ifindex_entry {
 	struct  ifnet *ife_ifnet;
 };
@@ -2402,6 +2407,17 @@ ifhwioctl(u_long cmd, struct ifnet *ifp,
 	return (error);
 }
 
+#ifdef COMPAT_FREEBSD32
+struct ifconf32 {
+	int32_t	ifc_len;
+	union {
+		uint32_t	ifcu_buf;
+		uint32_t	ifcu_req;
+	} ifc_ifcu;
+};
+#define	SIOCGIFCONF32	_IOWR('i', 36, struct ifconf32)
+#endif
+
 /*
  * Interface ioctls.
  */
@@ -2416,10 +2432,21 @@ ifioctl(struct socket *so, u_long cmd, c
 	switch (cmd) {
 	case SIOCGIFCONF:
 	case OSIOCGIFCONF:
-#ifdef __amd64__
+		return (ifconf(cmd, data));
+
+#ifdef COMPAT_FREEBSD32
 	case SIOCGIFCONF32:
+		{
+			struct ifconf32 *ifc32;
+			struct ifconf ifc;
+
+			ifc32 = (struct ifconf32 *)data;
+			ifc.ifc_len = ifc32->ifc_len;
+			ifc.ifc_buf = PTRIN(ifc32->ifc_buf);
+
+			return (ifconf(SIOCGIFCONF, (void *)&ifc));
+		}
 #endif
-		return (ifconf(cmd, data));
 	}
 	ifr = (struct ifreq *)data;
 
@@ -2646,23 +2673,12 @@ static int
 ifconf(u_long cmd, caddr_t data)
 {
 	struct ifconf *ifc = (struct ifconf *)data;
-#ifdef __amd64__
-	struct ifconf32 *ifc32 = (struct ifconf32 *)data;
-	struct ifconf ifc_swab;
-#endif
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 	struct ifreq ifr;
 	struct sbuf *sb;
 	int error, full = 0, valid_len, max_len;
 
-#ifdef __amd64__
-	if (cmd == SIOCGIFCONF32) {
-		ifc_swab.ifc_len = ifc32->ifc_len;
-		ifc_swab.ifc_buf = (caddr_t)(uintptr_t)ifc32->ifc_buf;
-		ifc = &ifc_swab;
-	}
-#endif
 	/* Limit initial buffer size to MAXPHYS to avoid DoS from userspace. */
 	max_len = MAXPHYS - 1;
 
@@ -2752,10 +2768,6 @@ again:
 	}
 
 	ifc->ifc_len = valid_len;
-#ifdef __amd64__
-	if (cmd == SIOCGIFCONF32)
-		ifc32->ifc_len = valid_len;
-#endif
 	sbuf_finish(sb);
 	error = copyout(sbuf_data(sb), ifc->ifc_req, ifc->ifc_len);
 	sbuf_delete(sb);

Modified: head/sys/net/if.h
==============================================================================
--- head/sys/net/if.h	Thu Oct 21 16:08:31 2010	(r214135)
+++ head/sys/net/if.h	Thu Oct 21 16:20:48 2010	(r214136)
@@ -391,16 +391,6 @@ struct	ifconf {
 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
 };
 
-#if defined (__amd64__)
-struct ifconf32 {
-	int	ifc_len;		/* size of associated buffer */
-	union {
-		u_int	ifcu_buf;
-		u_int	ifcu_req;
-	} ifc_ifcu;
-};
-#endif
-
 /*
  * interface groups
  */

Modified: head/sys/sys/sockio.h
==============================================================================
--- head/sys/sys/sockio.h	Thu Oct 21 16:08:31 2010	(r214135)
+++ head/sys/sys/sockio.h	Thu Oct 21 16:20:48 2010	(r214136)
@@ -62,9 +62,6 @@
 #define	SIOCSIFBRDADDR	 _IOW('i', 19, struct ifreq)	/* set broadcast addr */
 #define	OSIOCGIFCONF	_IOWR('i', 20, struct ifconf)	/* get ifnet list */
 #define	SIOCGIFCONF	_IOWR('i', 36, struct ifconf)	/* get ifnet list */
-#if  defined (__amd64__)
-#define	SIOCGIFCONF32	_IOWR('i', 36, struct ifconf32)	/* get ifnet list */
-#endif
 #define	OSIOCGIFNETMASK	_IOWR('i', 21, struct ifreq)	/* get net addr mask */
 #define	SIOCGIFNETMASK	_IOWR('i', 37, struct ifreq)	/* get net addr mask */
 #define	SIOCSIFNETMASK	 _IOW('i', 22, struct ifreq)	/* set net addr mask */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010211620.o9LGKnmT096042>