Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_ioctl.c revision 1.34
      1 /*	$NetBSD: netbsd32_ioctl.c,v 1.34 2007/05/30 00:00:59 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * handle ioctl conversions from netbsd32 -> 64-bit kernel
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.34 2007/05/30 00:00:59 christos Exp $");
     37 
     38 #if defined(_KERNEL_OPT)
     39 #include "opt_ktrace.h"
     40 #endif
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/filedesc.h>
     45 #include <sys/ioctl.h>
     46 #include <sys/file.h>
     47 #include <sys/proc.h>
     48 #include <sys/socketvar.h>
     49 #include <sys/audioio.h>
     50 #include <sys/disklabel.h>
     51 #include <sys/dkio.h>
     52 #include <sys/malloc.h>
     53 #include <sys/sockio.h>
     54 #include <sys/socket.h>
     55 #include <sys/ttycom.h>
     56 #include <sys/mount.h>
     57 #include <sys/syscallargs.h>
     58 #ifdef KTRACE
     59 #include <sys/ktrace.h>
     60 #endif
     61 
     62 #ifdef __sparc__
     63 #include <dev/sun/fbio.h>
     64 #include <machine/openpromio.h>
     65 #endif
     66 
     67 #include <net/if.h>
     68 #include <net/route.h>
     69 
     70 #include <netinet/in.h>
     71 #include <netinet/in_var.h>
     72 #include <netinet/igmp.h>
     73 #include <netinet/igmp_var.h>
     74 #include <netinet/ip_mroute.h>
     75 
     76 #include <compat/sys/sockio.h>
     77 
     78 #include <compat/netbsd32/netbsd32.h>
     79 #include <compat/netbsd32/netbsd32_ioctl.h>
     80 #include <compat/netbsd32/netbsd32_syscallargs.h>
     81 
     82 /* prototypes for the converters */
     83 static inline void netbsd32_to_partinfo(struct netbsd32_partinfo *,
     84 					  struct partinfo *, u_long);
     85 #if 0
     86 static inline void netbsd32_to_format_op(struct netbsd32_format_op *,
     87 					   struct format_op *, u_long);
     88 #endif
     89 static inline void netbsd32_to_ifreq(struct netbsd32_ifreq *, struct ifreq *,
     90 				       u_long cmd);
     91 static inline void netbsd32_to_ifconf(struct netbsd32_ifconf *,
     92 					struct ifconf *, u_long);
     93 static inline void netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *,
     94 					    struct ifmediareq *, u_long);
     95 static inline void netbsd32_to_ifdrv(struct netbsd32_ifdrv *, struct ifdrv *,
     96 				       u_long);
     97 static inline void netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *,
     98 					      struct sioc_vif_req *, u_long);
     99 static inline void netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *,
    100 					     struct sioc_sg_req *, u_long);
    101 static inline void netbsd32_from_partinfo(struct partinfo *,
    102 					    struct netbsd32_partinfo *, u_long);
    103 #if 0
    104 static inline void netbsd32_from_format_op(struct format_op *,
    105 					     struct netbsd32_format_op *,
    106 					     u_long);
    107 #endif
    108 static inline void netbsd32_from_ifreq(struct ifreq *,
    109                                          struct netbsd32_ifreq *, u_long);
    110 static inline void netbsd32_from_ifconf(struct ifconf *,
    111 					  struct netbsd32_ifconf *, u_long);
    112 static inline void netbsd32_from_ifmediareq(struct ifmediareq *,
    113 					      struct netbsd32_ifmediareq *,
    114 					      u_long);
    115 static inline void netbsd32_from_ifdrv(struct ifdrv *,
    116 					 struct netbsd32_ifdrv *, u_long);
    117 static inline void netbsd32_from_sioc_vif_req(struct sioc_vif_req *,
    118 						struct netbsd32_sioc_vif_req *,
    119 						u_long);
    120 static inline void netbsd32_from_sioc_sg_req(struct sioc_sg_req *,
    121 					       struct netbsd32_sioc_sg_req *,
    122 					       u_long);
    123 
    124 /* convert to/from different structures */
    125 
    126 static inline void
    127 netbsd32_to_partinfo(s32p, p, cmd)
    128 	struct netbsd32_partinfo *s32p;
    129 	struct partinfo *p;
    130 	u_long cmd;
    131 {
    132 
    133 	p->disklab = (struct disklabel *)NETBSD32PTR64(s32p->disklab);
    134 	p->part = (struct partition *)NETBSD32PTR64(s32p->part);
    135 }
    136 
    137 #if 0
    138 static inline void
    139 netbsd32_to_format_op(s32p, p, cmd)
    140 	struct netbsd32_format_op *s32p;
    141 	struct format_op *p;
    142 	u_long cmd;
    143 {
    144 
    145 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
    146 	p->df_count = s32p->df_count;
    147 	p->df_startblk = s32p->df_startblk;
    148 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
    149 }
    150 #endif
    151 
    152 static inline void
    153 netbsd32_to_ifreq(s32p, p, cmd)
    154 	struct netbsd32_ifreq *s32p;
    155 	struct ifreq *p;
    156 	u_long cmd;
    157 {
    158 
    159 	memcpy(p, s32p, sizeof *s32p);
    160 	/*
    161 	 * XXX
    162 	 * struct ifreq says the same, but sometimes the ifr_data
    163 	 * union member needs to be converted to 64 bits... this
    164 	 * is very driver specific and so we ignore it for now..
    165 	 */
    166 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    167 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    168 }
    169 
    170 static inline void
    171 netbsd32_to_ifconf(s32p, p, cmd)
    172 	struct netbsd32_ifconf *s32p;
    173 	struct ifconf *p;
    174 	u_long cmd;
    175 {
    176 
    177 	p->ifc_len = s32p->ifc_len;
    178 	/* ifc_buf & ifc_req are the same size so this works */
    179 	p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
    180 }
    181 
    182 static inline void
    183 netbsd32_to_ifmediareq(s32p, p, cmd)
    184 	struct netbsd32_ifmediareq *s32p;
    185 	struct ifmediareq *p;
    186 	u_long cmd;
    187 {
    188 
    189 	memcpy(p, s32p, sizeof *s32p);
    190 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
    191 }
    192 
    193 static inline void
    194 netbsd32_to_ifdrv(s32p, p, cmd)
    195 	struct netbsd32_ifdrv *s32p;
    196 	struct ifdrv *p;
    197 	u_long cmd;
    198 {
    199 
    200 	memcpy(p, s32p, sizeof *s32p);
    201 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
    202 }
    203 
    204 static inline void
    205 netbsd32_to_sioc_vif_req(s32p, p, cmd)
    206 	struct netbsd32_sioc_vif_req *s32p;
    207 	struct sioc_vif_req *p;
    208 	u_long cmd;
    209 {
    210 
    211 	p->vifi = s32p->vifi;
    212 	p->icount = (u_long)s32p->icount;
    213 	p->ocount = (u_long)s32p->ocount;
    214 	p->ibytes = (u_long)s32p->ibytes;
    215 	p->obytes = (u_long)s32p->obytes;
    216 }
    217 
    218 static inline void
    219 netbsd32_to_sioc_sg_req(s32p, p, cmd)
    220 	struct netbsd32_sioc_sg_req *s32p;
    221 	struct sioc_sg_req *p;
    222 	u_long cmd;
    223 {
    224 
    225 	p->src = s32p->src;
    226 	p->grp = s32p->grp;
    227 	p->pktcnt = (u_long)s32p->pktcnt;
    228 	p->bytecnt = (u_long)s32p->bytecnt;
    229 	p->wrong_if = (u_long)s32p->wrong_if;
    230 }
    231 
    232 /*
    233  * handle ioctl conversions from 64-bit kernel -> netbsd32
    234  */
    235 
    236 static inline void
    237 netbsd32_from_partinfo(p, s32p, cmd)
    238 	struct partinfo *p;
    239 	struct netbsd32_partinfo *s32p;
    240 	u_long cmd;
    241 {
    242 
    243 	NETBSD32PTR32(s32p->disklab, p->disklab);
    244 	NETBSD32PTR32(s32p->part, p->part);
    245 }
    246 
    247 #if 0
    248 static inline void
    249 netbsd32_from_format_op(p, s32p, cmd)
    250 	struct format_op *p;
    251 	struct netbsd32_format_op *s32p;
    252 	u_long cmd;
    253 {
    254 
    255 /* filled in */
    256 #if 0
    257 	s32p->df_buf = (netbsd32_charp)p->df_buf;
    258 #endif
    259 	s32p->df_count = p->df_count;
    260 	s32p->df_startblk = p->df_startblk;
    261 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
    262 }
    263 #endif
    264 
    265 static inline void
    266 netbsd32_from_ifreq(p, s32p, cmd)
    267 	struct ifreq *p;
    268 	struct netbsd32_ifreq *s32p;
    269 	u_long cmd;
    270 {
    271 
    272 	/*
    273 	 * XXX
    274 	 * struct ifreq says the same, but sometimes the ifr_data
    275 	 * union member needs to be converted to 64 bits... this
    276 	 * is very driver specific and so we ignore it for now..
    277 	 */
    278 	*s32p->ifr_name = *p->ifr_name;
    279 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    280 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    281 }
    282 
    283 static inline void
    284 netbsd32_from_ifconf(p, s32p, cmd)
    285 	struct ifconf *p;
    286 	struct netbsd32_ifconf *s32p;
    287 	u_long cmd;
    288 {
    289 
    290 	s32p->ifc_len = p->ifc_len;
    291 	/* ifc_buf & ifc_req are the same size so this works */
    292 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
    293 }
    294 
    295 static inline void
    296 netbsd32_from_ifmediareq(p, s32p, cmd)
    297 	struct ifmediareq *p;
    298 	struct netbsd32_ifmediareq *s32p;
    299 	u_long cmd;
    300 {
    301 
    302 	memcpy(s32p, p, sizeof *p);
    303 /* filled in? */
    304 #if 0
    305 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
    306 #endif
    307 }
    308 
    309 static inline void
    310 netbsd32_from_ifdrv(p, s32p, cmd)
    311 	struct ifdrv *p;
    312 	struct netbsd32_ifdrv *s32p;
    313 	u_long cmd;
    314 {
    315 
    316 	memcpy(s32p, p, sizeof *p);
    317 /* filled in? */
    318 #if 0
    319 	s32p->ifm_data = (netbsd32_u_longp_t)p->ifm_data;
    320 #endif
    321 }
    322 
    323 static inline void
    324 netbsd32_from_sioc_vif_req(p, s32p, cmd)
    325 	struct sioc_vif_req *p;
    326 	struct netbsd32_sioc_vif_req *s32p;
    327 	u_long cmd;
    328 {
    329 
    330 	s32p->vifi = p->vifi;
    331 	s32p->icount = (netbsd32_u_long)p->icount;
    332 	s32p->ocount = (netbsd32_u_long)p->ocount;
    333 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
    334 	s32p->obytes = (netbsd32_u_long)p->obytes;
    335 }
    336 
    337 static inline void
    338 netbsd32_from_sioc_sg_req(p, s32p, cmd)
    339 	struct sioc_sg_req *p;
    340 	struct netbsd32_sioc_sg_req *s32p;
    341 	u_long cmd;
    342 {
    343 
    344 	s32p->src = p->src;
    345 	s32p->grp = p->grp;
    346 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
    347 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
    348 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
    349 }
    350 
    351 
    352 /*
    353  * main ioctl syscall.
    354  *
    355  * ok, here we are in the biggy.  we have to do fix ups depending
    356  * on the ioctl command before and afterwards.
    357  */
    358 int
    359 netbsd32_ioctl(l, v, retval)
    360 	struct lwp *l;
    361 	void *v;
    362 	register_t *retval;
    363 {
    364 	struct netbsd32_ioctl_args /* {
    365 		syscallarg(int) fd;
    366 		syscallarg(netbsd32_u_long) com;
    367 		syscallarg(netbsd32_voidp) data;
    368 	} */ *uap = v;
    369 	struct proc *p = l->l_proc;
    370 	struct file *fp;
    371 	struct filedesc *fdp;
    372 	u_long com;
    373 	int error = 0;
    374 	u_int size, size32;
    375 	void *data, *memp = NULL;
    376 	void *data32, *memp32 = NULL;
    377 	int tmp;
    378 #define STK_PARAMS	128
    379 	u_long stkbuf[STK_PARAMS/sizeof(u_long)];
    380 	u_long stkbuf32[STK_PARAMS/sizeof(u_long)];
    381 
    382 	/*
    383 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
    384 	 * some after (_IOR), and some both (_IOWR).
    385 	 */
    386 #if 0
    387 	{
    388 char *dirs[8] = { "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
    389 		"INOUT", "VOID|IN|OUT!" };
    390 
    391 printf("netbsd32_ioctl(%d, %x, %x): %s group %c base %d len %d\n",
    392        SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data),
    393        dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
    394        IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
    395        IOCPARM_LEN(SCARG(uap, com)));
    396 	}
    397 #endif
    398 
    399 	fdp = p->p_fd;
    400 	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    401 		return (EBADF);
    402 
    403 	FILE_USE(fp);
    404 
    405 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    406 		error = EBADF;
    407 		goto out;
    408 	}
    409 
    410 	switch (com = SCARG(uap, com)) {
    411 	case FIONCLEX:
    412 		fdp->fd_ofileflags[SCARG(uap, fd)] &= ~UF_EXCLOSE;
    413 		goto out;
    414 
    415 	case FIOCLEX:
    416 		fdp->fd_ofileflags[SCARG(uap, fd)] |= UF_EXCLOSE;
    417 		goto out;
    418 	}
    419 
    420 	/*
    421 	 * Interpret high order word to find amount of data to be
    422 	 * copied to/from the user's address space.
    423 	 */
    424 	size32 = IOCPARM_LEN(com);
    425 	if (size32 > IOCPARM_MAX) {
    426 		error = ENOTTY;
    427 		goto out;
    428 	}
    429 	memp = NULL;
    430 	if (size32 > sizeof(stkbuf)) {
    431 		memp32 = malloc((u_long)size32, M_IOCTLOPS, M_WAITOK);
    432 		data32 = memp32;
    433 	} else
    434 		data32 = (void *)stkbuf32;
    435 	if (com&IOC_IN) {
    436 		if (size32) {
    437 			error = copyin(SCARG_P32(uap, data), data32, size32);
    438 			if (error) {
    439 				if (memp32)
    440 					free(memp32, M_IOCTLOPS);
    441 				goto out;
    442 			}
    443 #ifdef KTRACE
    444 			if (KTRPOINT(p, KTR_GENIO)) {
    445 				struct iovec iov;
    446 				iov.iov_base = SCARG_P32(uap, data);
    447 				iov.iov_len = size32;
    448 				ktrgenio(l, SCARG(uap, fd), UIO_WRITE, &iov,
    449 				    size32, 0);
    450 			}
    451 #endif
    452 		} else
    453 			*(void **)data32 = SCARG_P32(uap, data);
    454 	} else if ((com&IOC_OUT) && size32)
    455 		/*
    456 		 * Zero the buffer so the user always
    457 		 * gets back something deterministic.
    458 		 */
    459 		memset(data32, 0, size32);
    460 	else if (com&IOC_VOID)
    461 		*(void **)data32 = SCARG_P32(uap, data);
    462 
    463 	/*
    464 	 * convert various structures, pointers, and other objects that
    465 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
    466 	 */
    467 	switch (SCARG(uap, com)) {
    468 	case FIONBIO:
    469 		if ((tmp = *(int *)data32) != 0)
    470 			fp->f_flag |= FNONBLOCK;
    471 		else
    472 			fp->f_flag &= ~FNONBLOCK;
    473 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp, l);
    474 		break;
    475 
    476 	case FIOASYNC:
    477 		if ((tmp = *(int *)data32) != 0)
    478 			fp->f_flag |= FASYNC;
    479 		else
    480 			fp->f_flag &= ~FASYNC;
    481 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp, l);
    482 		break;
    483 
    484 	case DIOCGPART32:
    485 		IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
    486 #if 0	/* not implemented by anything */
    487 	case DIOCRFORMAT32:
    488 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
    489 	case DIOCWFORMAT32:
    490 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
    491 #endif
    492 
    493 /*
    494  * only a few ifreq syscalls need conversion and those are
    495  * all driver specific... XXX
    496  */
    497 #if 0
    498 	case SIOCGADDRROM3232:
    499 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
    500 	case SIOCGCHIPID32:
    501 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
    502 	case SIOCSIFADDR32:
    503 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
    504 	case OSIOCGIFADDR32:
    505 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
    506 	case SIOCGIFADDR32:
    507 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
    508 	case SIOCSIFDSTADDR32:
    509 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
    510 	case OSIOCGIFDSTADDR32:
    511 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
    512 	case SIOCGIFDSTADDR32:
    513 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
    514 	case OSIOCGIFBRDADDR32:
    515 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
    516 	case SIOCGIFBRDADDR32:
    517 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
    518 	case SIOCSIFBRDADDR32:
    519 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
    520 	case OSIOCGIFNETMASK32:
    521 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
    522 	case SIOCGIFNETMASK32:
    523 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
    524 	case SIOCSIFNETMASK32:
    525 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
    526 	case SIOCGIFMETRIC32:
    527 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
    528 	case SIOCSIFMETRIC32:
    529 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
    530 	case SIOCDIFADDR32:
    531 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
    532 	case SIOCADDMULTI32:
    533 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
    534 	case SIOCDELMULTI32:
    535 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
    536 	case SIOCSIFMEDIA32:
    537 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
    538 	case SIOCSIFMTU32:
    539 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
    540 	case SIOCGIFMTU32:
    541 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
    542 	case BIOCGETIF32:
    543 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
    544 	case BIOCSETIF32:
    545 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
    546 	case SIOCPHASE132:
    547 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
    548 	case SIOCPHASE232:
    549 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
    550 #endif
    551 
    552 	case OSIOCGIFCONF32:
    553 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
    554 	case SIOCGIFCONF32:
    555 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
    556 
    557 	case SIOCGIFFLAGS32:
    558 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
    559 	case SIOCSIFFLAGS32:
    560 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
    561 
    562 	case SIOCGIFMEDIA32:
    563 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
    564 
    565 	case SIOCSDRVSPEC32:
    566 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
    567 
    568 	case SIOCGETVIFCNT32:
    569 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
    570 
    571 	case SIOCGETSGCNT32:
    572 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
    573 
    574 	default:
    575 #ifdef NETBSD32_MD_IOCTL
    576 		error = netbsd32_md_ioctl(fp, com, data32, l);
    577 #else
    578 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32, l);
    579 #endif
    580 		break;
    581 	}
    582 
    583 	if (error == EPASSTHROUGH)
    584 		error = ENOTTY;
    585 
    586 	/*
    587 	 * Copy any data to user, size was
    588 	 * already set and checked above.
    589 	 */
    590 	if (error == 0 && (com&IOC_OUT) && size32) {
    591 		error = copyout(data32, SCARG_P32(uap, data), size32);
    592 #ifdef KTRACE
    593 		if (KTRPOINT(p, KTR_GENIO)) {
    594 			struct iovec iov;
    595 			iov.iov_base = SCARG_P32(uap, data);
    596 			iov.iov_len = size32;
    597 			ktrgenio(l, SCARG(uap, fd), UIO_READ, &iov,
    598 			    size32, error);
    599 		}
    600 #endif
    601 	}
    602 
    603 	/* if we malloced data, free it here */
    604 	if (memp32)
    605 		free(memp32, M_IOCTLOPS);
    606 	if (memp)
    607 		free(memp, M_IOCTLOPS);
    608 
    609  out:
    610 	FILE_UNUSE(fp, l);
    611 	return (error);
    612 }
    613