Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v retrieving revision 1.135.2.1 retrieving revision 1.136 diff -u -p -r1.135.2.1 -r1.136 --- src/sys/kern/uipc_socket.c 2007/07/11 20:10:18 1.135.2.1 +++ src/sys/kern/uipc_socket.c 2007/03/12 21:33:08 1.136 @@ -1,7 +1,7 @@ -/* $NetBSD: uipc_socket.c,v 1.135.2.1 2007/07/11 20:10:18 mjf Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.136 2007/03/12 21:33:08 ad Exp $ */ /*- - * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. + * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.135.2.1 2007/07/11 20:10:18 mjf Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.136 2007/03/12 21:33:08 ad Exp $"); #include "opt_sock_counters.h" #include "opt_sosend_loan.h" @@ -298,14 +298,17 @@ sodopendfree() static size_t sodopendfreel() { - struct mbuf *m, *next; size_t rv = 0; - int s; KASSERT(mutex_owned(&so_pendfree_lock)); - while (so_pendfree != NULL) { + for (;;) { + struct mbuf *m; + struct mbuf *next; + m = so_pendfree; + if (m == NULL) + break; so_pendfree = NULL; mutex_exit(&so_pendfree_lock); @@ -316,9 +319,7 @@ sodopendfreel() sodoloanfree((m->m_flags & M_EXT_PAGES) ? m->m_ext.ext_pgs : NULL, m->m_ext.ext_buf, m->m_ext.ext_size); - s = splvm(); pool_cache_put(&mbpool_cache, m); - splx(s); } mutex_enter(&so_pendfree_lock); @@ -461,29 +462,29 @@ socreate(int dom, struct socket **aso, i error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type), KAUTH_ARG(proto)); - if (error != 0) - return error; + if (error) + return (error); if (proto) prp = pffindproto(dom, proto, type); else prp = pffindtype(dom, type); - if (prp == NULL) { + if (prp == 0) { /* no support for domain */ if (pffinddomain(dom) == 0) - return EAFNOSUPPORT; + return (EAFNOSUPPORT); /* no support for socket type */ if (proto == 0 && type != 0) - return EPROTOTYPE; - return EPROTONOSUPPORT; + return (EPROTOTYPE); + return (EPROTONOSUPPORT); } - if (prp->pr_usrreq == NULL) - return EPROTONOSUPPORT; + if (prp->pr_usrreq == 0) + return (EPROTONOSUPPORT); if (prp->pr_type != type) - return EPROTOTYPE; + return (EPROTOTYPE); s = splsoftnet(); so = pool_get(&socket_pool, PR_WAITOK); - memset(so, 0, sizeof(*so)); + memset((void *)so, 0, sizeof(*so)); TAILQ_INIT(&so->so_q0); TAILQ_INIT(&so->so_q); so->so_type = type; @@ -495,19 +496,23 @@ socreate(int dom, struct socket **aso, i so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; so->so_mowner = &prp->pr_domain->dom_mowner; #endif - uid = kauth_cred_geteuid(l->l_cred); + if (l != NULL) { + uid = kauth_cred_geteuid(l->l_cred); + } else { + uid = 0; + } so->so_uidinfo = uid_find(uid); - error = (*prp->pr_usrreq)(so, PRU_ATTACH, NULL, - (struct mbuf *)(long)proto, NULL, l); - if (error != 0) { + error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, + (struct mbuf *)(long)proto, (struct mbuf *)0, l); + if (error) { so->so_state |= SS_NOFDREF; sofree(so); splx(s); - return error; + return (error); } splx(s); *aso = so; - return 0; + return (0); } int @@ -516,9 +521,10 @@ sobind(struct socket *so, struct mbuf *n int s, error; s = splsoftnet(); - error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, NULL, nam, NULL, l); + error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0, + nam, (struct mbuf *)0, l); splx(s); - return error; + return (error); } int @@ -527,11 +533,11 @@ solisten(struct socket *so, int backlog) int s, error; s = splsoftnet(); - error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, NULL, - NULL, NULL, NULL); - if (error != 0) { + error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0, + (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); + if (error) { splx(s); - return error; + return (error); } if (TAILQ_EMPTY(&so->so_q)) so->so_options |= SO_ACCEPTCONN; @@ -539,7 +545,7 @@ solisten(struct socket *so, int backlog) backlog = 0; so->so_qlimit = min(backlog, somaxconn); splx(s); - return 0; + return (0); } void @@ -615,7 +621,8 @@ soclose(struct socket *so) drop: if (so->so_pcb) { int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, - NULL, NULL, NULL, NULL); + (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, + (struct lwp *)0); if (error == 0) error = error2; } @@ -634,15 +641,9 @@ soclose(struct socket *so) int soabort(struct socket *so) { - int error; - KASSERT(so->so_head == NULL); - error = (*so->so_proto->pr_usrreq)(so, PRU_ABORT, NULL, - NULL, NULL, NULL); - if (error) { - sofree(so); - } - return error; + return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0, + (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); } int @@ -658,7 +659,7 @@ soaccept(struct socket *so, struct mbuf if ((so->so_state & SS_ISDISCONNECTED) == 0 || (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0) error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, - NULL, nam, NULL, NULL); + (struct mbuf *)0, nam, (struct mbuf *)0, (struct lwp *)0); else error = ECONNABORTED; @@ -686,7 +687,7 @@ soconnect(struct socket *so, struct mbuf error = EISCONN; else error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, - NULL, nam, NULL, l); + (struct mbuf *)0, nam, (struct mbuf *)0, l); splx(s); return (error); } @@ -698,7 +699,8 @@ soconnect2(struct socket *so1, struct so s = splsoftnet(); error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, - NULL, (struct mbuf *)so2, NULL, NULL); + (struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0, + (struct lwp *)0); splx(s); return (error); } @@ -718,7 +720,8 @@ sodisconnect(struct socket *so) goto bad; } error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, - NULL, NULL, NULL, NULL); + (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, + (struct lwp *)0); bad: splx(s); sodopendfree(); @@ -835,7 +838,7 @@ sosend(struct socket *so, struct mbuf *a m = m_gethdr(M_WAIT, MT_DATA); mlen = MHLEN; m->m_pkthdr.len = 0; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif = (struct ifnet *)0; } else { m = m_get(M_WAIT, MT_DATA); mlen = MLEN; @@ -976,7 +979,8 @@ soreceive(struct socket *so, struct mbuf if (flags & MSG_OOB) { m = m_get(M_WAIT, MT_DATA); error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, - (struct mbuf *)(long)(flags & MSG_PEEK), NULL, l); + (struct mbuf *)(long)(flags & MSG_PEEK), + (struct mbuf *)0, l); if (error) goto bad; do { @@ -990,9 +994,10 @@ soreceive(struct socket *so, struct mbuf return (error); } if (mp) - *mp = NULL; + *mp = (struct mbuf *)0; if (so->so_state & SS_ISCONFIRMING && uio->uio_resid) - (*pr->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL, l); + (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, + (struct mbuf *)0, (struct mbuf *)0, l); restart: if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) @@ -1228,7 +1233,7 @@ soreceive(struct socket *so, struct mbuf *mp = m; mp = &m->m_next; so->so_rcv.sb_mb = m = m->m_next; - *mp = NULL; + *mp = (struct mbuf *)0; } else { MFREE(m, so->so_rcv.sb_mb); m = so->so_rcv.sb_mb; @@ -1299,7 +1304,9 @@ soreceive(struct socket *so, struct mbuf */ if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) (*pr->pr_usrreq)(so, PRU_RCVD, - NULL, (struct mbuf *)(long)flags, NULL, l); + (struct mbuf *)0, + (struct mbuf *)(long)flags, + (struct mbuf *)0, l); SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); error = sbwait(&so->so_rcv); @@ -1335,8 +1342,8 @@ soreceive(struct socket *so, struct mbuf SBLASTRECORDCHK(&so->so_rcv, "soreceive 4"); SBLASTMBUFCHK(&so->so_rcv, "soreceive 4"); if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) - (*pr->pr_usrreq)(so, PRU_RCVD, NULL, - (struct mbuf *)(long)flags, NULL, l); + (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, + (struct mbuf *)(long)flags, (struct mbuf *)0, l); } if (orig_resid == uio->uio_resid && orig_resid && (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) { @@ -1365,8 +1372,8 @@ soshutdown(struct socket *so, int how) if (how == SHUT_RD || how == SHUT_RDWR) sorflush(so); if (how == SHUT_WR || how == SHUT_RDWR) - return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, - NULL, NULL, NULL); + return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0, + (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); return (0); }