Import socket() implementation from FreeBSD

Add new test syscalls01.
This commit is contained in:
Sebastian Huber 2013-10-10 11:29:33 +02:00
parent 69b29a0c0d
commit caf8eded60
9 changed files with 3452 additions and 38 deletions

View File

@ -163,6 +163,8 @@ LIB_C_FILES += freebsd/sys/libkern/fls.c
LIB_C_FILES += freebsd/sys/libkern/inet_ntoa.c
LIB_C_FILES += freebsd/sys/libkern/random.c
LIB_C_FILES += freebsd/sys/vm/uma_core.c
LIB_C_FILES += freebsd/sys/kern/sys_socket.c
LIB_C_FILES += freebsd/sys/kern/uipc_syscalls.c
LIB_C_FILES += freebsd/sys/net/bridgestp.c
LIB_C_FILES += freebsd/sys/net/ieee8023ad_lacp.c
LIB_C_FILES += freebsd/sys/net/if_atmsubr.c
@ -778,6 +780,18 @@ LIB_C_FILES += freebsd/usr.bin/netstat/pfkey.c
LIB_C_FILES += freebsd/usr.bin/netstat/sctp.c
LIB_C_FILES += freebsd/usr.bin/netstat/unix.c
TEST_SYSCALLS01 = testsuite/syscalls01/syscalls01.exe
TEST_SYSCALLS01_O_FILES =
TEST_SYSCALLS01_D_FILES =
TEST_SYSCALLS01_O_FILES += testsuite/syscalls01/test_main.o
TEST_SYSCALLS01_D_FILES += testsuite/syscalls01/test_main.d
$(TEST_SYSCALLS01): $(TEST_SYSCALLS01_O_FILES) $(LIB)
$(LINK.c) -Wl,-Map,testsuite/syscalls01/syscalls01.map $^ -lm -o $@
TESTS += $(TEST_SYSCALLS01)
O_FILES += $(TEST_SYSCALLS01_O_FILES)
D_FILES += $(TEST_SYSCALLS01_D_FILES)
RUN_TESTS += $(TEST_SYSCALLS01)
TEST_USB01 = testsuite/usb01/usb01.exe
TEST_USB01_O_FILES =
TEST_USB01_D_FILES =

View File

@ -1432,6 +1432,8 @@ net.addHeaderFiles(
)
net.addSourceFiles(
[
'sys/kern/sys_socket.c',
'sys/kern/uipc_syscalls.c',
'sys/net/bridgestp.c',
'sys/net/ieee8023ad_lacp.c',
'sys/net/if_atmsubr.c',
@ -2356,6 +2358,7 @@ in_cksum.addCPUDependentSourceFiles(
)
tests = Module('tests')
tests.addTest('syscalls01', ['test_main'])
tests.addTest('usb01', ['init', 'test-file-system'], False)
tests.addTest('loopback01', ['test_main'])
tests.addTest('netshell01', ['test_main', 'shellconfig', 'ns_parser_vars'], False)

View File

@ -0,0 +1,330 @@
#include <machine/rtems-bsd-config.h>
/*-
* Copyright (c) 1982, 1986, 1990, 1993
* The Regents of the University of California. 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.
* 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.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#)sys_socket.c 8.1 (Berkeley) 6/10/93
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <rtems/bsd/sys/param.h>
#include <sys/systm.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/sigio.h>
#include <sys/signal.h>
#include <sys/signalvar.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/filio.h> /* XXX */
#include <sys/sockio.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <sys/ucred.h>
#include <net/if.h>
#include <net/route.h>
#include <net/vnet.h>
#include <security/mac/mac_framework.h>
#ifndef __rtems__
struct fileops socketops = {
.fo_read = soo_read,
.fo_write = soo_write,
.fo_truncate = soo_truncate,
.fo_ioctl = soo_ioctl,
.fo_poll = soo_poll,
.fo_kqfilter = soo_kqfilter,
.fo_stat = soo_stat,
.fo_close = soo_close,
.fo_flags = DFLAG_PASSABLE
};
#endif /* __rtems__ */
#ifndef __rtems__
/* ARGSUSED */
int
soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
struct socket *so = fp->f_data;
int error;
#ifdef MAC
error = mac_socket_check_receive(active_cred, so);
if (error)
return (error);
#endif
CURVNET_SET(so->so_vnet);
error = soreceive(so, 0, uio, 0, 0, 0);
CURVNET_RESTORE();
return (error);
}
/* ARGSUSED */
int
soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
struct socket *so = fp->f_data;
int error;
#ifdef MAC
error = mac_socket_check_send(active_cred, so);
if (error)
return (error);
#endif
error = sosend(so, 0, uio, 0, 0, 0, uio->uio_td);
if (error == EPIPE && (so->so_options & SO_NOSIGPIPE) == 0) {
PROC_LOCK(uio->uio_td->td_proc);
tdksignal(uio->uio_td, SIGPIPE, NULL);
PROC_UNLOCK(uio->uio_td->td_proc);
}
return (error);
}
int
soo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{
return (EINVAL);
}
int
soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
struct thread *td)
{
struct socket *so = fp->f_data;
int error = 0;
CURVNET_SET(so->so_vnet);
switch (cmd) {
case FIONBIO:
SOCK_LOCK(so);
if (*(int *)data)
so->so_state |= SS_NBIO;
else
so->so_state &= ~SS_NBIO;
SOCK_UNLOCK(so);
break;
case FIOASYNC:
/*
* XXXRW: This code separately acquires SOCK_LOCK(so) and
* SOCKBUF_LOCK(&so->so_rcv) even though they are the same
* mutex to avoid introducing the assumption that they are
* the same.
*/
if (*(int *)data) {
SOCK_LOCK(so);
so->so_state |= SS_ASYNC;
SOCK_UNLOCK(so);
SOCKBUF_LOCK(&so->so_rcv);
so->so_rcv.sb_flags |= SB_ASYNC;
SOCKBUF_UNLOCK(&so->so_rcv);
SOCKBUF_LOCK(&so->so_snd);
so->so_snd.sb_flags |= SB_ASYNC;
SOCKBUF_UNLOCK(&so->so_snd);
} else {
SOCK_LOCK(so);
so->so_state &= ~SS_ASYNC;
SOCK_UNLOCK(so);
SOCKBUF_LOCK(&so->so_rcv);
so->so_rcv.sb_flags &= ~SB_ASYNC;
SOCKBUF_UNLOCK(&so->so_rcv);
SOCKBUF_LOCK(&so->so_snd);
so->so_snd.sb_flags &= ~SB_ASYNC;
SOCKBUF_UNLOCK(&so->so_snd);
}
break;
case FIONREAD:
/* Unlocked read. */
*(int *)data = so->so_rcv.sb_cc;
break;
case FIONWRITE:
/* Unlocked read. */
*(int *)data = so->so_snd.sb_cc;
break;
case FIONSPACE:
if ((so->so_snd.sb_hiwat < so->so_snd.sb_cc) ||
(so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt))
*(int *)data = 0;
else
*(int *)data = sbspace(&so->so_snd);
break;
case FIOSETOWN:
error = fsetown(*(int *)data, &so->so_sigio);
break;
case FIOGETOWN:
*(int *)data = fgetown(&so->so_sigio);
break;
case SIOCSPGRP:
error = fsetown(-(*(int *)data), &so->so_sigio);
break;
case SIOCGPGRP:
*(int *)data = -fgetown(&so->so_sigio);
break;
case SIOCATMARK:
/* Unlocked read. */
*(int *)data = (so->so_rcv.sb_state & SBS_RCVATMARK) != 0;
break;
default:
/*
* Interface/routing/protocol specific ioctls: interface and
* routing ioctls should have a different entry since a
* socket is unnecessary.
*/
if (IOCGROUP(cmd) == 'i')
error = ifioctl(so, cmd, data, td);
else if (IOCGROUP(cmd) == 'r')
error = rtioctl_fib(cmd, data, so->so_fibnum);
else
error = ((*so->so_proto->pr_usrreqs->pru_control)
(so, cmd, data, 0, td));
break;
}
CURVNET_RESTORE();
return (error);
}
int
soo_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
{
struct socket *so = fp->f_data;
#ifdef MAC
int error;
error = mac_socket_check_poll(active_cred, so);
if (error)
return (error);
#endif
return (sopoll(so, events, fp->f_cred, td));
}
int
soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
struct thread *td)
{
struct socket *so = fp->f_data;
#ifdef MAC
int error;
#endif
bzero((caddr_t)ub, sizeof (*ub));
ub->st_mode = S_IFSOCK;
#ifdef MAC
error = mac_socket_check_stat(active_cred, so);
if (error)
return (error);
#endif
/*
* If SBS_CANTRCVMORE is set, but there's still data left in the
* receive buffer, the socket is still readable.
*/
SOCKBUF_LOCK(&so->so_rcv);
if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) == 0 ||
so->so_rcv.sb_cc != 0)
ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
ub->st_size = so->so_rcv.sb_cc - so->so_rcv.sb_ctl;
SOCKBUF_UNLOCK(&so->so_rcv);
/* Unlocked read. */
if ((so->so_snd.sb_state & SBS_CANTSENDMORE) == 0)
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
ub->st_uid = so->so_cred->cr_uid;
ub->st_gid = so->so_cred->cr_gid;
return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
}
#endif /* __rtems__ */
/*
* API socket close on file pointer. We call soclose() to close the socket
* (including initiating closing protocols). soclose() will sorele() the
* file reference but the actual socket will not go away until the socket's
* ref count hits 0.
*/
/* ARGSUSED */
#ifdef __rtems__
static
#endif /* __rtems__ */
int
soo_close(struct file *fp, struct thread *td)
{
int error = 0;
struct socket *so;
so = fp->f_data;
#ifndef __rtems__
fp->f_ops = &badfileops;
#else /* __rtems__ */
fp->f_io.pathinfo.handlers = &rtems_filesystem_handlers_default;
#endif /* __rtems__ */
fp->f_data = NULL;
if (so)
error = soclose(so);
return (error);
}
#ifdef __rtems__
static int
rtems_bsd_soo_close(rtems_libio_t *iop)
{
struct file *fp = rtems_bsd_iop_to_fp(iop);
int error = soo_close(fp, NULL);
return rtems_bsd_error_to_status_and_errno(error);
}
const rtems_filesystem_file_handlers_r socketops = {
.open_h = rtems_filesystem_default_open,
.close_h = rtems_bsd_soo_close,
.read_h = rtems_filesystem_default_read,
.write_h = rtems_filesystem_default_write,
.ioctl_h = rtems_filesystem_default_ioctl,
.lseek_h = rtems_filesystem_default_lseek,
.fstat_h = rtems_filesystem_default_fstat,
.ftruncate_h = rtems_filesystem_default_ftruncate,
.fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
.fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
.fcntl_h = rtems_filesystem_default_fcntl
};
#endif /* __rtems__ */

File diff suppressed because it is too large Load Diff

View File

@ -254,7 +254,11 @@ MALLOC_DECLARE(M_FILE);
extern struct fileops vnops;
extern struct fileops badfileops;
#ifndef __rtems__
extern struct fileops socketops;
#else /* __rtems__ */
extern const rtems_filesystem_file_handlers_r socketops;
#endif /* __rtems__ */
extern int maxfiles; /* kernel limit on number of open files */
extern int maxfilesperproc; /* per process limit on number of open files */
extern volatile int openfiles; /* actual number of open files */
@ -280,6 +284,7 @@ int fget_read(struct thread *td, int fd, struct file **fpp);
int fget_write(struct thread *td, int fd, struct file **fpp);
int _fdrop(struct file *fp, struct thread *td);
#ifndef __rtems__
/*
* The socket operations are used a couple of places.
* XXX: This is wrong, they should go through the operations vector for
@ -293,6 +298,7 @@ fo_poll_t soo_poll;
fo_kqfilter_t soo_kqfilter;
fo_stat_t soo_stat;
fo_close_t soo_close;
#endif /* __rtems__ */
#ifndef __rtems__
void finit(struct file *, u_int, short, void *, struct fileops *);

View File

@ -350,11 +350,13 @@ struct setpriority_args {
char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)];
char prio_l_[PADL_(int)]; int prio; char prio_r_[PADR_(int)];
};
#endif /* __rtems__ */
struct socket_args {
char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)];
char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)];
char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)];
};
#ifndef __rtems__
struct connect_args {
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)];

View File

@ -46,6 +46,7 @@
#include <sys/cdefs.h>
#include <sys/select.h>
#include <sys/socket.h>
__BEGIN_DECLS
@ -54,6 +55,8 @@ int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict,
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
int socket(int, int, int);
__END_DECLS
#endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_SYSCALL_API_H_ */

View File

@ -192,44 +192,6 @@ getsockaddr(namp, uaddr, len)
* BSD-style entry points *
*********************************************************************
*/
int
socket (int domain, int type, int protocol)
{
struct thread *td;
struct socket *so;
int fd, error;
td = curthread;
if (!td) {
printf("Current thread NULL\n");
exit(0);
}
#ifdef MAC
error = mac_socket_check_create(td->td_ucred, domain, type, protocol);
if (error == 0 )
{
#endif
/* An extra reference on `fp' has been held for us by falloc(). */
error = socreate(domain, &so, type, protocol, td->td_ucred, td);
if (error == 0) {
fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0)
{
soclose (so);
error = EBADF;
}
}
#ifdef MAC
}
#endif
if( error == 0 )
{
return fd;
}
errno = error;
return -1;
}
int
kern_bind(td, fd, sa)
struct thread *td;

View File

@ -0,0 +1,310 @@
/*
* Copyright (c) 2013 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* 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 AUTHOR 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 AUTHOR 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.
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <rtems/libcsupport.h>
#define TEST_NAME "LIBBSD SYSCALLS 1"
typedef struct {
int domain;
int type;
int protocol;
int expect_errno;
} socket_test;
static socket_test socket_tests[] = {
{ -1, SOCK_RAW, 0, EPROTONOSUPPORT },
{ PF_UNSPEC, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_UNIX, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_INET, -1, 0, EPROTONOSUPPORT },
{ PF_INET, SOCK_RAW, -1, EPROTONOSUPPORT },
{ PF_INET, SOCK_STREAM, 0, 0 },
{ PF_INET, SOCK_DGRAM, 0, 0 },
{ PF_INET, SOCK_SEQPACKET, 0, EPROTONOSUPPORT },
{ PF_INET, SOCK_RAW, IPPROTO_3PC, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ADFS, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_AH, EPROTONOSUPPORT },
{ PF_INET, SOCK_RAW, IPPROTO_AHIP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_APES, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ARGUS, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_AX25, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_BHA, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_BLT, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_BRSATMON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CARP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CFTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CHAOS, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CMTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CPHB, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_CPNX, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_DDP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_DGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_DSTOPTS, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_EGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_EMCON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ENCAP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_EON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ESP, EPROTONOSUPPORT },
{ PF_INET, SOCK_RAW, IPPROTO_ETHERIP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_FRAGMENT, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_GGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_GMTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_GRE, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_HELLO, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_HMP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ICMP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ICMPV6, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IDP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IDPR, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IDRP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IGMP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IGRP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IL, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_INLSP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_INP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPCOMP, EPROTONOSUPPORT },
{ PF_INET, SOCK_RAW, IPPROTO_IPCV, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPEIP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPIP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPPC, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPV4, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IPV6, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_IRTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_KRYPTOLAN, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_LARP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_LEAF1, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_LEAF2, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MEAS, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MHRP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MICP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MOBILE, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_MUX, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ND, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_NHRP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_NONE, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_NSP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_NVPII, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_OLD_DIVERT, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_OSPFIGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PFSYNC, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PGM, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PIGP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PIM, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PRM, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PUP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_PVP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_RCCMON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_RDP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ROUTING, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_RSVP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_RVD, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SATEXPAK, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SATMON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SCCSP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SCTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SDRP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SEP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SKIP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SRPC, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_ST, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SVMTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_SWIPE, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TCF, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TCP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TLSP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TPXX, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TRUNK1, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TRUNK2, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_TTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_UDP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_VINES, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_VISA, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_VMTP, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_WBEXPAK, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_WBMON, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_WSN, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_XNET, 0 },
{ PF_INET, SOCK_RAW, IPPROTO_XTP, 0 },
{ PF_IMPLINK, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_PUP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_CHAOS, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_NETBIOS, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ISO, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ECMA, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_DATAKIT, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_CCITT, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_SNA, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_DECnet, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_DLI, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_LAT, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_HYLINK, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_APPLETALK, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ROUTE, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_LINK, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_XTP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_COIP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_CNT, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_RTIP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_IPX, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_SIP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_PIP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ISDN, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_KEY, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_INET6, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_NATM, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ATM, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ pseudo_AF_HDRCMPLT, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_NETGRAPH, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_SLOW, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_SCLUSTER, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_ARP, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ PF_BLUETOOTH, SOCK_DGRAM, 0, EPROTONOSUPPORT },
{ AF_IEEE80211, SOCK_DGRAM, 0, EPROTONOSUPPORT }
};
static void
test_socket(const socket_test *st)
{
int sd;
int rv;
errno = 0;
sd = socket(st->domain, st->type, st->protocol);
if (st->expect_errno == 0) {
assert(sd >= 0);
rv = close(sd);
assert(rv == 0);
} else {
assert(st->expect_errno == errno);
}
}
static void
test_sockets(void)
{
size_t n = sizeof(socket_tests) / sizeof(socket_tests[0]);
size_t i;
puts("test sockets");
for (i = 0; i < n; ++i) {
const socket_test *st = &socket_tests[i];
test_socket(st);
}
puts("test sockets and check resources");
for (i = 0; i < n; ++i) {
const socket_test *st = &socket_tests[i];
rtems_resource_snapshot snapshot;
rtems_resource_snapshot_take(&snapshot);
test_socket(st);
assert(rtems_resource_snapshot_check(&snapshot));
}
}
static void
test_socket_unsupported_ops(void)
{
rtems_resource_snapshot snapshot;
int sd;
int rv;
off_t off;
puts("test socket unsupported ops");
rtems_resource_snapshot_take(&snapshot);
sd = socket(PF_INET, SOCK_DGRAM, 0);
assert(sd >= 0);
errno = 0;
off = lseek(sd, 0, SEEK_CUR);
assert(off == -1);
assert(errno == ESPIPE);
errno = 0;
rv = ftruncate(sd, 0);
assert(rv == -1);
assert(errno == EINVAL);
errno = 0;
rv = fsync(sd);
assert(rv == -1);
assert(errno == EINVAL);
errno = 0;
rv = fdatasync(sd);
assert(rv == -1);
assert(errno == EINVAL);
rv = close(sd);
assert(rv == 0);
assert(rtems_resource_snapshot_check(&snapshot));
}
static void
test_main(void)
{
/* Must be first test to ensure resource checks work */
test_sockets();
test_socket_unsupported_ops();
puts("*** END OF " TEST_NAME " TEST ***");
exit(0);
}
#include <rtems/bsd/test/default-init.h>