2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-10-06 14:39:15 +00:00
|
|
|
#include "opt_mac.h"
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/file.h>
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/filedesc.h>
|
The SO_NOSIGPIPE socket option allows a user process to mark a socket
so that the socket does not generate SIGPIPE, only EPIPE, when a write
is attempted after socket shutdown. When the option was introduced in
2002, this required the logic for determining whether SIGPIPE was
generated to be pushed down from dofilewrite() to the socket layer so
that the socket options could be considered. However, the change in
2002 omitted modification to soo_write() required to add that logic,
resulting in SIGPIPE not being generated even without SO_NOSIGPIPE when
the socket was written to using write() or related generic system calls.
This change adds the EPIPE logic to soo_write(), generating a SIGPIPE
signal to the process associated with the passed uio in the event that
the SO_NOSIGPIPE option is not set.
Notes:
- The are upsides and downsides to placing this logic in the socket
layer as opposed to the file descriptor layer. This is really fd
layer logic, but because we need so_options, we have a choice of
layering violations and pick this one.
- SIGPIPE possibly should be delivered to the thread performing the
write, not the process performing the write.
- uio->uio_td and the td argument to soo_write() might potentially
differ; we use the thread in the uio argument.
- The "sigpipe" regression test in src/tools/regression/sockets/sigpipe
tests for the bug.
Submitted by: Mikko Tyolajarvi <mbsd at pacbell dot net>
Talked with: glebius, alfred
PR: 78478
MFC after: 1 week
2005-03-11 15:06:16 +00:00
|
|
|
#include <sys/proc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/protosw.h>
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/sigio.h>
|
The SO_NOSIGPIPE socket option allows a user process to mark a socket
so that the socket does not generate SIGPIPE, only EPIPE, when a write
is attempted after socket shutdown. When the option was introduced in
2002, this required the logic for determining whether SIGPIPE was
generated to be pushed down from dofilewrite() to the socket layer so
that the socket options could be considered. However, the change in
2002 omitted modification to soo_write() required to add that logic,
resulting in SIGPIPE not being generated even without SO_NOSIGPIPE when
the socket was written to using write() or related generic system calls.
This change adds the EPIPE logic to soo_write(), generating a SIGPIPE
signal to the process associated with the passed uio in the event that
the SO_NOSIGPIPE option is not set.
Notes:
- The are upsides and downsides to placing this logic in the socket
layer as opposed to the file descriptor layer. This is really fd
layer logic, but because we need so_options, we have a choice of
layering violations and pick this one.
- SIGPIPE possibly should be delivered to the thread performing the
write, not the process performing the write.
- uio->uio_td and the td argument to soo_write() might potentially
differ; we use the thread in the uio argument.
- The "sigpipe" regression test in src/tools/regression/sockets/sigpipe
tests for the bug.
Submitted by: Mikko Tyolajarvi <mbsd at pacbell dot net>
Talked with: glebius, alfred
PR: 78478
MFC after: 1 week
2005-03-11 15:06:16 +00:00
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1997-03-24 11:52:29 +00:00
|
|
|
#include <sys/filio.h> /* XXX */
|
|
|
|
#include <sys/sockio.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/stat.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
#include <sys/uio.h>
|
2000-05-11 22:08:57 +00:00
|
|
|
#include <sys/ucred.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
2007-03-04 17:50:46 +00:00
|
|
|
struct fileops socketops = {
|
2003-06-18 18:16:40 +00:00
|
|
|
.fo_read = soo_read,
|
|
|
|
.fo_write = soo_write,
|
|
|
|
.fo_ioctl = soo_ioctl,
|
|
|
|
.fo_poll = soo_poll,
|
|
|
|
.fo_kqfilter = soo_kqfilter,
|
|
|
|
.fo_stat = soo_stat,
|
|
|
|
.fo_close = soo_close,
|
|
|
|
.fo_flags = DFLAG_PASSABLE
|
2001-02-15 16:34:11 +00:00
|
|
|
};
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-01-30 06:25:00 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
|
|
|
|
int flags, struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-01-13 00:33:17 +00:00
|
|
|
struct socket *so = fp->f_data;
|
2002-03-15 08:03:46 +00:00
|
|
|
int error;
|
|
|
|
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_LOCK_GIANT();
|
2002-10-06 14:39:15 +00:00
|
|
|
#ifdef MAC
|
2004-06-13 02:50:07 +00:00
|
|
|
SOCK_LOCK(so);
|
2002-10-06 14:39:15 +00:00
|
|
|
error = mac_check_socket_receive(active_cred, so);
|
2004-06-13 02:50:07 +00:00
|
|
|
SOCK_UNLOCK(so);
|
2002-10-06 14:39:15 +00:00
|
|
|
if (error) {
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2002-10-06 14:39:15 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
soreceive_generic(), and sopoll_generic(). Add new functions sosend(),
soreceive(), and sopoll(), which are wrappers for pru_sosend,
pru_soreceive, and pru_sopoll, and are now used univerally by socket
consumers rather than either directly invoking the old so*() functions
or directly invoking the protocol switch method (about an even split
prior to this commit).
This completes an architectural change that was begun in 1996 to permit
protocols to provide substitute implementations, as now used by UDP.
Consumers now uniformly invoke sosend(), soreceive(), and sopoll() to
perform these operations on sockets -- in particular, distributed file
systems and socket system calls.
Architectural head nod: sam, gnn, wollman
2006-07-24 15:20:08 +00:00
|
|
|
error = soreceive(so, 0, uio, 0, 0, 0);
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2002-03-15 08:03:46 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-01-30 06:25:00 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
|
|
|
|
int flags, struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-01-13 00:33:17 +00:00
|
|
|
struct socket *so = fp->f_data;
|
2002-03-15 08:03:46 +00:00
|
|
|
int error;
|
|
|
|
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_LOCK_GIANT();
|
2002-10-06 14:39:15 +00:00
|
|
|
#ifdef MAC
|
2004-06-13 02:50:07 +00:00
|
|
|
SOCK_LOCK(so);
|
2002-10-06 14:39:15 +00:00
|
|
|
error = mac_check_socket_send(active_cred, so);
|
2004-06-13 02:50:07 +00:00
|
|
|
SOCK_UNLOCK(so);
|
2002-10-06 14:39:15 +00:00
|
|
|
if (error) {
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2002-10-06 14:39:15 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
soreceive_generic(), and sopoll_generic(). Add new functions sosend(),
soreceive(), and sopoll(), which are wrappers for pru_sosend,
pru_soreceive, and pru_sopoll, and are now used univerally by socket
consumers rather than either directly invoking the old so*() functions
or directly invoking the protocol switch method (about an even split
prior to this commit).
This completes an architectural change that was begun in 1996 to permit
protocols to provide substitute implementations, as now used by UDP.
Consumers now uniformly invoke sosend(), soreceive(), and sopoll() to
perform these operations on sockets -- in particular, distributed file
systems and socket system calls.
Architectural head nod: sam, gnn, wollman
2006-07-24 15:20:08 +00:00
|
|
|
error = sosend(so, 0, uio, 0, 0, 0, uio->uio_td);
|
The SO_NOSIGPIPE socket option allows a user process to mark a socket
so that the socket does not generate SIGPIPE, only EPIPE, when a write
is attempted after socket shutdown. When the option was introduced in
2002, this required the logic for determining whether SIGPIPE was
generated to be pushed down from dofilewrite() to the socket layer so
that the socket options could be considered. However, the change in
2002 omitted modification to soo_write() required to add that logic,
resulting in SIGPIPE not being generated even without SO_NOSIGPIPE when
the socket was written to using write() or related generic system calls.
This change adds the EPIPE logic to soo_write(), generating a SIGPIPE
signal to the process associated with the passed uio in the event that
the SO_NOSIGPIPE option is not set.
Notes:
- The are upsides and downsides to placing this logic in the socket
layer as opposed to the file descriptor layer. This is really fd
layer logic, but because we need so_options, we have a choice of
layering violations and pick this one.
- SIGPIPE possibly should be delivered to the thread performing the
write, not the process performing the write.
- uio->uio_td and the td argument to soo_write() might potentially
differ; we use the thread in the uio argument.
- The "sigpipe" regression test in src/tools/regression/sockets/sigpipe
tests for the bug.
Submitted by: Mikko Tyolajarvi <mbsd at pacbell dot net>
Talked with: glebius, alfred
PR: 78478
MFC after: 1 week
2005-03-11 15:06:16 +00:00
|
|
|
if (error == EPIPE && (so->so_options & SO_NOSIGPIPE) == 0) {
|
|
|
|
PROC_LOCK(uio->uio_td->td_proc);
|
|
|
|
psignal(uio->uio_td->td_proc, SIGPIPE);
|
|
|
|
PROC_UNLOCK(uio->uio_td->td_proc);
|
|
|
|
}
|
2004-03-29 01:55:32 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2002-03-15 08:03:46 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
|
|
|
struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2004-11-13 17:21:26 +00:00
|
|
|
struct socket *so = fp->f_data;
|
|
|
|
int error = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2004-11-17 09:09:55 +00:00
|
|
|
NET_LOCK_GIANT();
|
1994-05-24 10:09:53 +00:00
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case FIONBIO:
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_LOCK(so);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (*(int *)data)
|
|
|
|
so->so_state |= SS_NBIO;
|
|
|
|
else
|
|
|
|
so->so_state &= ~SS_NBIO;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_UNLOCK(so);
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
case FIOASYNC:
|
2004-06-17 22:48:11 +00:00
|
|
|
/*
|
2007-03-04 17:50:46 +00:00
|
|
|
* 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.
|
2004-06-17 22:48:11 +00:00
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
if (*(int *)data) {
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_LOCK(so);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_state |= SS_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_rcv.sb_flags |= SB_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
SOCKBUF_LOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_snd.sb_flags |= SB_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
} else {
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_LOCK(so);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_state &= ~SS_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_rcv.sb_flags &= ~SB_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
SOCKBUF_LOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_snd.sb_flags &= ~SB_ASYNC;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
case FIONREAD:
|
2004-06-20 17:35:50 +00:00
|
|
|
/* Unlocked read. */
|
1994-05-24 10:09:53 +00:00
|
|
|
*(int *)data = so->so_rcv.sb_cc;
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Installed the second patch attached to kern/7899 with some changes suggested
by bde, a few other tweaks to get the patch to apply cleanly again and
some improvements to the comments.
This change closes some fairly minor security holes associated with
F_SETOWN, fixes a few bugs, and removes some limitations that F_SETOWN
had on tty devices. For more details, see the description on the PR.
Because this patch increases the size of the proc and pgrp structures,
it is necessary to re-install the includes and recompile libkvm,
the vinum lkm, fstat, gcore, gdb, ipfilter, ps, top, and w.
PR: kern/7899
Reviewed by: bde, elvind
1998-11-11 10:04:13 +00:00
|
|
|
case FIOSETOWN:
|
2004-11-13 17:21:26 +00:00
|
|
|
error = fsetown(*(int *)data, &so->so_sigio);
|
|
|
|
break;
|
Installed the second patch attached to kern/7899 with some changes suggested
by bde, a few other tweaks to get the patch to apply cleanly again and
some improvements to the comments.
This change closes some fairly minor security holes associated with
F_SETOWN, fixes a few bugs, and removes some limitations that F_SETOWN
had on tty devices. For more details, see the description on the PR.
Because this patch increases the size of the proc and pgrp structures,
it is necessary to re-install the includes and recompile libkvm,
the vinum lkm, fstat, gcore, gdb, ipfilter, ps, top, and w.
PR: kern/7899
Reviewed by: bde, elvind
1998-11-11 10:04:13 +00:00
|
|
|
|
|
|
|
case FIOGETOWN:
|
2002-10-03 02:13:00 +00:00
|
|
|
*(int *)data = fgetown(&so->so_sigio);
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Installed the second patch attached to kern/7899 with some changes suggested
by bde, a few other tweaks to get the patch to apply cleanly again and
some improvements to the comments.
This change closes some fairly minor security holes associated with
F_SETOWN, fixes a few bugs, and removes some limitations that F_SETOWN
had on tty devices. For more details, see the description on the PR.
Because this patch increases the size of the proc and pgrp structures,
it is necessary to re-install the includes and recompile libkvm,
the vinum lkm, fstat, gcore, gdb, ipfilter, ps, top, and w.
PR: kern/7899
Reviewed by: bde, elvind
1998-11-11 10:04:13 +00:00
|
|
|
case SIOCSPGRP:
|
2004-11-13 17:21:26 +00:00
|
|
|
error = fsetown(-(*(int *)data), &so->so_sigio);
|
|
|
|
break;
|
Installed the second patch attached to kern/7899 with some changes suggested
by bde, a few other tweaks to get the patch to apply cleanly again and
some improvements to the comments.
This change closes some fairly minor security holes associated with
F_SETOWN, fixes a few bugs, and removes some limitations that F_SETOWN
had on tty devices. For more details, see the description on the PR.
Because this patch increases the size of the proc and pgrp structures,
it is necessary to re-install the includes and recompile libkvm,
the vinum lkm, fstat, gcore, gdb, ipfilter, ps, top, and w.
PR: kern/7899
Reviewed by: bde, elvind
1998-11-11 10:04:13 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
case SIOCGPGRP:
|
2002-10-03 02:13:00 +00:00
|
|
|
*(int *)data = -fgetown(&so->so_sigio);
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
case SIOCATMARK:
|
2004-06-20 17:35:50 +00:00
|
|
|
/* Unlocked read. */
|
2004-06-14 18:16:22 +00:00
|
|
|
*(int *)data = (so->so_rcv.sb_state & SBS_RCVATMARK) != 0;
|
2004-11-13 17:21:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
2007-03-04 17:50:46 +00:00
|
|
|
* Interface/routing/protocol specific ioctls: interface and
|
|
|
|
* routing ioctls should have a different entry since a
|
|
|
|
* socket is unnecessary.
|
2004-11-13 17:21:26 +00:00
|
|
|
*/
|
|
|
|
if (IOCGROUP(cmd) == 'i')
|
|
|
|
error = ifioctl(so, cmd, data, td);
|
|
|
|
else if (IOCGROUP(cmd) == 'r')
|
|
|
|
error = rtioctl(cmd, data);
|
|
|
|
else
|
|
|
|
error = ((*so->so_proto->pr_usrreqs->pru_control)
|
|
|
|
(so, cmd, data, 0, td));
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2004-11-17 09:09:55 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2004-11-13 17:21:26 +00:00
|
|
|
return(error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_poll(struct file *fp, int events, struct ucred *active_cred,
|
|
|
|
struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-01-13 00:33:17 +00:00
|
|
|
struct socket *so = fp->f_data;
|
2004-11-13 17:21:26 +00:00
|
|
|
int error;
|
|
|
|
|
2004-11-17 08:01:10 +00:00
|
|
|
NET_LOCK_GIANT();
|
2005-04-16 18:46:29 +00:00
|
|
|
#ifdef MAC
|
|
|
|
SOCK_LOCK(so);
|
|
|
|
error = mac_check_socket_poll(active_cred, so);
|
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
if (error) {
|
|
|
|
NET_UNLOCK_GIANT();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
soreceive_generic(), and sopoll_generic(). Add new functions sosend(),
soreceive(), and sopoll(), which are wrappers for pru_sosend,
pru_soreceive, and pru_sopoll, and are now used univerally by socket
consumers rather than either directly invoking the old so*() functions
or directly invoking the protocol switch method (about an even split
prior to this commit).
This completes an architectural change that was begun in 1996 to permit
protocols to provide substitute implementations, as now used by UDP.
Consumers now uniformly invoke sosend(), soreceive(), and sopoll() to
perform these operations on sockets -- in particular, distributed file
systems and socket system calls.
Architectural head nod: sam, gnn, wollman
2006-07-24 15:20:08 +00:00
|
|
|
error = sopoll(so, events, fp->f_cred, td);
|
2004-11-17 08:01:10 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2004-11-13 17:21:26 +00:00
|
|
|
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
|
|
|
|
struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-01-13 00:33:17 +00:00
|
|
|
struct socket *so = fp->f_data;
|
2004-07-22 20:40:23 +00:00
|
|
|
int error;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
bzero((caddr_t)ub, sizeof (*ub));
|
2000-07-02 23:56:45 +00:00
|
|
|
ub->st_mode = S_IFSOCK;
|
2004-07-22 20:40:23 +00:00
|
|
|
NET_LOCK_GIANT();
|
2005-04-16 18:46:29 +00:00
|
|
|
#ifdef MAC
|
|
|
|
SOCK_LOCK(so);
|
|
|
|
error = mac_check_socket_stat(active_cred, so);
|
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
if (error) {
|
|
|
|
NET_UNLOCK_GIANT();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
2000-07-02 23:56:45 +00:00
|
|
|
/*
|
2004-06-14 18:16:22 +00:00
|
|
|
* If SBS_CANTRCVMORE is set, but there's still data left in the
|
2000-07-02 23:56:45 +00:00
|
|
|
* receive buffer, the socket is still readable.
|
2004-06-20 17:35:50 +00:00
|
|
|
*
|
2007-03-04 17:50:46 +00:00
|
|
|
* XXXRW: perhaps should lock socket buffer so st_size result is
|
|
|
|
* consistent.
|
2000-07-02 23:56:45 +00:00
|
|
|
*/
|
2004-06-20 17:35:50 +00:00
|
|
|
/* Unlocked read. */
|
2004-06-14 18:16:22 +00:00
|
|
|
if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) == 0 ||
|
2000-07-02 23:56:45 +00:00
|
|
|
so->so_rcv.sb_cc != 0)
|
|
|
|
ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
|
2004-06-14 18:16:22 +00:00
|
|
|
if ((so->so_snd.sb_state & SBS_CANTSENDMORE) == 0)
|
2000-07-02 23:56:45 +00:00
|
|
|
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
|
2002-11-01 21:31:13 +00:00
|
|
|
ub->st_size = so->so_rcv.sb_cc - so->so_rcv.sb_ctl;
|
2000-05-11 22:08:57 +00:00
|
|
|
ub->st_uid = so->so_cred->cr_uid;
|
|
|
|
ub->st_gid = so->so_cred->cr_gid;
|
2004-07-22 20:40:23 +00:00
|
|
|
error = (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
|
|
|
|
NET_UNLOCK_GIANT();
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2001-11-17 03:07:11 +00:00
|
|
|
/*
|
2007-03-04 17:50:46 +00:00
|
|
|
* 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.
|
2001-11-17 03:07:11 +00:00
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
/* ARGSUSED */
|
1999-01-30 06:25:00 +00:00
|
|
|
int
|
2007-03-04 17:50:46 +00:00
|
|
|
soo_close(struct file *fp, struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
2001-11-17 03:07:11 +00:00
|
|
|
struct socket *so;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2004-07-22 18:35:43 +00:00
|
|
|
NET_LOCK_GIANT();
|
2003-01-13 00:33:17 +00:00
|
|
|
so = fp->f_data;
|
1999-08-04 18:53:50 +00:00
|
|
|
fp->f_ops = &badfileops;
|
2003-01-13 00:33:17 +00:00
|
|
|
fp->f_data = NULL;
|
2002-01-13 11:58:06 +00:00
|
|
|
|
|
|
|
if (so)
|
2001-11-17 03:07:11 +00:00
|
|
|
error = soclose(so);
|
2004-07-22 18:35:43 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
}
|