Date: 16 Nov 2001 18:10:08 +0100 From: Dag-Erling Smorgrav <des@ofug.org> To: Ian Dowse <iedowse@maths.tcd.ie> Cc: Takanori Saneto <sanewo@ba2.so-net.ne.jp>, emulation@FreeBSD.ORG Subject: Re: Linuxulator MFC and VMware Message-ID: <xzpofm2od5b.fsf@flood.ping.uio.no> In-Reply-To: <xzpsnbeodfl.fsf@flood.ping.uio.no> References: <200111161658.aa21165@salmon.maths.tcd.ie> <xzpsnbeodfl.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Corrected patch attached (and uploaded to the usual place).
DES
--
Dag-Erling Smorgrav - des@ofug.org
[-- Attachment #2 --]
Index: sys/compat/linux/linux_ioctl.c
===================================================================
RCS file: /home/ncvs/src/sys/compat/linux/linux_ioctl.c,v
retrieving revision 1.71
diff -u -r1.71 linux_ioctl.c
--- sys/compat/linux/linux_ioctl.c 20 Oct 2001 00:01:26 -0000 1.71
+++ sys/compat/linux/linux_ioctl.c 16 Nov 2001 17:08:55 -0000
@@ -66,6 +66,7 @@
static linux_ioctl_function_t linux_ioctl_sound;
static linux_ioctl_function_t linux_ioctl_termio;
static linux_ioctl_function_t linux_ioctl_private;
+static linux_ioctl_function_t linux_ioctl_special;
static struct linux_ioctl_handler cdrom_handler =
{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX };
@@ -1348,9 +1349,11 @@
return (ENOIOCTL);
}
-#define IFP_IS_ETH(ifp) ((ifp->if_flags & \
- (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST)) == \
- IFF_BROADCAST)
+/*
+ * Criteria for interface name translation
+ */
+
+#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
/*
* Construct the Linux name for an interface
@@ -1541,7 +1544,8 @@
{
char lifname[LINUX_IFNAMSIZ], ifname[IFNAMSIZ];
struct ifnet *ifp;
- int error;
+ struct file *fp;
+ int error, type;
KASSERT(LINUX_IFNAMSIZ == IFNAMSIZ,
(__FUNCTION__ "(): LINUX_IFNAMSIZ != IFNAMSIZ"));
@@ -1549,6 +1553,26 @@
ifp = NULL;
error = 0;
+ mtx_lock(&Giant);
+ if ((error = fget(td, args->fd, &fp)) != 0) {
+ mtx_unlock(&Giant);
+ return (error);
+ }
+ type = fp->f_type;
+ fdrop(fp, td);
+ mtx_unlock(&Giant);
+
+ if (type != DTYPE_SOCKET) {
+ /* not a socket - probably a tap / vmnet device */
+ switch (args->cmd) {
+ case LINUX_SIOCGIFADDR:
+ case LINUX_SIOCSIFADDR:
+ return (linux_ioctl_special(td, args));
+ default:
+ return (ENOTTY);
+ }
+ }
+
switch (args->cmd & 0xffff) {
case LINUX_FIOGETOWN:
@@ -1561,13 +1585,14 @@
case LINUX_SIOCSPGRP:
/* these ioctls don't take an interface name */
#ifdef DEBUG
- printf(__FUNCTION__ "(): ioctl %d\n",
- args->cmd & 0xffff);
+ printf(__FUNCTION__ "(): ioctl %d\n",
+ args->cmd & 0xffff);
#endif
break;
case LINUX_SIOCGIFFLAGS:
case LINUX_SIOCGIFADDR:
+ case LINUX_SIOCSIFADDR:
case LINUX_SIOCGIFDSTADDR:
case LINUX_SIOCGIFBRDADDR:
case LINUX_SIOCGIFNETMASK:
@@ -1584,8 +1609,8 @@
if (error != 0)
return (error);
#ifdef DEBUG
- printf(__FUNCTION__ "(): ioctl %d on %.*s\n",
- args->cmd & 0xffff, LINUX_IFNAMSIZ, lifname);
+ printf(__FUNCTION__ "(): ioctl %d on %.*s\n",
+ args->cmd & 0xffff, LINUX_IFNAMSIZ, lifname);
#endif
ifp = ifname_linux_to_bsd(lifname, ifname);
if (ifp == NULL)
@@ -1652,6 +1677,12 @@
error = ioctl(td, (struct ioctl_args *)args);
break;
+ case LINUX_SIOCSIFADDR:
+ /* XXX probably doesn't work, included for completeness */
+ args->cmd = SIOCSIFADDR;
+ error = ioctl(td, (struct ioctl_args *)args);
+ break;
+
case LINUX_SIOCGIFDSTADDR:
args->cmd = OSIOCGIFDSTADDR;
error = ioctl(td, (struct ioctl_args *)args);
@@ -1723,7 +1754,7 @@
copyout(lifname, (char *)args->arg, LINUX_IFNAMSIZ);
#ifdef DEBUG
- printf(__FUNCTION__ "(): returning %d\n", error);
+ printf(__FUNCTION__ "(): returning %d\n", error);
#endif
return (error);
}
@@ -1731,27 +1762,49 @@
/*
* Device private ioctl handler
*/
+
static int
linux_ioctl_private(struct thread *td, struct linux_ioctl_args *args)
{
- struct filedesc *fdp;
struct file *fp;
- int type;
+ int error, type;
- /* XXX is it sufficient to PROC_LOCK td->td_proc? */
mtx_lock(&Giant);
- fdp = td->td_proc->p_fd;
- if (args->fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[args->fd]) == NULL) {
+ if ((error = fget(td, args->fd, &fp)) != 0) {
mtx_unlock(&Giant);
- return (EBADF);
- } else {
- type = fp->f_type;
+ return (error);
}
+ type = fp->f_type;
+ fdrop(fp, td);
mtx_unlock(&Giant);
if (type == DTYPE_SOCKET)
return (linux_ioctl_socket(td, args));
return (ioctl(td, (struct ioctl_args *)args));
+}
+
+/*
+ * Special ioctl handler
+ */
+
+static int
+linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args)
+{
+ int error;
+
+ switch (args->cmd) {
+ case LINUX_SIOCGIFADDR:
+ args->cmd = SIOCGIFADDR;
+ error = ioctl(td, (struct ioctl_args *)args);
+ break;
+ case LINUX_SIOCSIFADDR:
+ args->cmd = SIOCSIFADDR;
+ error = ioctl(td, (struct ioctl_args *)args);
+ break;
+ default:
+ error = ENOIOCTL;
+ }
+
+ return (error);
}
/*
Index: sys/compat/linux/linux_ioctl.h
===================================================================
RCS file: /home/ncvs/src/sys/compat/linux/linux_ioctl.h,v
retrieving revision 1.7
diff -u -r1.7 linux_ioctl.h
--- sys/compat/linux/linux_ioctl.h 20 Oct 2001 00:01:26 -0000 1.7
+++ sys/compat/linux/linux_ioctl.h 7 Nov 2001 15:43:32 -0000
@@ -133,6 +133,7 @@
#define LINUX_SIOCGIFCONF 0x8912
#define LINUX_SIOCGIFFLAGS 0x8913
#define LINUX_SIOCGIFADDR 0x8915
+#define LINUX_SIOCSIFADDR 0x8916
#define LINUX_SIOCGIFDSTADDR 0x8917
#define LINUX_SIOCGIFBRDADDR 0x8919
#define LINUX_SIOCGIFNETMASK 0x891b
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpofm2od5b.fsf>
