32 #include <sys/cdefs.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/filedesc.h>
40 #include <sys/protosw.h>
41 #include <sys/sigio.h>
42 #include <sys/signal.h>
43 #include <sys/signalvar.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <sys/filio.h>
47 #include <sys/sockio.h>
50 #include <sys/ucred.h>
53 #include <net/route.h>
56 #include <security/mac/mac_framework.h>
69 .fo_flags = DFLAG_PASSABLE
74 soo_read(
struct file *fp,
struct uio *uio,
struct ucred *active_cred,
75 int flags,
struct thread *td)
77 struct socket *so = fp->f_data;
81 error = mac_socket_check_receive(active_cred, so);
91 soo_write(
struct file *fp,
struct uio *uio,
struct ucred *active_cred,
92 int flags,
struct thread *td)
94 struct socket *so = fp->f_data;
98 error = mac_socket_check_send(active_cred, so);
102 error =
sosend(so, 0, uio, 0, 0, 0, uio->uio_td);
103 if (error == EPIPE && (so->so_options & SO_NOSIGPIPE) == 0) {
104 PROC_LOCK(uio->uio_td->td_proc);
106 PROC_UNLOCK(uio->uio_td->td_proc);
120 soo_ioctl(
struct file *fp, u_long cmd,
void *data,
struct ucred *active_cred,
123 struct socket *so = fp->f_data;
130 so->so_state |= SS_NBIO;
132 so->so_state &= ~SS_NBIO;
145 so->so_state |= SS_ASYNC;
147 SOCKBUF_LOCK(&so->so_rcv);
148 so->so_rcv.sb_flags |= SB_ASYNC;
149 SOCKBUF_UNLOCK(&so->so_rcv);
150 SOCKBUF_LOCK(&so->so_snd);
151 so->so_snd.sb_flags |= SB_ASYNC;
152 SOCKBUF_UNLOCK(&so->so_snd);
155 so->so_state &= ~SS_ASYNC;
157 SOCKBUF_LOCK(&so->so_rcv);
158 so->so_rcv.sb_flags &= ~SB_ASYNC;
159 SOCKBUF_UNLOCK(&so->so_rcv);
160 SOCKBUF_LOCK(&so->so_snd);
161 so->so_snd.sb_flags &= ~SB_ASYNC;
162 SOCKBUF_UNLOCK(&so->so_snd);
168 *(
int *)data = so->so_rcv.sb_cc;
173 *(
int *)data = so->so_snd.sb_cc;
177 if ((so->so_snd.sb_hiwat < so->so_snd.sb_cc) ||
178 (so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt))
181 *(
int *)data = sbspace(&so->so_snd);
185 error =
fsetown(*(
int *)data, &so->so_sigio);
189 *(
int *)data =
fgetown(&so->so_sigio);
193 error =
fsetown(-(*(
int *)data), &so->so_sigio);
197 *(
int *)data = -
fgetown(&so->so_sigio);
202 *(
int *)data = (so->so_rcv.sb_state & SBS_RCVATMARK) != 0;
210 if (IOCGROUP(cmd) ==
'i')
211 error = ifioctl(so, cmd, data, td);
212 else if (IOCGROUP(cmd) ==
'r') {
213 CURVNET_SET(so->so_vnet);
214 error = rtioctl_fib(cmd, data, so->so_fibnum);
217 CURVNET_SET(so->so_vnet);
218 error = ((*so->so_proto->pr_usrreqs->pru_control)
219 (so, cmd, data, 0, td));
228 soo_poll(
struct file *fp,
int events,
struct ucred *active_cred,
231 struct socket *so = fp->f_data;
235 error = mac_socket_check_poll(active_cred, so);
239 return (
sopoll(so, events, fp->f_cred, td));
243 soo_stat(
struct file *fp,
struct stat *ub,
struct ucred *active_cred,
246 struct socket *so = fp->f_data;
251 bzero((caddr_t)ub,
sizeof (*ub));
252 ub->st_mode = S_IFSOCK;
254 error = mac_socket_check_stat(active_cred, so);
262 SOCKBUF_LOCK(&so->so_rcv);
263 if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) == 0 ||
264 so->so_rcv.sb_cc != 0)
265 ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
266 ub->st_size = so->so_rcv.sb_cc - so->so_rcv.sb_ctl;
267 SOCKBUF_UNLOCK(&so->so_rcv);
269 if ((so->so_snd.sb_state & SBS_CANTSENDMORE) == 0)
270 ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
271 ub->st_uid = so->so_cred->cr_uid;
272 ub->st_gid = so->so_cred->cr_gid;
273 return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
pid_t fgetown(struct sigio **sigiop)
int fsetown(pid_t pgid, struct sigio **sigiop)
int soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
int soo_kqfilter(struct file *fp, struct knote *kn)
int invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
int soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred, struct thread *td)
int soo_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
int invfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
int soo_close(struct file *fp, struct thread *td)
int soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred, struct thread *td)
int sopoll(struct socket *so, int events, struct ucred *active_cred, struct thread *td)
void tdsignal(struct thread *td, int sig)
int soo_poll(struct file *fp, int events, struct ucred *active_cred, struct thread *td)
int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
int soclose(struct socket *so)
int soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
int soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
struct fileops badfileops