X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/97a33c788e2b7b2a1bdb3c64a1c876e3dc6c34c2..b44419cb4460c6e8d4e16a260372e9965b77eecf:/sys/kern/uipc_socket2.c diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index e77388074f..f6525a95f6 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -32,7 +32,7 @@ * * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/uipc_socket2.c,v 1.55.2.17 2002/08/31 19:04:55 dwmalone Exp $ - * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.6 2003/08/28 01:48:18 hmp Exp $ + * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.10 2004/04/20 01:52:22 dillon Exp $ */ #include "opt_param.h" @@ -54,6 +54,9 @@ #include /* for aio_swake proto */ #include +#include +#include + int maxsockets; /* @@ -174,6 +177,7 @@ struct socket * sonewconn(struct socket *head, int connstatus) { struct socket *so; + struct pru_attach_info ai; if (head->so_qlen > 3 * head->so_qlimit / 2) return ((struct socket *)0); @@ -190,8 +194,12 @@ sonewconn(struct socket *head, int connstatus) so->so_proto = head->so_proto; so->so_timeo = head->so_timeo; so->so_cred = crhold(head->so_cred); - if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat) || - (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { + ai.sb_rlimit = NULL; + ai.p_ucred = NULL; + ai.fd_rdir = NULL; /* jail code cruft XXX JH */ + if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat, NULL) || + /* Directly call function since we're already at protocol level. */ + (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, &ai)) { sodealloc(so); return ((struct socket *)0); } @@ -284,16 +292,17 @@ sb_lock(sb) } /* - * Wakeup processes waiting on a socket buffer. - * Do asynchronous notification via SIGIO - * if the socket has the SS_ASYNC flag set. + * Wakeup processes waiting on a socket buffer. Do asynchronous notification + * via SIGIO if the socket has the SS_ASYNC flag set. */ void sowakeup(so, sb) struct socket *so; struct sockbuf *sb; { - selwakeup(&sb->sb_sel); + struct selinfo *selinfo = &sb->sb_sel; + + selwakeup(selinfo); sb->sb_flags &= ~SB_SEL; if (sb->sb_flags & SB_WAIT) { sb->sb_flags &= ~SB_WAIT; @@ -305,7 +314,20 @@ sowakeup(so, sb) (*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT); if (sb->sb_flags & SB_AIO) aio_swake(so, sb); - KNOTE(&sb->sb_sel.si_note, 0); + KNOTE(&selinfo->si_note, 0); + if (sb->sb_flags & SB_MEVENT) { + struct netmsg_so_notify *msg, *nmsg; + + TAILQ_FOREACH_MUTABLE(msg, &selinfo->si_mlist, nm_list, nmsg) { + if (msg->nm_predicate((struct netmsg *)msg)) { + TAILQ_REMOVE(&selinfo->si_mlist, msg, nm_list); + lwkt_replymsg(&msg->nm_lmsg, + msg->nm_lmsg.ms_error); + } + } + if (TAILQ_EMPTY(&sb->sb_sel.si_mlist)) + sb->sb_flags &= ~SB_MEVENT; + } } /* @@ -341,15 +363,11 @@ sowakeup(so, sb) */ int -soreserve(so, sndcc, rcvcc) - struct socket *so; - u_long sndcc, rcvcc; +soreserve(struct socket *so, u_long sndcc, u_long rcvcc, struct rlimit *rl) { - struct proc *p = curproc; - - if (sbreserve(&so->so_snd, sndcc, so, p) == 0) + if (sbreserve(&so->so_snd, sndcc, so, rl) == 0) goto bad; - if (sbreserve(&so->so_rcv, rcvcc, so, p) == 0) + if (sbreserve(&so->so_rcv, rcvcc, so, rl) == 0) goto bad2; if (so->so_rcv.sb_lowat == 0) so->so_rcv.sb_lowat = 1; @@ -390,21 +408,17 @@ sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) * if buffering efficiency is near the normal case. */ int -sbreserve(sb, cc, so, p) - struct sockbuf *sb; - u_long cc; - struct socket *so; - struct proc *p; +sbreserve(struct sockbuf *sb, u_long cc, struct socket *so, struct rlimit *rl) { /* - * p will only be NULL when we're in an interrupt - * (e.g. in tcp_input()) + * rl will only be NULL when we're in an interrupt (eg, in tcp_input) + * or when called from netgraph (ie, ngd_attach) */ if (cc > sb_max_adj) return (0); if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, - p ? p->p_rlimit[RLIMIT_SBSIZE].rlim_cur : RLIM_INFINITY)) { + rl ? rl->rlim_cur : RLIM_INFINITY)) { return (0); } sb->sb_mbmax = min(cc * sb_efficiency, sb_max);