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