phunix/minix/servers/vfs/socket.c
David van Moolenbroek c38dbb97aa Prepare for switch to native BSD socket API
Currently, the BSD socket API is implemented in libc, translating the
API calls to character driver operations underneath.  This approach
has several issues:

- it is inefficient, as most character driver operations are specific
  to the socket type, thus requiring that each operation start by
  bruteforcing the socket protocol family and type of the given file
  descriptor using several system calls;
- it requires that libc itself be changed every time system support
  for a new protocol is added;
- various parts of the libc implementations violate the asynchronous
  signal safety POSIX requirements.

In order to resolve all these issues at once, the plan is to turn the
BSD socket calls into system calls, thus making the BSD socket API the
"native" ABI, removing the complexity from libc and instead letting
VFS deal with the socket calls.

The overall change is going to break all networking functionality. In
order to smoothen the transition, this patch introduces the fifteen
new BSD socket system calls, and makes libc try these first before
falling back on the old behavior.  For now, the VFS implementations of
the new calls fail such that libc will always use the fallback cases.
Later on, when we introduce the actual implementation of the native
BSD socket calls, all statically linked programs will automatically
use the new ABI, thus limiting actual application breakage.

In other words: by itself, this patch does nothing, except add a bit
of transitional overhead that will disappear in the future.  The
largest part of the patch is concerned with adding full support for
the new BSD socket system calls to trace(1) - this early addition has
the advantage of making system call tracing output of several socket
calls much more readable already.

Both the system call interfaces and the trace(1) support have already
been tested using code that will be committed later on.

Change-Id: I3460812be50c78be662d857f9d3d6840f3ca917f
2016-02-23 14:34:05 +00:00

180 lines
2.8 KiB
C

/*
* IMPORTANT NOTICE: THIS FILE CONTAINS STUBS ONLY RIGHT NOW, TO ENABLE A
* SEAMLESS TRANSITION TO THE NEW API FOR PROGRAMS STATICALLY LINKED TO LIBC!
*
* This file implements the upper socket layer of VFS: the BSD socket system
* calls, and any associated file descriptor, file pointer, vnode, and file
* system processing. In most cases, this layer will call into the lower
* socket layer in order to send the request to a socket driver. Generic file
* calls (e.g., read, write, ioctl, and select) are not implemented here, and
* will directly call into the lower socket layer as well.
*
* The following table shows the system call numbers implemented in this file,
* along with their request and reply message types. Each request layout
* message type is prefixed with "m_lc_vfs_". Each reply layout message type
* is prefixed with "m_vfs_lc_". For requests without a specific reply layout,
* only the "m_type" message field is used in the reply message.
*
* Type Request layout Reply layout
* ---- -------------- ------------
* VFS_SOCKET socket
* VFS_SOCKETPAIR socket fdpair
* VFS_BIND sockaddr
* VFS_CONNECT sockaddr
* VFS_LISTEN listen
* VFS_ACCEPT sockaddr socklen
* VFS_SENDTO sendrecv
* VFS_RECVFROM sendrecv socklen
* VFS_SENDMSG sockmsg
* VFS_RECVMSG sockmsg
* VFS_SETSOCKOPT sockopt
* VFS_GETSOCKOPT sockopt socklen
* VFS_GETSOCKNAME sockaddr socklen
* VFS_GETPEERNAME sockaddr socklen
* VFS_SHUTDOWN shutdown
*/
#include "fs.h"
#include <sys/socket.h>
/*
* Create a socket.
*/
int
do_socket(void)
{
return EAFNOSUPPORT;
}
/*
* Create a pair of connected sockets.
*/
int
do_socketpair(void)
{
return EAFNOSUPPORT;
}
/*
* Bind a socket to a local address.
*/
int
do_bind(void)
{
return ENOTSOCK;
}
/*
* Connect a socket to a remote address.
*/
int
do_connect(void)
{
return ENOTSOCK;
}
/*
* Put a socket in listening mode.
*/
int
do_listen(void)
{
return ENOTSOCK;
}
/*
* Accept a connection on a listening socket, creating a new socket.
*/
int
do_accept(void)
{
return ENOTSOCK;
}
/*
* Send a message on a socket.
*/
int
do_sendto(void)
{
return ENOTSOCK;
}
/*
* Receive a message from a socket.
*/
int
do_recvfrom(void)
{
return ENOTSOCK;
}
/*
* Send or receive a message on a socket using a message structure.
*/
int
do_sockmsg(void)
{
return ENOTSOCK;
}
/*
* Set socket options.
*/
int
do_setsockopt(void)
{
return ENOTSOCK;
}
/*
* Get socket options.
*/
int
do_getsockopt(void)
{
return ENOTSOCK;
}
/*
* Get the local address of a socket.
*/
int
do_getsockname(void)
{
return ENOTSOCK;
}
/*
* Get the remote address of a socket.
*/
int
do_getpeername(void)
{
return ENOTSOCK;
}
/*
* Shut down socket send and receive operations.
*/
int
do_shutdown(void)
{
return ENOTSOCK;
}