1995-06-25 17:32:43 +00:00
|
|
|
|
/*-
|
|
|
|
|
* Copyright (c) 1995 S<EFBFBD>ren Schmidt
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2003-03-03 09:17:12 +00:00
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
1995-06-25 17:32:43 +00:00
|
|
|
|
* in this position and unchanged.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2002-06-02 20:05:59 +00:00
|
|
|
|
* derived from this software without specific prior written permission
|
1995-06-25 17:32:43 +00:00
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-06-10 21:29:12 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
1995-11-22 07:43:53 +00:00
|
|
|
|
/* XXX we use functions that might not exist. */
|
1997-12-16 17:40:42 +00:00
|
|
|
|
#include "opt_compat.h"
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#include "opt_inet6.h"
|
1997-12-16 17:40:42 +00:00
|
|
|
|
|
|
|
|
|
#ifndef COMPAT_43
|
|
|
|
|
#error "Unable to compile Linux-emulator due to missing COMPAT_43 option!"
|
|
|
|
|
#endif
|
1995-11-22 07:43:53 +00:00
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <sys/param.h>
|
1997-12-14 03:17:54 +00:00
|
|
|
|
#include <sys/proc.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <sys/systm.h>
|
1995-11-22 07:43:53 +00:00
|
|
|
|
#include <sys/sysproto.h>
|
1998-02-07 02:13:27 +00:00
|
|
|
|
#include <sys/fcntl.h>
|
2001-03-01 21:44:40 +00:00
|
|
|
|
#include <sys/file.h>
|
2003-04-29 13:36:06 +00:00
|
|
|
|
#include <sys/limits.h>
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#include <sys/malloc.h>
|
2003-11-09 17:04:04 +00:00
|
|
|
|
#include <sys/mbuf.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <sys/socket.h>
|
2001-03-01 21:44:40 +00:00
|
|
|
|
#include <sys/socketvar.h>
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#include <sys/syscallsubr.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
|
#include <sys/uio.h>
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#include <sys/syslog.h>
|
1995-11-22 07:43:53 +00:00
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <netinet/in.h>
|
1997-12-14 03:17:54 +00:00
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
|
#include <netinet/ip.h>
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#ifdef INET6
|
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
|
#endif
|
1995-06-25 17:32:43 +00:00
|
|
|
|
|
2000-08-22 01:51:54 +00:00
|
|
|
|
#include <machine/../linux/linux.h>
|
2000-11-10 21:30:19 +00:00
|
|
|
|
#include <machine/../linux/linux_proto.h>
|
2000-12-19 00:24:25 +00:00
|
|
|
|
#include <compat/linux/linux_socket.h>
|
2000-08-22 01:51:54 +00:00
|
|
|
|
#include <compat/linux/linux_util.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
|
2003-02-03 17:43:20 +00:00
|
|
|
|
static int do_sa_get(struct sockaddr **, const struct osockaddr *, int *,
|
|
|
|
|
struct malloc_type *);
|
|
|
|
|
static int linux_to_bsd_domain(int);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Reads a linux sockaddr and does any necessary translation.
|
|
|
|
|
* Linux sockaddrs don't have a length field, only a family.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
linux_getsockaddr(struct sockaddr **sap, const struct osockaddr *osa, int len)
|
|
|
|
|
{
|
|
|
|
|
int osalen = len;
|
|
|
|
|
|
|
|
|
|
return (do_sa_get(sap, osa, &osalen, M_SONAME));
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-26 23:10:08 +00:00
|
|
|
|
/*
|
2003-02-03 17:43:20 +00:00
|
|
|
|
* Copy the osockaddr structure pointed to by osa to kernel, adjust
|
|
|
|
|
* family and convert to sockaddr.
|
2001-10-26 23:10:08 +00:00
|
|
|
|
*/
|
|
|
|
|
static int
|
2003-02-03 17:43:20 +00:00
|
|
|
|
do_sa_get(struct sockaddr **sap, const struct osockaddr *osa, int *osalen,
|
|
|
|
|
struct malloc_type *mtype)
|
2001-10-26 23:10:08 +00:00
|
|
|
|
{
|
2003-02-03 17:43:20 +00:00
|
|
|
|
int error=0, bdom;
|
|
|
|
|
struct sockaddr *sa;
|
|
|
|
|
struct osockaddr *kosa;
|
|
|
|
|
int alloclen;
|
|
|
|
|
#ifdef INET6
|
|
|
|
|
int oldv6size;
|
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (*osalen < 2 || *osalen > UCHAR_MAX || !osa)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
alloclen = *osalen;
|
|
|
|
|
#ifdef INET6
|
|
|
|
|
oldv6size = 0;
|
|
|
|
|
/*
|
|
|
|
|
* Check for old (pre-RFC2553) sockaddr_in6. We may accept it
|
|
|
|
|
* if it's a v4-mapped address, so reserve the proper space
|
|
|
|
|
* for it.
|
|
|
|
|
*/
|
|
|
|
|
if (alloclen == sizeof (struct sockaddr_in6) - sizeof (u_int32_t)) {
|
|
|
|
|
alloclen = sizeof (struct sockaddr_in6);
|
|
|
|
|
oldv6size = 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-10-26 23:10:08 +00:00
|
|
|
|
|
2003-02-20 11:24:55 +00:00
|
|
|
|
MALLOC(kosa, struct osockaddr *, alloclen, mtype, M_WAITOK);
|
2001-10-26 23:10:08 +00:00
|
|
|
|
|
2003-03-03 09:14:26 +00:00
|
|
|
|
if ((error = copyin(osa, kosa, *osalen)))
|
2003-02-03 17:43:20 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
bdom = linux_to_bsd_domain(kosa->sa_family);
|
|
|
|
|
if (bdom == -1) {
|
|
|
|
|
error = EINVAL;
|
|
|
|
|
goto out;
|
2001-10-26 23:10:08 +00:00
|
|
|
|
}
|
2003-02-03 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
|
/*
|
|
|
|
|
* Older Linux IPv6 code uses obsolete RFC2133 struct sockaddr_in6,
|
|
|
|
|
* which lacks the scope id compared with RFC2553 one. If we detect
|
|
|
|
|
* the situation, reject the address and write a message to system log.
|
|
|
|
|
*
|
|
|
|
|
* Still accept addresses for which the scope id is not used.
|
|
|
|
|
*/
|
|
|
|
|
if (oldv6size && bdom == AF_INET6) {
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)kosa;
|
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr) ||
|
|
|
|
|
(!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) &&
|
|
|
|
|
!IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) &&
|
|
|
|
|
!IN6_IS_ADDR_V4COMPAT(&sin6->sin6_addr) &&
|
|
|
|
|
!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
|
|
|
|
|
!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))) {
|
|
|
|
|
sin6->sin6_scope_id = 0;
|
|
|
|
|
} else {
|
|
|
|
|
log(LOG_DEBUG,
|
|
|
|
|
"obsolete pre-RFC2553 sockaddr_in6 rejected");
|
|
|
|
|
error = EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
if (bdom == AF_INET)
|
|
|
|
|
alloclen = sizeof(struct sockaddr_in);
|
|
|
|
|
|
|
|
|
|
sa = (struct sockaddr *) kosa;
|
|
|
|
|
sa->sa_family = bdom;
|
|
|
|
|
sa->sa_len = alloclen;
|
|
|
|
|
|
|
|
|
|
*sap = sa;
|
|
|
|
|
*osalen = alloclen;
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
FREE(kosa, mtype);
|
|
|
|
|
return (error);
|
2001-10-26 23:10:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_domain(int domain)
|
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
switch (domain) {
|
|
|
|
|
case LINUX_AF_UNSPEC:
|
|
|
|
|
return (AF_UNSPEC);
|
|
|
|
|
case LINUX_AF_UNIX:
|
|
|
|
|
return (AF_LOCAL);
|
|
|
|
|
case LINUX_AF_INET:
|
|
|
|
|
return (AF_INET);
|
2003-02-03 17:43:20 +00:00
|
|
|
|
case LINUX_AF_INET6:
|
|
|
|
|
return (AF_INET6);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_AF_AX25:
|
|
|
|
|
return (AF_CCITT);
|
|
|
|
|
case LINUX_AF_IPX:
|
|
|
|
|
return (AF_IPX);
|
|
|
|
|
case LINUX_AF_APPLETALK:
|
|
|
|
|
return (AF_APPLETALK);
|
|
|
|
|
}
|
|
|
|
|
return (-1);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#ifndef __alpha__
|
|
|
|
|
static int
|
|
|
|
|
bsd_to_linux_domain(int domain)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
switch (domain) {
|
|
|
|
|
case AF_UNSPEC:
|
|
|
|
|
return (LINUX_AF_UNSPEC);
|
|
|
|
|
case AF_LOCAL:
|
|
|
|
|
return (LINUX_AF_UNIX);
|
|
|
|
|
case AF_INET:
|
|
|
|
|
return (LINUX_AF_INET);
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
return (LINUX_AF_INET6);
|
|
|
|
|
case AF_CCITT:
|
|
|
|
|
return (LINUX_AF_AX25);
|
|
|
|
|
case AF_IPX:
|
|
|
|
|
return (LINUX_AF_IPX);
|
|
|
|
|
case AF_APPLETALK:
|
|
|
|
|
return (LINUX_AF_APPLETALK);
|
|
|
|
|
}
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_sockopt_level(int level)
|
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
|
case LINUX_SOL_SOCKET:
|
|
|
|
|
return (SOL_SOCKET);
|
|
|
|
|
}
|
|
|
|
|
return (level);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-11 15:08:32 +00:00
|
|
|
|
static int
|
|
|
|
|
bsd_to_linux_sockopt_level(int level)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
|
case SOL_SOCKET:
|
|
|
|
|
return (LINUX_SOL_SOCKET);
|
|
|
|
|
}
|
|
|
|
|
return (level);
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-26 05:12:16 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_ip_sockopt(int opt)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case LINUX_IP_TOS:
|
|
|
|
|
return (IP_TOS);
|
|
|
|
|
case LINUX_IP_TTL:
|
|
|
|
|
return (IP_TTL);
|
|
|
|
|
case LINUX_IP_OPTIONS:
|
|
|
|
|
return (IP_OPTIONS);
|
|
|
|
|
case LINUX_IP_MULTICAST_IF:
|
|
|
|
|
return (IP_MULTICAST_IF);
|
|
|
|
|
case LINUX_IP_MULTICAST_TTL:
|
|
|
|
|
return (IP_MULTICAST_TTL);
|
|
|
|
|
case LINUX_IP_MULTICAST_LOOP:
|
|
|
|
|
return (IP_MULTICAST_LOOP);
|
|
|
|
|
case LINUX_IP_ADD_MEMBERSHIP:
|
|
|
|
|
return (IP_ADD_MEMBERSHIP);
|
|
|
|
|
case LINUX_IP_DROP_MEMBERSHIP:
|
|
|
|
|
return (IP_DROP_MEMBERSHIP);
|
|
|
|
|
case LINUX_IP_HDRINCL:
|
|
|
|
|
return (IP_HDRINCL);
|
|
|
|
|
}
|
|
|
|
|
return (-1);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_so_sockopt(int opt)
|
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case LINUX_SO_DEBUG:
|
|
|
|
|
return (SO_DEBUG);
|
|
|
|
|
case LINUX_SO_REUSEADDR:
|
|
|
|
|
return (SO_REUSEADDR);
|
|
|
|
|
case LINUX_SO_TYPE:
|
|
|
|
|
return (SO_TYPE);
|
|
|
|
|
case LINUX_SO_ERROR:
|
|
|
|
|
return (SO_ERROR);
|
|
|
|
|
case LINUX_SO_DONTROUTE:
|
|
|
|
|
return (SO_DONTROUTE);
|
|
|
|
|
case LINUX_SO_BROADCAST:
|
|
|
|
|
return (SO_BROADCAST);
|
|
|
|
|
case LINUX_SO_SNDBUF:
|
|
|
|
|
return (SO_SNDBUF);
|
|
|
|
|
case LINUX_SO_RCVBUF:
|
|
|
|
|
return (SO_RCVBUF);
|
|
|
|
|
case LINUX_SO_KEEPALIVE:
|
|
|
|
|
return (SO_KEEPALIVE);
|
|
|
|
|
case LINUX_SO_OOBINLINE:
|
|
|
|
|
return (SO_OOBINLINE);
|
|
|
|
|
case LINUX_SO_LINGER:
|
|
|
|
|
return (SO_LINGER);
|
|
|
|
|
}
|
|
|
|
|
return (-1);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-12-19 00:24:25 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_msg_flags(int flags)
|
|
|
|
|
{
|
|
|
|
|
int ret_flags = 0;
|
|
|
|
|
|
|
|
|
|
if (flags & LINUX_MSG_OOB)
|
|
|
|
|
ret_flags |= MSG_OOB;
|
|
|
|
|
if (flags & LINUX_MSG_PEEK)
|
|
|
|
|
ret_flags |= MSG_PEEK;
|
|
|
|
|
if (flags & LINUX_MSG_DONTROUTE)
|
|
|
|
|
ret_flags |= MSG_DONTROUTE;
|
|
|
|
|
if (flags & LINUX_MSG_CTRUNC)
|
|
|
|
|
ret_flags |= MSG_CTRUNC;
|
|
|
|
|
if (flags & LINUX_MSG_TRUNC)
|
|
|
|
|
ret_flags |= MSG_TRUNC;
|
|
|
|
|
if (flags & LINUX_MSG_DONTWAIT)
|
|
|
|
|
ret_flags |= MSG_DONTWAIT;
|
|
|
|
|
if (flags & LINUX_MSG_EOR)
|
|
|
|
|
ret_flags |= MSG_EOR;
|
|
|
|
|
if (flags & LINUX_MSG_WAITALL)
|
|
|
|
|
ret_flags |= MSG_WAITALL;
|
|
|
|
|
#if 0 /* not handled */
|
|
|
|
|
if (flags & LINUX_MSG_PROXY)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_FIN)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_SYN)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_CONFIRM)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_RST)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_ERRQUEUE)
|
|
|
|
|
;
|
|
|
|
|
if (flags & LINUX_MSG_NOSIGNAL)
|
|
|
|
|
;
|
|
|
|
|
#endif
|
|
|
|
|
return ret_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-03 17:43:20 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_sa_put(struct osockaddr *osa)
|
|
|
|
|
{
|
|
|
|
|
struct osockaddr sa;
|
|
|
|
|
int error, bdom;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Only read/write the osockaddr family part, the rest is
|
|
|
|
|
* not changed.
|
|
|
|
|
*/
|
2003-03-03 09:14:26 +00:00
|
|
|
|
error = copyin(osa, &sa, sizeof(sa.sa_family));
|
2003-02-03 17:43:20 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bdom = bsd_to_linux_domain(sa.sa_family);
|
|
|
|
|
if (bdom == -1)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
sa.sa_family = bdom;
|
|
|
|
|
error = copyout(&sa, osa, sizeof(sa.sa_family));
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-09 17:04:04 +00:00
|
|
|
|
static int
|
|
|
|
|
linux_sendit(struct thread *td, int s, struct msghdr *mp, int flags)
|
|
|
|
|
{
|
|
|
|
|
struct mbuf *control;
|
|
|
|
|
struct sockaddr *to;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if (mp->msg_name != NULL) {
|
|
|
|
|
error = linux_getsockaddr(&to, mp->msg_name, mp->msg_namelen);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
mp->msg_name = to;
|
|
|
|
|
} else
|
|
|
|
|
to = NULL;
|
|
|
|
|
|
|
|
|
|
if (mp->msg_control != NULL) {
|
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
|
|
|
|
|
|
if (mp->msg_controllen < sizeof(struct cmsghdr)) {
|
|
|
|
|
error = EINVAL;
|
|
|
|
|
goto bad;
|
|
|
|
|
}
|
|
|
|
|
error = sockargs(&control, mp->msg_control,
|
|
|
|
|
mp->msg_controllen, MT_CONTROL);
|
|
|
|
|
if (error)
|
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
|
|
cmsg = mtod(control, struct cmsghdr *);
|
|
|
|
|
cmsg->cmsg_level = linux_to_bsd_sockopt_level(cmsg->cmsg_level);
|
|
|
|
|
} else
|
|
|
|
|
control = NULL;
|
|
|
|
|
|
|
|
|
|
error = kern_sendit(td, s, mp, linux_to_bsd_msg_flags(flags), control);
|
|
|
|
|
|
|
|
|
|
bad:
|
|
|
|
|
if (to)
|
|
|
|
|
FREE(to, M_SONAME);
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-26 05:12:16 +00:00
|
|
|
|
/* Return 0 if IP_HDRINCL is set for the given socket. */
|
1997-12-14 03:17:54 +00:00
|
|
|
|
static int
|
2003-02-08 09:26:31 +00:00
|
|
|
|
linux_check_hdrincl(struct thread *td, caddr_t *sg, int s)
|
1997-12-14 03:17:54 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct getsockopt_args /* {
|
2003-12-25 09:59:02 +00:00
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
void * __restrict val;
|
|
|
|
|
socklen_t * __restrict avalsize;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
} */ bsd_args;
|
2003-12-25 09:59:02 +00:00
|
|
|
|
void * __restrict val;
|
|
|
|
|
socklen_t * __restrict valsize;
|
|
|
|
|
int error, optval, size_val;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
2003-12-25 09:59:02 +00:00
|
|
|
|
val = stackgap_alloc(sg, sizeof(size_val));
|
|
|
|
|
valsize = stackgap_alloc(sg, sizeof(socklen_t));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
2003-12-25 09:59:02 +00:00
|
|
|
|
size_val = sizeof(val);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
if ((error = copyout(&size_val, valsize, sizeof(size_val))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = s;
|
|
|
|
|
bsd_args.level = IPPROTO_IP;
|
|
|
|
|
bsd_args.name = IP_HDRINCL;
|
|
|
|
|
bsd_args.val = val;
|
2003-12-25 09:59:02 +00:00
|
|
|
|
bsd_args.avalsize = valsize;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
if ((error = getsockopt(td, &bsd_args)))
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(val, &optval, sizeof(optval))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
return (optval == 0);
|
1997-12-14 03:17:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-09 17:04:04 +00:00
|
|
|
|
struct linux_sendto_args {
|
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t to;
|
|
|
|
|
int tolen;
|
|
|
|
|
};
|
|
|
|
|
|
1997-12-14 03:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Updated sendto() when IP_HDRINCL is set:
|
|
|
|
|
* tweak endian-dependent fields in the IP packet.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2003-11-09 17:04:04 +00:00
|
|
|
|
linux_sendto_hdrincl(struct thread *td, caddr_t *sg, struct linux_sendto_args *linux_args)
|
1997-12-14 03:17:54 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* linux_ip_copysize defines how many bytes we should copy
|
|
|
|
|
* from the beginning of the IP packet before we customize it for BSD.
|
|
|
|
|
* It should include all the fields we modify (ip_len and ip_off)
|
|
|
|
|
* and be as small as possible to minimize copying overhead.
|
|
|
|
|
*/
|
|
|
|
|
#define linux_ip_copysize 8
|
|
|
|
|
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct ip *packet;
|
2003-11-09 17:04:04 +00:00
|
|
|
|
struct msghdr msg;
|
|
|
|
|
struct iovec aiov[2];
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
/* Check the packet isn't too small before we mess with it */
|
2003-11-09 17:04:04 +00:00
|
|
|
|
if (linux_args->len < linux_ip_copysize)
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tweaking the user buffer in place would be bad manners.
|
|
|
|
|
* We create a corrected IP header with just the needed length,
|
|
|
|
|
* then use an iovec to glue it to the rest of the user packet
|
2003-11-09 17:04:04 +00:00
|
|
|
|
* when calling sendit().
|
2000-08-26 05:12:16 +00:00
|
|
|
|
*/
|
2003-02-08 09:26:31 +00:00
|
|
|
|
packet = (struct ip *)stackgap_alloc(sg, linux_ip_copysize);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
/* Make a copy of the beginning of the packet to be sent */
|
2003-11-09 17:04:04 +00:00
|
|
|
|
if ((error = copyin(linux_args->msg, packet, linux_ip_copysize)))
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
/* Convert fields from Linux to BSD raw IP socket format */
|
2003-11-09 17:04:04 +00:00
|
|
|
|
packet->ip_len = linux_args->len;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
packet->ip_off = ntohs(packet->ip_off);
|
|
|
|
|
|
|
|
|
|
/* Prepare the msghdr and iovec structures describing the new packet */
|
2003-11-09 17:04:04 +00:00
|
|
|
|
msg.msg_name = linux_args->to;
|
|
|
|
|
msg.msg_namelen = linux_args->tolen;
|
|
|
|
|
msg.msg_iov = aiov;
|
|
|
|
|
msg.msg_iovlen = 2;
|
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
aiov[0].iov_base = (char *)packet;
|
|
|
|
|
aiov[0].iov_len = linux_ip_copysize;
|
|
|
|
|
aiov[1].iov_base = (char *)(linux_args->msg) + linux_ip_copysize;
|
|
|
|
|
aiov[1].iov_len = linux_args->len - linux_ip_copysize;
|
|
|
|
|
error = linux_sendit(td, linux_args->s, &msg, linux_args->flags);
|
|
|
|
|
return (error);
|
1997-12-14 03:17:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
struct linux_socket_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_socket(struct thread *td, struct linux_socket_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_socket_args linux_args;
|
|
|
|
|
struct socket_args /* {
|
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
} */ bsd_args;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct setsockopt_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
caddr_t val;
|
|
|
|
|
int valsize;
|
|
|
|
|
} */ bsd_setsockopt_args;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int error;
|
|
|
|
|
int retval_socket;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.protocol = linux_args.protocol;
|
|
|
|
|
bsd_args.type = linux_args.type;
|
|
|
|
|
bsd_args.domain = linux_to_bsd_domain(linux_args.domain);
|
|
|
|
|
if (bsd_args.domain == -1)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
|
retval_socket = socket(td, &bsd_args);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
if (bsd_args.type == SOCK_RAW
|
|
|
|
|
&& (bsd_args.protocol == IPPROTO_RAW || bsd_args.protocol == 0)
|
|
|
|
|
&& bsd_args.domain == AF_INET
|
|
|
|
|
&& retval_socket >= 0) {
|
|
|
|
|
/* It's a raw IP socket: set the IP_HDRINCL option. */
|
|
|
|
|
caddr_t sg;
|
|
|
|
|
int *hdrincl;
|
|
|
|
|
|
|
|
|
|
sg = stackgap_init();
|
|
|
|
|
hdrincl = (int *)stackgap_alloc(&sg, sizeof(*hdrincl));
|
|
|
|
|
*hdrincl = 1;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
bsd_setsockopt_args.s = td->td_retval[0];
|
2000-08-26 05:12:16 +00:00
|
|
|
|
bsd_setsockopt_args.level = IPPROTO_IP;
|
|
|
|
|
bsd_setsockopt_args.name = IP_HDRINCL;
|
|
|
|
|
bsd_setsockopt_args.val = (caddr_t)hdrincl;
|
|
|
|
|
bsd_setsockopt_args.valsize = sizeof(*hdrincl);
|
|
|
|
|
/* We ignore any error returned by setsockopt() */
|
2001-09-12 08:38:13 +00:00
|
|
|
|
setsockopt(td, &bsd_setsockopt_args);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
/* Copy back the return value from socket() */
|
2001-09-12 08:38:13 +00:00
|
|
|
|
td->td_retval[0] = bsd_setsockopt_args.s;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
}
|
2003-02-03 17:43:20 +00:00
|
|
|
|
#ifdef INET6
|
|
|
|
|
/*
|
|
|
|
|
* Linux AF_INET6 socket has IPV6_V6ONLY setsockopt set to 0 by
|
|
|
|
|
* default and some apps depend on this. So, set V6ONLY to 0
|
|
|
|
|
* for Linux apps if the sysctl value is set to 1.
|
|
|
|
|
*/
|
2003-02-05 11:05:45 +00:00
|
|
|
|
if (bsd_args.domain == PF_INET6 && retval_socket >= 0
|
|
|
|
|
#ifndef KLD_MODULE
|
|
|
|
|
/*
|
|
|
|
|
* XXX: Avoid undefined symbol error with an IPv4 only
|
|
|
|
|
* kernel.
|
2003-03-03 09:17:12 +00:00
|
|
|
|
*/
|
2003-02-05 11:05:45 +00:00
|
|
|
|
&& ip6_v6only
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2003-02-03 17:43:20 +00:00
|
|
|
|
caddr_t sg;
|
|
|
|
|
int *v6only;
|
|
|
|
|
|
|
|
|
|
sg = stackgap_init();
|
|
|
|
|
v6only = (int *)stackgap_alloc(&sg, sizeof(*v6only));
|
|
|
|
|
*v6only = 0;
|
|
|
|
|
bsd_setsockopt_args.s = td->td_retval[0];
|
|
|
|
|
bsd_setsockopt_args.level = IPPROTO_IPV6;
|
|
|
|
|
bsd_setsockopt_args.name = IPV6_V6ONLY;
|
|
|
|
|
bsd_setsockopt_args.val = (caddr_t)v6only;
|
|
|
|
|
bsd_setsockopt_args.valsize = sizeof(*v6only);
|
|
|
|
|
/* We ignore any error returned by setsockopt() */
|
|
|
|
|
setsockopt(td, &bsd_setsockopt_args);
|
|
|
|
|
/* Copy back the return value from socket() */
|
|
|
|
|
td->td_retval[0] = bsd_setsockopt_args.s;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1997-12-14 03:17:54 +00:00
|
|
|
|
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (retval_socket);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_bind_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct osockaddr *name;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int namelen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_bind(struct thread *td, struct linux_bind_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_bind_args linux_args;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct sockaddr *sa;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
2003-02-03 17:43:20 +00:00
|
|
|
|
error = linux_getsockaddr(&sa, linux_args.name, linux_args.namelen);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
return (kern_bind(td, linux_args.s, sa));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_connect_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct osockaddr * name;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int namelen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
2001-09-12 08:38:13 +00:00
|
|
|
|
int linux_connect(struct thread *, struct linux_connect_args *);
|
2000-11-16 01:05:53 +00:00
|
|
|
|
#endif /* !__alpha__*/
|
1995-06-25 17:32:43 +00:00
|
|
|
|
|
2000-11-16 01:05:53 +00:00
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_connect(struct thread *td, struct linux_connect_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_connect_args linux_args;
|
2001-03-01 21:44:40 +00:00
|
|
|
|
struct socket *so;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct sockaddr *sa;
|
2001-11-17 18:43:13 +00:00
|
|
|
|
u_int fflag;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
2000-11-16 01:05:53 +00:00
|
|
|
|
#ifdef __alpha__
|
|
|
|
|
bcopy(args, &linux_args, sizeof(linux_args));
|
|
|
|
|
#else
|
2000-08-26 05:12:16 +00:00
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
2000-11-16 01:05:53 +00:00
|
|
|
|
#endif /* __alpha__ */
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
2003-02-08 09:26:31 +00:00
|
|
|
|
error = linux_getsockaddr(&sa, (struct osockaddr *)linux_args.name,
|
|
|
|
|
linux_args.namelen);
|
2003-02-03 17:43:20 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
error = kern_connect(td, linux_args.s, sa);
|
2001-03-01 21:44:40 +00:00
|
|
|
|
if (error != EISCONN)
|
|
|
|
|
return (error);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
2001-03-01 21:44:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* Linux doesn't return EISCONN the first time it occurs,
|
|
|
|
|
* when on a non-blocking socket. Instead it returns the
|
|
|
|
|
* error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD.
|
|
|
|
|
*/
|
2001-11-17 18:43:13 +00:00
|
|
|
|
if ((error = fgetsock(td, linux_args.s, &so, &fflag)) != 0)
|
|
|
|
|
return(error);
|
2001-03-01 21:44:40 +00:00
|
|
|
|
error = EISCONN;
|
2001-11-17 18:43:13 +00:00
|
|
|
|
if (fflag & FNONBLOCK) {
|
2001-09-08 19:07:04 +00:00
|
|
|
|
if (so->so_emuldata == 0)
|
2001-03-01 21:44:40 +00:00
|
|
|
|
error = so->so_error;
|
|
|
|
|
so->so_emuldata = (void *)1;
|
1998-02-07 02:13:27 +00:00
|
|
|
|
}
|
2001-11-17 18:43:13 +00:00
|
|
|
|
fputsock(so);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (error);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-11-16 01:05:53 +00:00
|
|
|
|
#ifndef __alpha__
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
struct linux_listen_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
int backlog;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_listen(struct thread *td, struct linux_listen_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_listen_args linux_args;
|
|
|
|
|
struct listen_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
int backlog;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.backlog = linux_args.backlog;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (listen(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_accept_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct osockaddr *addr;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int *namelen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_accept(struct thread *td, struct linux_accept_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_accept_args linux_args;
|
|
|
|
|
struct accept_args /* {
|
2003-12-25 09:59:02 +00:00
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr * __restrict name;
|
|
|
|
|
socklen_t * __restrict anamelen;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
} */ bsd_args;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct close_args /* {
|
|
|
|
|
int fd;
|
|
|
|
|
} */ c_args;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct fcntl_args /* {
|
2003-12-25 09:59:02 +00:00
|
|
|
|
int fd;
|
|
|
|
|
int cmd;
|
|
|
|
|
long arg;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
} */ f_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
2003-12-25 09:59:02 +00:00
|
|
|
|
/* XXX: */
|
|
|
|
|
bsd_args.name = (struct sockaddr * __restrict)linux_args.addr;
|
|
|
|
|
bsd_args.anamelen = linux_args.namelen; /* XXX */
|
2002-09-24 07:03:01 +00:00
|
|
|
|
error = oaccept(td, &bsd_args);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
2003-02-03 17:43:20 +00:00
|
|
|
|
if (linux_args.addr) {
|
|
|
|
|
error = linux_sa_put(linux_args.addr);
|
|
|
|
|
if (error) {
|
|
|
|
|
c_args.fd = td->td_retval[0];
|
|
|
|
|
(void)close(td, &c_args);
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-02-28 18:58:59 +00:00
|
|
|
|
|
2000-08-26 05:12:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* linux appears not to copy flags from the parent socket to the
|
|
|
|
|
* accepted one, so we must clear the flags in the new descriptor.
|
|
|
|
|
* Ignore any errors, because we already have an open fd.
|
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
|
f_args.fd = td->td_retval[0];
|
2000-08-26 05:12:16 +00:00
|
|
|
|
f_args.cmd = F_SETFL;
|
|
|
|
|
f_args.arg = 0;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
(void)fcntl(td, &f_args);
|
|
|
|
|
td->td_retval[0] = f_args.fd;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (0);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getsockname_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct osockaddr *addr;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int *namelen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_getsockname(struct thread *td, struct linux_getsockname_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_getsockname_args linux_args;
|
|
|
|
|
struct getsockname_args /* {
|
2003-12-25 09:59:02 +00:00
|
|
|
|
int fdes;
|
|
|
|
|
struct sockaddr * __restrict asa;
|
|
|
|
|
socklen_t * __restrict alen;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.fdes = linux_args.s;
|
2003-12-25 09:59:02 +00:00
|
|
|
|
/* XXX: */
|
|
|
|
|
bsd_args.asa = (struct sockaddr * __restrict)linux_args.addr;
|
|
|
|
|
bsd_args.alen = linux_args.namelen; /* XXX */
|
2003-02-03 17:43:20 +00:00
|
|
|
|
error = ogetsockname(td, &bsd_args);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
error = linux_sa_put(linux_args.addr);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
return (0);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getpeername_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct osockaddr *addr;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int *namelen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_getpeername(struct thread *td, struct linux_getpeername_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_getpeername_args linux_args;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
struct ogetpeername_args /* {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int fdes;
|
|
|
|
|
caddr_t asa;
|
|
|
|
|
int *alen;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.fdes = linux_args.s;
|
|
|
|
|
bsd_args.asa = (caddr_t) linux_args.addr;
|
|
|
|
|
bsd_args.alen = linux_args.namelen;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
error = ogetpeername(td, &bsd_args);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
error = linux_sa_put(linux_args.addr);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
return (0);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_socketpair_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
int *rsv;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_socketpair(struct thread *td, struct linux_socketpair_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_socketpair_args linux_args;
|
|
|
|
|
struct socketpair_args /* {
|
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
int *rsv;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.domain = linux_to_bsd_domain(linux_args.domain);
|
|
|
|
|
if (bsd_args.domain == -1)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
bsd_args.type = linux_args.type;
|
|
|
|
|
bsd_args.protocol = linux_args.protocol;
|
|
|
|
|
bsd_args.rsv = linux_args.rsv;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (socketpair(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_send_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_send(struct thread *td, struct linux_send_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_send_args linux_args;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
struct osend_args /* {
|
|
|
|
|
int s;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
caddr_t buf;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
int len;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int flags;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.buf = linux_args.msg;
|
|
|
|
|
bsd_args.len = linux_args.len;
|
|
|
|
|
bsd_args.flags = linux_args.flags;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
return (osend(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_recv_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_recv(struct thread *td, struct linux_recv_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_recv_args linux_args;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
struct orecv_args /* {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.buf = linux_args.msg;
|
|
|
|
|
bsd_args.len = linux_args.len;
|
|
|
|
|
bsd_args.flags = linux_args.flags;
|
2002-09-24 07:03:01 +00:00
|
|
|
|
return (orecv(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_sendto(struct thread *td, struct linux_sendto_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_sendto_args linux_args;
|
2003-11-09 17:04:04 +00:00
|
|
|
|
struct msghdr msg;
|
|
|
|
|
struct iovec aiov;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
caddr_t sg = stackgap_init();
|
2003-11-09 17:04:04 +00:00
|
|
|
|
int error;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
2003-02-08 09:26:31 +00:00
|
|
|
|
if (linux_check_hdrincl(td, &sg, linux_args.s) == 0)
|
2000-08-26 05:12:16 +00:00
|
|
|
|
/* IP_HDRINCL set, tweak the packet before sending */
|
2003-11-09 17:04:04 +00:00
|
|
|
|
return (linux_sendto_hdrincl(td, &sg, &linux_args));
|
|
|
|
|
|
|
|
|
|
msg.msg_name = linux_args.to;
|
|
|
|
|
msg.msg_namelen = linux_args.tolen;
|
|
|
|
|
msg.msg_iov = &aiov;
|
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
aiov.iov_base = linux_args.msg;
|
|
|
|
|
aiov.iov_len = linux_args.len;
|
|
|
|
|
error = linux_sendit(td, linux_args.s, &msg, linux_args.flags);
|
|
|
|
|
return (error);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_recvfrom_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
void *buf;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t from;
|
|
|
|
|
int *fromlen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_recvfrom_args linux_args;
|
|
|
|
|
struct recvfrom_args /* {
|
2003-12-25 09:59:02 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
size_t len;
|
|
|
|
|
int flags;
|
|
|
|
|
struct sockaddr * __restrict from;
|
|
|
|
|
socklen_t * __restrict fromlenaddr;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.buf = linux_args.buf;
|
|
|
|
|
bsd_args.len = linux_args.len;
|
2000-12-19 00:24:25 +00:00
|
|
|
|
bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags);
|
2003-12-25 09:59:02 +00:00
|
|
|
|
/* XXX: */
|
|
|
|
|
bsd_args.from = (struct sockaddr * __restrict)linux_args.from;
|
|
|
|
|
bsd_args.fromlenaddr = linux_args.fromlen; /* XXX */
|
2003-02-03 17:43:20 +00:00
|
|
|
|
error = orecvfrom(td, &bsd_args);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
if (linux_args.from) {
|
|
|
|
|
error = linux_sa_put((struct osockaddr *) linux_args.from);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_sendmsg_args {
|
|
|
|
|
int s;
|
|
|
|
|
const struct msghdr *msg;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args)
|
|
|
|
|
{
|
|
|
|
|
struct linux_sendmsg_args linux_args;
|
|
|
|
|
struct msghdr msg;
|
2003-11-09 17:04:04 +00:00
|
|
|
|
struct iovec aiov[UIO_SMALLIOV], *iov;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
2003-03-03 09:14:26 +00:00
|
|
|
|
error = copyin(linux_args.msg, &msg, sizeof(msg));
|
2003-02-03 17:43:20 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
2003-11-09 17:04:04 +00:00
|
|
|
|
if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
|
|
|
|
|
if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
|
|
|
|
|
return (EMSGSIZE);
|
|
|
|
|
MALLOC(iov, struct iovec *,
|
|
|
|
|
sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
|
|
|
|
|
M_WAITOK);
|
|
|
|
|
} else {
|
|
|
|
|
iov = aiov;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
}
|
2003-11-09 17:04:04 +00:00
|
|
|
|
if (msg.msg_iovlen &&
|
|
|
|
|
(error = copyin(msg.msg_iov, iov,
|
|
|
|
|
(unsigned)(msg.msg_iovlen * sizeof (struct iovec)))))
|
|
|
|
|
goto done;
|
|
|
|
|
msg.msg_iov = iov;
|
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
|
|
error = linux_sendit(td, linux_args.s, &msg, linux_args.flags);
|
|
|
|
|
done:
|
|
|
|
|
if (iov != aiov)
|
|
|
|
|
FREE(iov, M_IOV);
|
|
|
|
|
return (error);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-12-19 00:24:25 +00:00
|
|
|
|
struct linux_recvmsg_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct msghdr *msg;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args)
|
2000-12-19 00:24:25 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_recvmsg_args linux_args;
|
|
|
|
|
struct recvmsg_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
struct msghdr *msg;
|
|
|
|
|
int flags;
|
|
|
|
|
} */ bsd_args;
|
2003-02-03 17:43:20 +00:00
|
|
|
|
struct msghdr msg;
|
2003-10-11 15:08:32 +00:00
|
|
|
|
struct cmsghdr *cmsg;
|
2000-12-19 00:24:25 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.msg = linux_args.msg;
|
|
|
|
|
bsd_args.flags = linux_to_bsd_msg_flags(linux_args.flags);
|
2003-02-03 17:43:20 +00:00
|
|
|
|
error = recvmsg(td, &bsd_args);
|
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
|
2003-10-11 15:08:32 +00:00
|
|
|
|
if (bsd_args.msg->msg_control != NULL) {
|
|
|
|
|
cmsg = (struct cmsghdr*)bsd_args.msg->msg_control;
|
|
|
|
|
cmsg->cmsg_level = bsd_to_linux_sockopt_level(cmsg->cmsg_level);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 09:14:26 +00:00
|
|
|
|
error = copyin(linux_args.msg, &msg, sizeof(msg));
|
2003-02-03 17:43:20 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return (error);
|
|
|
|
|
if (msg.msg_name && msg.msg_namelen > 2)
|
|
|
|
|
error = linux_sa_put(msg.msg_name);
|
|
|
|
|
return (error);
|
2000-12-19 00:24:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
struct linux_shutdown_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
int how;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_shutdown(struct thread *td, struct linux_shutdown_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_shutdown_args linux_args;
|
|
|
|
|
struct shutdown_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
int how;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.how = linux_args.how;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (shutdown(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_setsockopt_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int optname;
|
|
|
|
|
void *optval;
|
|
|
|
|
int optlen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_setsockopt_args linux_args;
|
|
|
|
|
struct setsockopt_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
caddr_t val;
|
|
|
|
|
int valsize;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error, name;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.level = linux_to_bsd_sockopt_level(linux_args.level);
|
|
|
|
|
switch (bsd_args.level) {
|
|
|
|
|
case SOL_SOCKET:
|
|
|
|
|
name = linux_to_bsd_so_sockopt(linux_args.optname);
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_IP:
|
|
|
|
|
name = linux_to_bsd_ip_sockopt(linux_args.optname);
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
|
/* Linux TCP option values match BSD's */
|
|
|
|
|
name = linux_args.optname;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
name = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (name == -1)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
bsd_args.name = name;
|
|
|
|
|
bsd_args.val = linux_args.optval;
|
|
|
|
|
bsd_args.valsize = linux_args.optlen;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (setsockopt(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getsockopt_args {
|
2000-08-26 05:12:16 +00:00
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int optname;
|
|
|
|
|
void *optval;
|
|
|
|
|
int *optlen;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2000-08-26 05:12:16 +00:00
|
|
|
|
struct linux_getsockopt_args linux_args;
|
|
|
|
|
struct getsockopt_args /* {
|
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
caddr_t val;
|
|
|
|
|
int *avalsize;
|
|
|
|
|
} */ bsd_args;
|
|
|
|
|
int error, name;
|
|
|
|
|
|
|
|
|
|
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.level = linux_to_bsd_sockopt_level(linux_args.level);
|
|
|
|
|
switch (bsd_args.level) {
|
|
|
|
|
case SOL_SOCKET:
|
|
|
|
|
name = linux_to_bsd_so_sockopt(linux_args.optname);
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_IP:
|
|
|
|
|
name = linux_to_bsd_ip_sockopt(linux_args.optname);
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
|
/* Linux TCP option values match BSD's */
|
|
|
|
|
name = linux_args.optname;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
name = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (name == -1)
|
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
|
|
bsd_args.name = name;
|
|
|
|
|
bsd_args.val = linux_args.optval;
|
|
|
|
|
bsd_args.avalsize = linux_args.optlen;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (getsockopt(td, &bsd_args));
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
linux_socketcall(struct thread *td, struct linux_socketcall_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
2001-09-08 19:07:04 +00:00
|
|
|
|
void *arg = (void *)args->args;
|
2000-08-26 05:12:16 +00:00
|
|
|
|
|
|
|
|
|
switch (args->what) {
|
|
|
|
|
case LINUX_SOCKET:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_socket(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_BIND:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_bind(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_CONNECT:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_connect(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_LISTEN:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_listen(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_ACCEPT:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_accept(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_GETSOCKNAME:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_getsockname(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_GETPEERNAME:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_getpeername(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SOCKETPAIR:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_socketpair(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SEND:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_send(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_RECV:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_recv(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SENDTO:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_sendto(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_RECVFROM:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_recvfrom(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SHUTDOWN:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_shutdown(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SETSOCKOPT:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_setsockopt(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_GETSOCKOPT:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_getsockopt(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_SENDMSG:
|
2003-02-03 17:43:20 +00:00
|
|
|
|
return (linux_sendmsg(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
case LINUX_RECVMSG:
|
2001-09-12 08:38:13 +00:00
|
|
|
|
return (linux_recvmsg(td, arg));
|
2000-08-26 05:12:16 +00:00
|
|
|
|
}
|
1998-12-30 21:20:00 +00:00
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
uprintf("LINUX: 'socket' typ=%d not implemented\n", args->what);
|
2000-08-26 05:12:16 +00:00
|
|
|
|
return (ENOSYS);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
2000-11-01 19:48:35 +00:00
|
|
|
|
#endif /*!__alpha__*/
|