uipc_syscalls.c (190958) | uipc_syscalls.c (191816) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * sendfile(2) and related extensions: 6 * Copyright (c) 1998, David Greenman. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * sendfile(2) and related extensions: 6 * Copyright (c) 1998, David Greenman. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/kern/uipc_syscalls.c 190958 2009-04-12 05:19:35Z kmacy $"); | 36__FBSDID("$FreeBSD: head/sys/kern/uipc_syscalls.c 191816 2009-05-05 10:56:12Z zec $"); |
37 38#include "opt_sctp.h" 39#include "opt_compat.h" 40#include "opt_ktrace.h" 41#include "opt_mac.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> --- 14 unchanged lines hidden (view full) --- 59#include <sys/sf_buf.h> 60#include <sys/socket.h> 61#include <sys/socketvar.h> 62#include <sys/signalvar.h> 63#include <sys/syscallsubr.h> 64#include <sys/sysctl.h> 65#include <sys/uio.h> 66#include <sys/vnode.h> | 37 38#include "opt_sctp.h" 39#include "opt_compat.h" 40#include "opt_ktrace.h" 41#include "opt_mac.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> --- 14 unchanged lines hidden (view full) --- 59#include <sys/sf_buf.h> 60#include <sys/socket.h> 61#include <sys/socketvar.h> 62#include <sys/signalvar.h> 63#include <sys/syscallsubr.h> 64#include <sys/sysctl.h> 65#include <sys/uio.h> 66#include <sys/vnode.h> |
67#include <sys/vimage.h> |
|
67#ifdef KTRACE 68#include <sys/ktrace.h> 69#endif 70 71#include <security/mac/mac_framework.h> 72 73#include <vm/vm.h> 74#include <vm/vm_object.h> --- 184 unchanged lines hidden (view full) --- 259 so = fp->f_data; 260#ifdef MAC 261 SOCK_LOCK(so); 262 error = mac_socket_check_listen(td->td_ucred, so); 263 SOCK_UNLOCK(so); 264 if (error) 265 goto done; 266#endif | 68#ifdef KTRACE 69#include <sys/ktrace.h> 70#endif 71 72#include <security/mac/mac_framework.h> 73 74#include <vm/vm.h> 75#include <vm/vm_object.h> --- 184 unchanged lines hidden (view full) --- 260 so = fp->f_data; 261#ifdef MAC 262 SOCK_LOCK(so); 263 error = mac_socket_check_listen(td->td_ucred, so); 264 SOCK_UNLOCK(so); 265 if (error) 266 goto done; 267#endif |
268 CURVNET_SET(so->so_vnet); |
|
267 error = solisten(so, uap->backlog, td); | 269 error = solisten(so, uap->backlog, td); |
270 CURVNET_RESTORE(); |
|
268#ifdef MAC 269done: 270#endif 271 fdrop(fp, td); 272 } 273 return(error); 274} 275 --- 148 unchanged lines hidden (view full) --- 424 425 finit(nfp, fflag, DTYPE_SOCKET, so, &socketops); 426 /* Sync socket nonblocking/async state with file flags */ 427 tmp = fflag & FNONBLOCK; 428 (void) fo_ioctl(nfp, FIONBIO, &tmp, td->td_ucred, td); 429 tmp = fflag & FASYNC; 430 (void) fo_ioctl(nfp, FIOASYNC, &tmp, td->td_ucred, td); 431 sa = 0; | 271#ifdef MAC 272done: 273#endif 274 fdrop(fp, td); 275 } 276 return(error); 277} 278 --- 148 unchanged lines hidden (view full) --- 427 428 finit(nfp, fflag, DTYPE_SOCKET, so, &socketops); 429 /* Sync socket nonblocking/async state with file flags */ 430 tmp = fflag & FNONBLOCK; 431 (void) fo_ioctl(nfp, FIONBIO, &tmp, td->td_ucred, td); 432 tmp = fflag & FASYNC; 433 (void) fo_ioctl(nfp, FIOASYNC, &tmp, td->td_ucred, td); 434 sa = 0; |
435 CURVNET_SET(so->so_vnet); |
|
432 error = soaccept(so, &sa); | 436 error = soaccept(so, &sa); |
437 CURVNET_RESTORE(); |
|
433 if (error) { 434 /* 435 * return a namelen of zero for older code which might 436 * ignore the return value from accept. 437 */ 438 if (name) 439 *namelen = 0; 440 goto noconnection; --- 530 unchanged lines hidden (view full) --- 971 return (EINVAL); 972 } 973 } 974#ifdef KTRACE 975 if (KTRPOINT(td, KTR_GENIO)) 976 ktruio = cloneuio(&auio); 977#endif 978 len = auio.uio_resid; | 438 if (error) { 439 /* 440 * return a namelen of zero for older code which might 441 * ignore the return value from accept. 442 */ 443 if (name) 444 *namelen = 0; 445 goto noconnection; --- 530 unchanged lines hidden (view full) --- 976 return (EINVAL); 977 } 978 } 979#ifdef KTRACE 980 if (KTRPOINT(td, KTR_GENIO)) 981 ktruio = cloneuio(&auio); 982#endif 983 len = auio.uio_resid; |
984 CURVNET_SET(so->so_vnet); |
|
979 error = soreceive(so, &fromsa, &auio, (struct mbuf **)0, 980 (mp->msg_control || controlp) ? &control : (struct mbuf **)0, 981 &mp->msg_flags); | 985 error = soreceive(so, &fromsa, &auio, (struct mbuf **)0, 986 (mp->msg_control || controlp) ? &control : (struct mbuf **)0, 987 &mp->msg_flags); |
988 CURVNET_RESTORE(); |
|
982 if (error) { 983 if (auio.uio_resid != (int)len && (error == ERESTART || 984 error == EINTR || error == EWOULDBLOCK)) 985 error = 0; 986 } 987#ifdef KTRACE 988 if (ktruio != NULL) { 989 ktruio->uio_resid = (int)len - auio.uio_resid; --- 327 unchanged lines hidden (view full) --- 1317 break; 1318 default: 1319 panic("kern_setsockopt called with bad valseg"); 1320 } 1321 1322 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1323 if (error == 0) { 1324 so = fp->f_data; | 989 if (error) { 990 if (auio.uio_resid != (int)len && (error == ERESTART || 991 error == EINTR || error == EWOULDBLOCK)) 992 error = 0; 993 } 994#ifdef KTRACE 995 if (ktruio != NULL) { 996 ktruio->uio_resid = (int)len - auio.uio_resid; --- 327 unchanged lines hidden (view full) --- 1324 break; 1325 default: 1326 panic("kern_setsockopt called with bad valseg"); 1327 } 1328 1329 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1330 if (error == 0) { 1331 so = fp->f_data; |
1332 CURVNET_SET(so->so_vnet); |
|
1325 error = sosetopt(so, &sopt); | 1333 error = sosetopt(so, &sopt); |
1334 CURVNET_RESTORE(); |
|
1326 fdrop(fp, td); 1327 } 1328 return(error); 1329} 1330 1331/* ARGSUSED */ 1332int 1333getsockopt(td, uap) --- 61 unchanged lines hidden (view full) --- 1395 break; 1396 default: 1397 panic("kern_getsockopt called with bad valseg"); 1398 } 1399 1400 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1401 if (error == 0) { 1402 so = fp->f_data; | 1335 fdrop(fp, td); 1336 } 1337 return(error); 1338} 1339 1340/* ARGSUSED */ 1341int 1342getsockopt(td, uap) --- 61 unchanged lines hidden (view full) --- 1404 break; 1405 default: 1406 panic("kern_getsockopt called with bad valseg"); 1407 } 1408 1409 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1410 if (error == 0) { 1411 so = fp->f_data; |
1412 CURVNET_SET(so->so_vnet); |
|
1403 error = sogetopt(so, &sopt); | 1413 error = sogetopt(so, &sopt); |
1414 CURVNET_RESTORE(); |
|
1404 *valsize = sopt.sopt_valsize; 1405 fdrop(fp, td); 1406 } 1407 return (error); 1408} 1409 1410/* 1411 * getsockname1() - Get socket name. --- 46 unchanged lines hidden (view full) --- 1458 if (*alen < 0) 1459 return (EINVAL); 1460 1461 error = getsock(td->td_proc->p_fd, fd, &fp, NULL); 1462 if (error) 1463 return (error); 1464 so = fp->f_data; 1465 *sa = NULL; | 1415 *valsize = sopt.sopt_valsize; 1416 fdrop(fp, td); 1417 } 1418 return (error); 1419} 1420 1421/* 1422 * getsockname1() - Get socket name. --- 46 unchanged lines hidden (view full) --- 1469 if (*alen < 0) 1470 return (EINVAL); 1471 1472 error = getsock(td->td_proc->p_fd, fd, &fp, NULL); 1473 if (error) 1474 return (error); 1475 so = fp->f_data; 1476 *sa = NULL; |
1477 CURVNET_SET(so->so_vnet); |
|
1466 error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa); | 1478 error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa); |
1479 CURVNET_RESTORE(); |
|
1467 if (error) 1468 goto bad; 1469 if (*sa == NULL) 1470 len = 0; 1471 else 1472 len = MIN(*alen, (*sa)->sa_len); 1473 *alen = len; 1474#ifdef KTRACE --- 84 unchanged lines hidden (view full) --- 1559 if (error) 1560 return (error); 1561 so = fp->f_data; 1562 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { 1563 error = ENOTCONN; 1564 goto done; 1565 } 1566 *sa = NULL; | 1480 if (error) 1481 goto bad; 1482 if (*sa == NULL) 1483 len = 0; 1484 else 1485 len = MIN(*alen, (*sa)->sa_len); 1486 *alen = len; 1487#ifdef KTRACE --- 84 unchanged lines hidden (view full) --- 1572 if (error) 1573 return (error); 1574 so = fp->f_data; 1575 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { 1576 error = ENOTCONN; 1577 goto done; 1578 } 1579 *sa = NULL; |
1580 CURVNET_SET(so->so_vnet); |
|
1567 error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa); | 1581 error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa); |
1582 CURVNET_RESTORE(); |
|
1568 if (error) 1569 goto bad; 1570 if (*sa == NULL) 1571 len = 0; 1572 else 1573 len = MIN(*alen, (*sa)->sa_len); 1574 *alen = len; 1575#ifdef KTRACE --- 595 unchanged lines hidden (view full) --- 2171 mlen = m_length(m, NULL); 2172 SOCKBUF_LOCK(&so->so_snd); 2173 if (so->so_snd.sb_state & SBS_CANTSENDMORE) { 2174 error = EPIPE; 2175 SOCKBUF_UNLOCK(&so->so_snd); 2176 goto done; 2177 } 2178 SOCKBUF_UNLOCK(&so->so_snd); | 1583 if (error) 1584 goto bad; 1585 if (*sa == NULL) 1586 len = 0; 1587 else 1588 len = MIN(*alen, (*sa)->sa_len); 1589 *alen = len; 1590#ifdef KTRACE --- 595 unchanged lines hidden (view full) --- 2186 mlen = m_length(m, NULL); 2187 SOCKBUF_LOCK(&so->so_snd); 2188 if (so->so_snd.sb_state & SBS_CANTSENDMORE) { 2189 error = EPIPE; 2190 SOCKBUF_UNLOCK(&so->so_snd); 2191 goto done; 2192 } 2193 SOCKBUF_UNLOCK(&so->so_snd); |
2194 CURVNET_SET(so->so_vnet); |
|
2179 /* Avoid error aliasing. */ 2180 err = (*so->so_proto->pr_usrreqs->pru_send) 2181 (so, 0, m, NULL, NULL, td); | 2195 /* Avoid error aliasing. */ 2196 err = (*so->so_proto->pr_usrreqs->pru_send) 2197 (so, 0, m, NULL, NULL, td); |
2198 CURVNET_RESTORE(); |
|
2182 if (err == 0) { 2183 /* 2184 * We need two counters to get the 2185 * file offset and nbytes to send 2186 * right: 2187 * - sbytes contains the total amount 2188 * of bytes sent, including headers. 2189 * - fsbytes contains the total amount --- 520 unchanged lines hidden --- | 2199 if (err == 0) { 2200 /* 2201 * We need two counters to get the 2202 * file offset and nbytes to send 2203 * right: 2204 * - sbytes contains the total amount 2205 * of bytes sent, including headers. 2206 * - fsbytes contains the total amount --- 520 unchanged lines hidden --- |