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
|
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
|
* 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
|
|
|
|
|
* derived from this software withough specific prior written permission
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
1997-11-06 19:29:57 +00:00
|
|
|
|
* $Id: linux_socket.c,v 1.8 1997/07/20 16:06:04 bde Exp $
|
1995-06-25 17:32:43 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1995-11-22 07:43:53 +00:00
|
|
|
|
/* XXX we use functions that might not exist. */
|
|
|
|
|
#define COMPAT_43 1
|
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
1995-11-22 07:43:53 +00:00
|
|
|
|
#include <sys/sysproto.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <sys/socket.h>
|
1995-11-22 07:43:53 +00:00
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
1995-11-22 07:43:53 +00:00
|
|
|
|
#include <i386/linux/linux.h>
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
#include <i386/linux/linux_proto.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_domain(int domain)
|
|
|
|
|
{
|
|
|
|
|
switch (domain) {
|
|
|
|
|
case LINUX_AF_UNSPEC:
|
|
|
|
|
return AF_UNSPEC;
|
|
|
|
|
case LINUX_AF_UNIX:
|
|
|
|
|
return AF_LOCAL;
|
|
|
|
|
case LINUX_AF_INET:
|
|
|
|
|
return AF_INET;
|
|
|
|
|
case LINUX_AF_AX25:
|
|
|
|
|
return AF_CCITT;
|
|
|
|
|
case LINUX_AF_IPX:
|
|
|
|
|
return AF_IPX;
|
|
|
|
|
case LINUX_AF_APPLETALK:
|
|
|
|
|
return AF_APPLETALK;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_sockopt_level(int level)
|
|
|
|
|
{
|
|
|
|
|
switch (level) {
|
|
|
|
|
case LINUX_SOL_SOCKET:
|
|
|
|
|
return SOL_SOCKET;
|
|
|
|
|
default:
|
|
|
|
|
return level;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int linux_to_bsd_ip_sockopt(int opt)
|
|
|
|
|
{
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case LINUX_IP_TOS:
|
|
|
|
|
return IP_TOS;
|
|
|
|
|
case LINUX_IP_TTL:
|
|
|
|
|
return IP_TTL;
|
1996-12-03 02:52:29 +00:00
|
|
|
|
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:
|
1995-06-25 17:32:43 +00:00
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
linux_to_bsd_so_sockopt(int opt)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
case LINUX_SO_PRIORITY:
|
|
|
|
|
case LINUX_SO_NO_CHECK:
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_socket_args {
|
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_socket(struct proc *p, struct linux_socket_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_socket_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct socket_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return socket(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_bind_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr *name;
|
|
|
|
|
int namelen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_bind(struct proc *p, struct linux_bind_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_bind_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct bind_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t name;
|
|
|
|
|
int namelen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&linux_args, sizeof(linux_args))))
|
|
|
|
|
return error;
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.name = (caddr_t)linux_args.name;
|
|
|
|
|
bsd_args.namelen = linux_args.namelen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return bind(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_connect_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr * name;
|
|
|
|
|
int namelen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_connect(struct proc *p, struct linux_connect_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_connect_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct connect_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t name;
|
|
|
|
|
int namelen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&linux_args, sizeof(linux_args))))
|
|
|
|
|
return error;
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.name = (caddr_t)linux_args.name;
|
|
|
|
|
bsd_args.namelen = linux_args.namelen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return connect(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_listen_args {
|
|
|
|
|
int s;
|
|
|
|
|
int backlog;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_listen(struct proc *p, struct linux_listen_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_listen_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct listen_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
int backlog;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&linux_args, sizeof(linux_args))))
|
|
|
|
|
return error;
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.backlog = linux_args.backlog;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return listen(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_accept_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr *addr;
|
|
|
|
|
int *namelen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_accept(struct proc *p, struct linux_accept_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_accept_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct accept_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t name;
|
|
|
|
|
int *anamelen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&linux_args, sizeof(linux_args))))
|
|
|
|
|
return error;
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.name = (caddr_t)linux_args.addr;
|
|
|
|
|
bsd_args.anamelen = linux_args.namelen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return oaccept(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getsockname_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr *addr;
|
|
|
|
|
int *namelen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_getsockname(struct proc *p, struct linux_getsockname_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_getsockname_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct getsockname_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int fdes;
|
|
|
|
|
caddr_t asa;
|
|
|
|
|
int *alen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return ogetsockname(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getpeername_args {
|
|
|
|
|
int s;
|
|
|
|
|
struct sockaddr *addr;
|
|
|
|
|
int *namelen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_getpeername(struct proc *p, struct linux_getpeername_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_getpeername_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct ogetpeername_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int fdes;
|
|
|
|
|
caddr_t asa;
|
|
|
|
|
int *alen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return ogetpeername(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_socketpair_args {
|
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
int *rsv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_socketpair(struct proc *p, struct linux_socketpair_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_socketpair_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct socketpair_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int domain;
|
|
|
|
|
int type;
|
|
|
|
|
int protocol;
|
|
|
|
|
int *rsv;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return socketpair(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_send_args {
|
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_send(struct proc *p, struct linux_send_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_send_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct osend_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return osend(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_recv_args {
|
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_recv(struct proc *p, struct linux_recv_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_recv_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct orecv_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return orecv(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_sendto_args {
|
|
|
|
|
int s;
|
|
|
|
|
void *msg;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t to;
|
|
|
|
|
int tolen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_sendto(struct proc *p, struct linux_sendto_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_sendto_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct sendto_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
size_t len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t to;
|
|
|
|
|
int tolen;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
|
|
|
|
bsd_args.to = linux_args.to;
|
|
|
|
|
bsd_args.tolen = linux_args.tolen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return sendto(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_recvfrom_args {
|
|
|
|
|
int s;
|
|
|
|
|
void *buf;
|
|
|
|
|
int len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t from;
|
|
|
|
|
int *fromlen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_recvfrom(struct proc *p, struct linux_recvfrom_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_recvfrom_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct recvfrom_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
caddr_t buf;
|
|
|
|
|
size_t len;
|
|
|
|
|
int flags;
|
|
|
|
|
caddr_t from;
|
|
|
|
|
int *fromlenaddr;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
|
|
|
|
bsd_args.flags = linux_args.flags;
|
|
|
|
|
bsd_args.from = linux_args.from;
|
|
|
|
|
bsd_args.fromlenaddr = linux_args.fromlen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return orecvfrom(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_shutdown_args {
|
|
|
|
|
int s;
|
|
|
|
|
int how;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_shutdown(struct proc *p, struct linux_shutdown_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_shutdown_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct shutdown_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
int how;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&linux_args, sizeof(linux_args))))
|
|
|
|
|
return error;
|
|
|
|
|
bsd_args.s = linux_args.s;
|
|
|
|
|
bsd_args.how = linux_args.how;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return shutdown(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_setsockopt_args {
|
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int optname;
|
|
|
|
|
void *optval;
|
|
|
|
|
int optlen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_setsockopt(struct proc *p, struct linux_setsockopt_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_setsockopt_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct setsockopt_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
caddr_t val;
|
|
|
|
|
int valsize;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error, name;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
|
|
|
|
default:
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
if (name == -1)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
bsd_args.name = name;
|
|
|
|
|
bsd_args.val = linux_args.optval;
|
|
|
|
|
bsd_args.valsize = linux_args.optlen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return setsockopt(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct linux_getsockopt_args {
|
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int optname;
|
|
|
|
|
void *optval;
|
|
|
|
|
int *optlen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_getsockopt(struct proc *p, struct linux_getsockopt_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct linux_getsockopt_args linux_args;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
struct getsockopt_args /* {
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int s;
|
|
|
|
|
int level;
|
|
|
|
|
int name;
|
|
|
|
|
caddr_t val;
|
|
|
|
|
int *avalsize;
|
1995-12-15 03:06:57 +00:00
|
|
|
|
} */ bsd_args;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
int error, name;
|
|
|
|
|
|
|
|
|
|
if ((error=copyin((caddr_t)args, (caddr_t)&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;
|
|
|
|
|
default:
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
if (name == -1)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
bsd_args.val = linux_args.optval;
|
|
|
|
|
bsd_args.avalsize = linux_args.optlen;
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return getsockopt(p, &bsd_args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
1997-11-06 19:29:57 +00:00
|
|
|
|
linux_socketcall(struct proc *p, struct linux_socketcall_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
switch (args->what) {
|
|
|
|
|
case LINUX_SOCKET:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_socket(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_BIND:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_bind(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_CONNECT:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_connect(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_LISTEN:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_listen(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_ACCEPT:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_accept(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_GETSOCKNAME:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_getsockname(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_GETPEERNAME:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_getpeername(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_SOCKETPAIR:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_socketpair(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_SEND:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_send(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_RECV:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_recv(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_SENDTO:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_sendto(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_RECVFROM:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_recvfrom(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_SHUTDOWN:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_shutdown(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_SETSOCKOPT:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_setsockopt(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
case LINUX_GETSOCKOPT:
|
1997-11-06 19:29:57 +00:00
|
|
|
|
return linux_getsockopt(p, args->args);
|
1995-06-25 17:32:43 +00:00
|
|
|
|
default:
|
|
|
|
|
uprintf("LINUX: 'socket' typ=%d not implemented\n", args->what);
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
}
|