Module Name: src Committed By: maxv Date: Thu Mar 7 12:22:43 UTC 2019
Modified Files: src/sys/kern: uipc_socket.c Log Message: style To generate a diff of this commit: cvs rdiff -u -r1.269 -r1.270 src/sys/kern/uipc_socket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/uipc_socket.c diff -u src/sys/kern/uipc_socket.c:1.269 src/sys/kern/uipc_socket.c:1.270 --- src/sys/kern/uipc_socket.c:1.269 Mon Feb 4 04:18:27 2019 +++ src/sys/kern/uipc_socket.c Thu Mar 7 12:22:43 2019 @@ -1,6 +1,6 @@ -/* $NetBSD: uipc_socket.c,v 1.269 2019/02/04 04:18:27 mrg Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.270 2019/03/07 12:22:43 maxv Exp $ */ -/*- +/* * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. * All rights reserved. * @@ -71,7 +71,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.269 2019/02/04 04:18:27 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.270 2019/03/07 12:22:43 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -206,28 +206,19 @@ sokvaunreserve(vsize_t len) /* * sokvaalloc: allocate kva for loan. */ - vaddr_t sokvaalloc(vaddr_t sva, vsize_t len, struct socket *so) { vaddr_t lva; - /* - * reserve kva. - */ - if (sokvareserve(so, len) == 0) return 0; - /* - * allocate kva. - */ - lva = uvm_km_alloc(kernel_map, len, atop(sva) & uvmexp.colormask, UVM_KMF_COLORMATCH | UVM_KMF_VAONLY | UVM_KMF_WAITVA); if (lva == 0) { sokvaunreserve(len); - return (0); + return 0; } return lva; @@ -236,21 +227,11 @@ sokvaalloc(vaddr_t sva, vsize_t len, str /* * sokvafree: free kva for loan. */ - void sokvafree(vaddr_t sva, vsize_t len) { - /* - * free kva. - */ - uvm_km_free(kernel_map, sva, len, UVM_KMF_VAONLY); - - /* - * unreserve kva. - */ - sokvaunreserve(len); } @@ -275,10 +256,9 @@ sodoloanfree(struct vm_page **pgs, void } /* - * sopendfree_thread: free mbufs on "pendfree" list. - * unlock and relock so_pendfree_lock when freeing mbufs. + * sopendfree_thread: free mbufs on "pendfree" list. Unlock and relock + * so_pendfree_lock when freeing mbufs. */ - static void sopendfree_thread(void *v) { @@ -348,7 +328,7 @@ sosend_loan(struct socket *so, struct ui int i; if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace)) - return (0); + return 0; if (iov->iov_len < (size_t) space) space = iov->iov_len; @@ -370,7 +350,7 @@ sosend_loan(struct socket *so, struct ui m->m_ext.ext_pgs, UVM_LOAN_TOPAGE); if (error) { sokvafree(lva, len); - return (0); + return 0; } for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE) @@ -392,7 +372,7 @@ sosend_loan(struct socket *so, struct ui uio->uio_iovcnt--; } - return (space); + return space; } struct mbuf * @@ -501,13 +481,13 @@ soinit1(void) */ int socreate(int dom, struct socket **aso, int type, int proto, struct lwp *l, - struct socket *lockso) + struct socket *lockso) { - const struct protosw *prp; - struct socket *so; - uid_t uid; - int error; - kmutex_t *lock; + const struct protosw *prp; + struct socket *so; + uid_t uid; + int error; + kmutex_t *lock; error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type), @@ -635,7 +615,7 @@ sofamily(const struct socket *so) int sobind(struct socket *so, struct sockaddr *nam, struct lwp *l) { - int error; + int error; solock(so); if (nam->sa_family != so->so_proto->pr_domain->dom_family) { @@ -650,8 +630,8 @@ sobind(struct socket *so, struct sockadd int solisten(struct socket *so, int backlog, struct lwp *l) { - int error; - short oldopt, oldqlimit; + int error; + short oldopt, oldqlimit; solock(so); if ((so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | @@ -865,7 +845,7 @@ soconnect2(struct socket *so1, struct so int sodisconnect(struct socket *so) { - int error; + int error; KASSERT(solocked(so)); @@ -876,7 +856,7 @@ sodisconnect(struct socket *so) } else { error = (*so->so_proto->pr_usrreqs->pr_disconnect)(so); } - return (error); + return error; } #define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK) @@ -901,10 +881,10 @@ int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct lwp *l) { - struct mbuf **mp, *m; - long space, len, resid, clen, mlen; - int error, s, dontroute, atomic; - short wakeup_state = 0; + struct mbuf **mp, *m; + long space, len, resid, clen, mlen; + int error, s, dontroute, atomic; + short wakeup_state = 0; clen = 0; @@ -1099,14 +1079,14 @@ sosend(struct socket *so, struct sockadd m_freem(top); if (control) m_freem(control); - return (error); + return error; } /* * Following replacement or removal of the first mbuf on the first * mbuf chain of a socket buffer, push necessary state changes back * into the socket buffer so that other consumers see the values - * consistently. 'nextrecord' is the callers locally stored value of + * consistently. 'nextrecord' is the caller's locally stored value of * the original value of sb->sb_mb->m_nextpkt which must be restored * when the lead mbuf changes. NOTE: 'nextrecord' may be NULL. */ @@ -1141,33 +1121,34 @@ sbsync(struct sockbuf *sb, struct mbuf * /* * Implement receive operations on a socket. - * We depend on the way that records are added to the sockbuf - * by sbappend*. In particular, each record (mbufs linked through m_next) - * must begin with an address if the protocol so specifies, - * followed by an optional mbuf or mbufs containing ancillary data, - * and then zero or more mbufs of data. - * In order to avoid blocking network interrupts for the entire time here, - * we splx() while doing the actual copy to user space. - * Although the sockbuf is locked, new data may still be appended, - * and thus we must maintain consistency of the sockbuf during that time. * - * The caller may receive the data as a single mbuf chain by supplying - * an mbuf **mp0 for use in returning the chain. The uio is then used - * only for the count in uio_resid. + * We depend on the way that records are added to the sockbuf by sbappend*. In + * particular, each record (mbufs linked through m_next) must begin with an + * address if the protocol so specifies, followed by an optional mbuf or mbufs + * containing ancillary data, and then zero or more mbufs of data. + * + * In order to avoid blocking network interrupts for the entire time here, we + * splx() while doing the actual copy to user space. Although the sockbuf is + * locked, new data may still be appended, and thus we must maintain + * consistency of the sockbuf during that time. + * + * The caller may receive the data as a single mbuf chain by supplying an mbuf + * **mp0 for use in returning the chain. The uio is then used only for the + * count in uio_resid. */ int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, - struct mbuf **mp0, struct mbuf **controlp, int *flagsp) + struct mbuf **mp0, struct mbuf **controlp, int *flagsp) { struct lwp *l = curlwp; - struct mbuf *m, **mp, *mt; + struct mbuf *m, **mp, *mt; size_t len, offset, moff, orig_resid; int atomic, flags, error, s, type; - const struct protosw *pr; - struct mbuf *nextrecord; - int mbuf_removed = 0; + const struct protosw *pr; + struct mbuf *nextrecord; + int mbuf_removed = 0; const struct domain *dom; - short wakeup_state = 0; + short wakeup_state = 0; pr = so->so_proto; atomic = pr->pr_flags & PR_ATOMIC; @@ -1197,7 +1178,7 @@ soreceive(struct socket *so, struct mbuf MIN(uio->uio_resid, m->m_len), uio); m = m_free(m); } while (uio->uio_resid > 0 && error == 0 && m); - bad: +bad: if (m != NULL) m_freem(m); return error; @@ -1212,14 +1193,14 @@ soreceive(struct socket *so, struct mbuf */ s = splsoftnet(); solock(so); - restart: +restart: if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) { sounlock(so); splx(s); return error; } - m = so->so_rcv.sb_mb; + /* * If we have less data than requested, block awaiting more * (subject to any timeout) if: @@ -1292,7 +1273,8 @@ soreceive(struct socket *so, struct mbuf wakeup_state = so->so_state; goto restart; } - dontblock: + +dontblock: /* * On entry here, m points to the first record of the socket buffer. * From this point onward, we maintain 'nextrecord' as a cache of the @@ -1315,11 +1297,9 @@ soreceive(struct socket *so, struct mbuf SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); SBLASTMBUFCHK(&so->so_rcv, "soreceive 1"); nextrecord = m->m_nextpkt; + if (pr->pr_flags & PR_ADDR) { -#ifdef DIAGNOSTIC - if (m->m_type != MT_SONAME) - panic("receive 1a"); -#endif + KASSERT(m->m_type == MT_SONAME); orig_resid = 0; if (flags & MSG_PEEK) { if (paddr) @@ -1339,10 +1319,11 @@ soreceive(struct socket *so, struct mbuf sbsync(&so->so_rcv, nextrecord); } } + if (pr->pr_flags & PR_ADDR_OPT) { /* - * For SCTP we may be getting a - * whole message OR a partial delivery. + * For SCTP we may be getting a whole message OR a partial + * delivery. */ if (m->m_type == MT_SONAME) { orig_resid = 0; @@ -1392,6 +1373,7 @@ soreceive(struct socket *so, struct mbuf } while (m != NULL && m->m_type == MT_CONTROL); if ((flags & MSG_PEEK) == 0) sbsync(&so->so_rcv, nextrecord); + for (; cm != NULL; cm = cmn) { cmn = cm->m_next; cm->m_next = NULL; @@ -1446,12 +1428,15 @@ soreceive(struct socket *so, struct mbuf if (m->m_type == MT_OOBDATA) { if (type != MT_OOBDATA) break; - } else if (type == MT_OOBDATA) + } else if (type == MT_OOBDATA) { break; + } #ifdef DIAGNOSTIC - else if (m->m_type != MT_DATA && m->m_type != MT_HEADER) + else if (m->m_type != MT_DATA && m->m_type != MT_HEADER) { panic("receive 3"); + } #endif + so->so_state &= ~SS_RCVATMARK; wakeup_state = 0; len = uio->uio_resid; @@ -1459,6 +1444,7 @@ soreceive(struct socket *so, struct mbuf len = so->so_oobmark - offset; if (len > m->m_len - moff) len = m->m_len - moff; + /* * If mp is set, just pass back the mbufs. * Otherwise copy them out via the uio, then free. @@ -1492,15 +1478,17 @@ soreceive(struct socket *so, struct mbuf goto release; } - } else + } else { uio->uio_resid -= len; + } + if (len == m->m_len - moff) { if (m->m_flags & M_EOR) flags |= MSG_EOR; #ifdef SCTP if (m->m_flags & M_NOTIFICATION) flags |= MSG_NOTIFICATION; -#endif /* SCTP */ +#endif if (flags & MSG_PEEK) { m = m->m_next; moff = 0; @@ -1531,9 +1519,9 @@ soreceive(struct socket *so, struct mbuf SBLASTRECORDCHK(&so->so_rcv, "soreceive 3"); SBLASTMBUFCHK(&so->so_rcv, "soreceive 3"); } - } else if (flags & MSG_PEEK) + } else if (flags & MSG_PEEK) { moff += len; - else { + } else { if (mp != NULL) { mt = m_copym(m, 0, len, M_NOWAIT); if (__predict_false(mt == NULL)) { @@ -1547,6 +1535,7 @@ soreceive(struct socket *so, struct mbuf m->m_len -= len; so->so_rcv.sb_cc -= len; } + if (so->so_oobmark) { if ((flags & MSG_PEEK) == 0) { so->so_oobmark -= len; @@ -1562,6 +1551,7 @@ soreceive(struct socket *so, struct mbuf } if (flags & MSG_EOR) break; + /* * If the MSG_WAITALL flag is set (for non-atomic socket), * we must not quit until "uio->uio_resid == 0" or an error @@ -1637,7 +1627,7 @@ soreceive(struct socket *so, struct mbuf if (flagsp != NULL) *flagsp |= flags; - release: +release: sbunlock(&so->so_rcv); sounlock(so); splx(s); @@ -1647,14 +1637,14 @@ soreceive(struct socket *so, struct mbuf int soshutdown(struct socket *so, int how) { - const struct protosw *pr; - int error; + const struct protosw *pr; + int error; KASSERT(solocked(so)); pr = so->so_proto; if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) - return (EINVAL); + return EINVAL; if (how == SHUT_RD || how == SHUT_RDWR) { sorflush(so); @@ -1688,8 +1678,8 @@ sorestart(struct socket *so) void sorflush(struct socket *so) { - struct sockbuf *sb, asb; - const struct protosw *pr; + struct sockbuf *sb, asb; + const struct protosw *pr; KASSERT(solocked(so)); @@ -2036,13 +2026,13 @@ sogetopt1(struct socket *so, struct sock break; } - return (error); + return error; } int sogetopt(struct socket *so, struct sockopt *sopt) { - int error; + int error; solock(so); if (sopt->sopt_level != SOL_SOCKET) { @@ -2055,7 +2045,7 @@ sogetopt(struct socket *so, struct socko error = sogetopt1(so, sopt); } sounlock(so); - return (error); + return error; } /* @@ -2126,7 +2116,7 @@ sockopt_set(struct sockopt *sopt, const if (sopt->sopt_size < len) return EINVAL; - + memcpy(sopt->sopt_data, buf, len); sopt->sopt_retsize = len; @@ -2190,7 +2180,7 @@ sockopt_setmbuf(struct sockopt *sopt, st if (sopt->sopt_size < len) return EINVAL; - + m_copydata(m, 0, len, sopt->sopt_data); m_freem(m); sopt->sopt_retsize = len; @@ -2241,7 +2231,7 @@ sohasoutofband(struct socket *so) static void filt_sordetach(struct knote *kn) { - struct socket *so; + struct socket *so; so = ((file_t *)kn->kn_obj)->f_socket; solock(so); @@ -2255,7 +2245,7 @@ filt_sordetach(struct knote *kn) static int filt_soread(struct knote *kn, long hint) { - struct socket *so; + struct socket *so; int rv; so = ((file_t *)kn->kn_obj)->f_socket; @@ -2280,7 +2270,7 @@ filt_soread(struct knote *kn, long hint) static void filt_sowdetach(struct knote *kn) { - struct socket *so; + struct socket *so; so = ((file_t *)kn->kn_obj)->f_socket; solock(so); @@ -2294,7 +2284,7 @@ filt_sowdetach(struct knote *kn) static int filt_sowrite(struct knote *kn, long hint) { - struct socket *so; + struct socket *so; int rv; so = ((file_t *)kn->kn_obj)->f_socket; @@ -2323,7 +2313,7 @@ filt_sowrite(struct knote *kn, long hint static int filt_solisten(struct knote *kn, long hint) { - struct socket *so; + struct socket *so; int rv; so = ((file_t *)kn->kn_obj)->f_socket; @@ -2365,8 +2355,8 @@ static const struct filterops sowrite_fi int soo_kqfilter(struct file *fp, struct knote *kn) { - struct socket *so; - struct sockbuf *sb; + struct socket *so; + struct sockbuf *sb; so = ((file_t *)kn->kn_obj)->f_socket; solock(so); @@ -2384,12 +2374,12 @@ soo_kqfilter(struct file *fp, struct kno break; default: sounlock(so); - return (EINVAL); + return EINVAL; } SLIST_INSERT_HEAD(&sb->sb_sel.sel_klist, kn, kn_selnext); sb->sb_flags |= SB_KNOTE; sounlock(so); - return (0); + return 0; } static int @@ -2495,17 +2485,17 @@ sysctl_kern_somaxkva(SYSCTLFN_ARGS) node.sysctl_data = &new_somaxkva; error = sysctl_lookup(SYSCTLFN_CALL(&node)); if (error || newp == NULL) - return (error); + return error; if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ - return (EINVAL); + return EINVAL; mutex_enter(&so_pendfree_lock); somaxkva = new_somaxkva; cv_broadcast(&socurkva_cv); mutex_exit(&so_pendfree_lock); - return (error); + return error; } /* @@ -2523,13 +2513,13 @@ sysctl_kern_sbmax(SYSCTLFN_ARGS) node.sysctl_data = &new_sbmax; error = sysctl_lookup(SYSCTLFN_CALL(&node)); if (error || newp == NULL) - return (error); + return error; KERNEL_LOCK(1, NULL); error = sb_max_set(new_sbmax); KERNEL_UNLOCK_ONE(NULL); - return (error); + return error; } /* @@ -2567,7 +2557,7 @@ sysctl_kern_socket_setup(void) CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "somaxkva", SYSCTL_DESCR("Maximum amount of kernel memory to be " - "used for socket buffers"), + "used for socket buffers"), sysctl_kern_somaxkva, 0, NULL, 0, CTL_KERN, KERN_SOMAXKVA, CTL_EOL);