2009-01-22 19:10:19 +03:00
|
|
|
/* $NetBSD: svr4_net.c,v 1.55 2009/01/22 16:10:19 cegger Exp $ */
|
1998-09-05 18:50:25 +04:00
|
|
|
|
|
|
|
/*-
|
2008-03-22 00:54:58 +03:00
|
|
|
* Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
|
1998-09-05 18:50:25 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Christos Zoulas.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
1994-11-14 09:13:11 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emulate /dev/{udp,tcp,...}
|
|
|
|
*/
|
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-01-22 19:10:19 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: svr4_net.c,v 1.55 2009/01/22 16:10:19 cegger Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
1998-12-18 19:55:39 +03:00
|
|
|
#define COMPAT_SVR4 1
|
|
|
|
|
1994-11-14 09:13:11 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
1997-11-17 01:50:55 +03:00
|
|
|
#include <sys/fcntl.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1996-06-05 23:07:37 +04:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/domain.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/device.h>
|
1996-03-31 01:40:55 +03:00
|
|
|
#include <sys/conf.h>
|
1997-11-17 01:50:55 +03:00
|
|
|
#include <sys/mount.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
|
1997-11-17 01:50:55 +03:00
|
|
|
#include <sys/syscallargs.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
|
|
|
|
#include <compat/svr4/svr4_types.h>
|
|
|
|
#include <compat/svr4/svr4_util.h>
|
1994-11-18 05:53:37 +03:00
|
|
|
#include <compat/svr4/svr4_signal.h>
|
1999-09-07 22:20:18 +04:00
|
|
|
#include <compat/svr4/svr4_lwp.h>
|
|
|
|
#include <compat/svr4/svr4_ucontext.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
#include <compat/svr4/svr4_syscallargs.h>
|
|
|
|
#include <compat/svr4/svr4_ioctl.h>
|
1994-11-18 05:53:37 +03:00
|
|
|
#include <compat/svr4/svr4_stropts.h>
|
1996-04-11 16:52:41 +04:00
|
|
|
#include <compat/svr4/svr4_socket.h>
|
1994-11-14 09:13:11 +03:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(svr4_netopen);
|
|
|
|
|
|
|
|
const struct cdevsw svr4_net_cdevsw = {
|
|
|
|
svr4_netopen, noclose, noread, nowrite, noioctl,
|
2006-09-03 10:29:03 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
1994-11-14 09:13:11 +03:00
|
|
|
/*
|
|
|
|
* Device minor numbers
|
|
|
|
*/
|
|
|
|
enum {
|
1996-04-11 16:52:41 +04:00
|
|
|
dev_arp = 26,
|
|
|
|
dev_icmp = 27,
|
|
|
|
dev_ip = 28,
|
|
|
|
dev_tcp = 35,
|
|
|
|
dev_udp = 36,
|
|
|
|
dev_rawip = 37,
|
|
|
|
dev_unix_dgram = 38,
|
|
|
|
dev_unix_stream = 39,
|
|
|
|
dev_unix_ord_stream = 40
|
1994-11-14 09:13:11 +03:00
|
|
|
};
|
|
|
|
|
2007-12-04 21:40:07 +03:00
|
|
|
int svr4_netattach(int);
|
1995-10-14 23:24:14 +03:00
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
int svr4_soo_close(file_t *);
|
1994-11-18 05:53:37 +03:00
|
|
|
|
2004-11-30 07:25:43 +03:00
|
|
|
static const struct fileops svr4_netops = {
|
2001-04-07 21:37:09 +04:00
|
|
|
soo_read, soo_write, soo_ioctl, soo_fcntl, soo_poll,
|
2002-10-23 13:10:23 +04:00
|
|
|
soo_stat, svr4_soo_close, soo_kqfilter
|
1994-11-18 05:53:37 +03:00
|
|
|
};
|
1994-11-14 09:13:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used by new config, but we don't need it.
|
|
|
|
*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
svr4_netattach(int n)
|
1994-11-14 09:13:11 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
svr4_netopen(dev_t dev, int flag, int mode, struct lwp *l)
|
1994-11-14 09:13:11 +03:00
|
|
|
{
|
1994-12-14 23:08:30 +03:00
|
|
|
int type, protocol;
|
|
|
|
int fd;
|
2008-03-22 00:54:58 +03:00
|
|
|
file_t *fp;
|
1994-11-14 09:13:11 +03:00
|
|
|
struct socket *so;
|
|
|
|
int error;
|
1996-04-11 16:52:41 +04:00
|
|
|
int family;
|
1994-11-14 09:13:11 +03:00
|
|
|
|
|
|
|
DPRINTF(("netopen("));
|
|
|
|
|
2003-09-13 12:32:10 +04:00
|
|
|
if (curlwp->l_dupfd >= 0) /* XXX */
|
1994-11-14 09:13:11 +03:00
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
switch (minor(dev)) {
|
|
|
|
case dev_udp:
|
1996-04-11 16:52:41 +04:00
|
|
|
family = AF_INET;
|
1994-11-14 09:13:11 +03:00
|
|
|
type = SOCK_DGRAM;
|
|
|
|
protocol = IPPROTO_UDP;
|
|
|
|
DPRINTF(("udp, "));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dev_tcp:
|
1996-04-11 16:52:41 +04:00
|
|
|
family = AF_INET;
|
1994-11-14 09:13:11 +03:00
|
|
|
type = SOCK_STREAM;
|
|
|
|
protocol = IPPROTO_TCP;
|
|
|
|
DPRINTF(("tcp, "));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dev_ip:
|
1996-04-11 16:52:41 +04:00
|
|
|
case dev_rawip:
|
|
|
|
family = AF_INET;
|
1994-11-14 09:13:11 +03:00
|
|
|
type = SOCK_RAW;
|
|
|
|
protocol = IPPROTO_IP;
|
|
|
|
DPRINTF(("ip, "));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dev_icmp:
|
1996-04-11 16:52:41 +04:00
|
|
|
family = AF_INET;
|
1994-11-14 09:13:11 +03:00
|
|
|
type = SOCK_RAW;
|
|
|
|
protocol = IPPROTO_ICMP;
|
|
|
|
DPRINTF(("icmp, "));
|
|
|
|
break;
|
|
|
|
|
1996-04-11 16:52:41 +04:00
|
|
|
case dev_unix_dgram:
|
1998-07-18 09:04:35 +04:00
|
|
|
family = AF_LOCAL;
|
1996-04-11 16:52:41 +04:00
|
|
|
type = SOCK_DGRAM;
|
|
|
|
protocol = 0;
|
|
|
|
DPRINTF(("unix-dgram, "));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dev_unix_stream:
|
|
|
|
case dev_unix_ord_stream:
|
1998-07-18 09:04:35 +04:00
|
|
|
family = AF_LOCAL;
|
1996-04-11 16:52:41 +04:00
|
|
|
type = SOCK_STREAM;
|
|
|
|
protocol = 0;
|
|
|
|
DPRINTF(("unix-stream, "));
|
|
|
|
break;
|
|
|
|
|
1994-11-14 09:13:11 +03:00
|
|
|
default:
|
2009-01-22 19:10:19 +03:00
|
|
|
DPRINTF(("%"PRId32");\n", minor(dev)));
|
1994-11-14 09:13:11 +03:00
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
if ((error = fd_allocfile(&fp, &fd)) != 0)
|
1997-11-17 01:50:55 +03:00
|
|
|
return error;
|
1994-11-14 09:13:11 +03:00
|
|
|
|
2008-04-24 15:38:36 +04:00
|
|
|
if ((error = socreate(family, &so, type, protocol, l, NULL)) != 0) {
|
1994-11-14 09:13:11 +03:00
|
|
|
DPRINTF(("socreate error %d\n", error));
|
2008-03-22 00:54:58 +03:00
|
|
|
fd_abort(curproc, fp, fd);
|
1994-11-14 09:13:11 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
error = fd_clone(fp, fd, flag, &svr4_netops, so);
|
1994-11-14 09:13:11 +03:00
|
|
|
fp->f_type = DTYPE_SOCKET;
|
2004-11-30 07:25:43 +03:00
|
|
|
(void)svr4_stream_get(fp);
|
1996-06-05 23:07:37 +04:00
|
|
|
|
1994-11-14 09:13:11 +03:00
|
|
|
DPRINTF(("ok);\n"));
|
2004-11-30 07:25:43 +03:00
|
|
|
return error;
|
1994-11-14 09:13:11 +03:00
|
|
|
}
|
1994-11-18 05:53:37 +03:00
|
|
|
|
1997-11-17 01:50:55 +03:00
|
|
|
|
2001-02-11 04:16:42 +03:00
|
|
|
int
|
2008-03-22 00:54:58 +03:00
|
|
|
svr4_soo_close(file_t *fp)
|
1994-11-18 05:53:37 +03:00
|
|
|
{
|
2008-03-22 00:54:58 +03:00
|
|
|
struct socket *so = fp->f_data;
|
1997-11-17 01:50:55 +03:00
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
svr4_delete_socket(curproc, fp);
|
1996-02-04 05:01:07 +03:00
|
|
|
free(so->so_internal, M_NETADDR);
|
2008-03-22 00:54:58 +03:00
|
|
|
return soo_close(fp);
|
1994-11-18 05:53:37 +03:00
|
|
|
}
|
1996-06-05 23:07:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
struct svr4_strm *
|
2008-03-22 00:54:58 +03:00
|
|
|
svr4_stream_get(file_t *fp)
|
1996-06-05 23:07:37 +04:00
|
|
|
{
|
|
|
|
struct socket *so;
|
|
|
|
struct svr4_strm *st;
|
|
|
|
|
|
|
|
if (fp == NULL || fp->f_type != DTYPE_SOCKET)
|
|
|
|
return NULL;
|
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
so = fp->f_data;
|
1996-06-05 23:07:37 +04:00
|
|
|
|
|
|
|
if (so->so_internal)
|
|
|
|
return so->so_internal;
|
|
|
|
|
|
|
|
/* Allocate a new one. */
|
|
|
|
fp->f_ops = &svr4_netops;
|
|
|
|
st = malloc(sizeof(struct svr4_strm), M_NETADDR, M_WAITOK);
|
|
|
|
st->s_family = so->so_proto->pr_domain->dom_family;
|
|
|
|
st->s_cmd = ~0;
|
1996-08-31 03:06:24 +04:00
|
|
|
st->s_afd = -1;
|
1998-08-27 11:04:31 +04:00
|
|
|
st->s_eventmask = 0;
|
1996-06-05 23:07:37 +04:00
|
|
|
so->so_internal = st;
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|