Module Name: src Committed By: joerg Date: Fri Nov 13 21:45:03 UTC 2009
Modified Files: src/sys/compat/linux/common: linux_socket.c linux_sockio.h src/sys/compat/linux32/common: linux32_socket.c linux32_sockio.h Log Message: Provide SIOCGIFNAME. To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/compat/linux/common/linux_socket.c cvs rdiff -u -r1.16 -r1.17 src/sys/compat/linux/common/linux_sockio.h cvs rdiff -u -r1.10 -r1.11 src/sys/compat/linux32/common/linux32_socket.c cvs rdiff -u -r1.2 -r1.3 src/sys/compat/linux32/common/linux32_sockio.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/linux/common/linux_socket.c diff -u src/sys/compat/linux/common/linux_socket.c:1.104 src/sys/compat/linux/common/linux_socket.c:1.105 --- src/sys/compat/linux/common/linux_socket.c:1.104 Wed Jun 17 14:18:51 2009 +++ src/sys/compat/linux/common/linux_socket.c Fri Nov 13 21:45:03 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_socket.c,v 1.104 2009/06/17 14:18:51 njoly Exp $ */ +/* $NetBSD: linux_socket.c,v 1.105 2009/11/13 21:45:03 joerg Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.104 2009/06/17 14:18:51 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.105 2009/11/13 21:45:03 joerg Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -114,6 +114,7 @@ int linux_to_bsd_ip_sockopt(int); int linux_to_bsd_tcp_sockopt(int); int linux_to_bsd_udp_sockopt(int); +int linux_getifname(struct lwp *, register_t *, void *); int linux_getifconf(struct lwp *, register_t *, void *); int linux_getifhwaddr(struct lwp *, register_t *, u_int, void *); static int linux_get_sa(struct lwp *, int, struct mbuf **, @@ -1005,6 +1006,31 @@ } int +linux_getifname(struct lwp *l, register_t *retval, void *data) +{ + struct ifnet *ifp; + struct linux_ifreq ifr; + int error; + + error = copyin(data, &ifr, sizeof(ifr)); + if (error) + return error; + + if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim) + return ENODEV; + + ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex]; + if (ifp == NULL) + return ENODEV; + + strncpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name)); + + error = copyout(&ifr, data, sizeof(ifr)); + + return 0; +} + +int linux_getifconf(struct lwp *l, register_t *retval, void *data) { struct linux_ifreq ifr, *ifrp; @@ -1225,6 +1251,10 @@ retval[0] = 0; switch (com) { + case LINUX_SIOCGIFNAME: + error = linux_getifname(l, retval, SCARG(uap, data)); + dosys = 0; + break; case LINUX_SIOCGIFCONF: error = linux_getifconf(l, retval, SCARG(uap, data)); dosys = 0; Index: src/sys/compat/linux/common/linux_sockio.h diff -u src/sys/compat/linux/common/linux_sockio.h:1.16 src/sys/compat/linux/common/linux_sockio.h:1.17 --- src/sys/compat/linux/common/linux_sockio.h:1.16 Thu Jul 3 14:07:09 2008 +++ src/sys/compat/linux/common/linux_sockio.h Fri Nov 13 21:45:03 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_sockio.h,v 1.16 2008/07/03 14:07:09 njoly Exp $ */ +/* $NetBSD: linux_sockio.h,v 1.17 2009/11/13 21:45:03 joerg Exp $ */ /*- * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #ifndef _LINUX_SOCKIO_H #define _LINUX_SOCKIO_H +#define LINUX_SIOCGIFNAME _LINUX_IO(0x89, 0x10) #define LINUX_SIOCGIFCONF _LINUX_IO(0x89, 0x12) #define LINUX_SIOCGIFFLAGS _LINUX_IO(0x89, 0x13) #define LINUX_SIOCSIFFLAGS _LINUX_IO(0x89, 0x14) @@ -66,6 +67,7 @@ struct osockaddr ifru_addr; struct osockaddr ifru_hwaddr; struct linux_ifmap ifru_map; + int ifru_ifindex; } ifr_ifru; #define ifr_name ifr_ifrn.ifrn_name /* interface name */ #define ifr_addr ifr_ifru.ifru_addr /* address */ Index: src/sys/compat/linux32/common/linux32_socket.c diff -u src/sys/compat/linux32/common/linux32_socket.c:1.10 src/sys/compat/linux32/common/linux32_socket.c:1.11 --- src/sys/compat/linux32/common/linux32_socket.c:1.10 Wed Nov 19 18:36:04 2008 +++ src/sys/compat/linux32/common/linux32_socket.c Fri Nov 13 21:45:03 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $ */ +/* $NetBSD: linux32_socket.c,v 1.11 2009/11/13 21:45:03 joerg Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.11 2009/11/13 21:45:03 joerg Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -91,6 +91,7 @@ #include <compat/linux32/common/linux32_ioctl.h> #include <compat/linux32/linux32_syscallargs.h> +int linux32_getifname(struct lwp *, register_t *, void *); int linux32_getifconf(struct lwp *, register_t *, void *); int linux32_getifhwaddr(struct lwp *, register_t *, u_int, void *); @@ -387,6 +388,31 @@ } int +linux32_getifname(struct lwp *l, register_t *retval, void *data) +{ + struct ifnet *ifp; + struct linux32_ifreq ifr; + int error; + + error = copyin(data, &ifr, sizeof(ifr)); + if (error) + return error; + + if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim) + return ENODEV; + + ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex]; + if (ifp == NULL) + return ENODEV; + + strncpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name)); + + error = copyout(&ifr, data, sizeof(ifr)); + + return 0; +} + +int linux32_getifconf(struct lwp *l, register_t *retval, void *data) { struct linux32_ifreq ifr, *ifrp; @@ -606,6 +632,10 @@ retval[0] = 0; switch (com) { + case LINUX_SIOCGIFNAME: + error = linux32_getifname(l, retval, SCARG_P32(uap, data)); + dosys = 0; + break; case LINUX_SIOCGIFCONF: error = linux32_getifconf(l, retval, SCARG_P32(uap, data)); dosys = 0; Index: src/sys/compat/linux32/common/linux32_sockio.h diff -u src/sys/compat/linux32/common/linux32_sockio.h:1.2 src/sys/compat/linux32/common/linux32_sockio.h:1.3 --- src/sys/compat/linux32/common/linux32_sockio.h:1.2 Wed Jul 23 12:32:09 2008 +++ src/sys/compat/linux32/common/linux32_sockio.h Fri Nov 13 21:45:03 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_sockio.h,v 1.2 2008/07/23 12:32:09 njoly Exp $ */ +/* $NetBSD: linux32_sockio.h,v 1.3 2009/11/13 21:45:03 joerg Exp $ */ /* * Copyright (c) 2008 Nicolas Joly @@ -48,6 +48,7 @@ struct osockaddr ifru_addr; struct osockaddr ifru_hwaddr; struct linux32_ifmap ifru_map; + int ifru_ifindex; } ifr_ifru; #define ifr_name ifr_ifrn.ifrn_name /* interface name */ #define ifr_addr ifr_ifru.ifru_addr /* address */