uipc_socket.c (169375) | uipc_socket.c (169624) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. 4 * Copyright (c) 2004 The FreeBSD Foundation 5 * Copyright (c) 2004-2007 Robert N. M. Watson 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 81 unchanged lines hidden (view full) --- 90 * calls to explicitly manage socket references, soref(), and sorele(). 91 * Currently, these are generally required only when transitioning a socket 92 * from a listen queue to a file descriptor, in order to prevent garbage 93 * collection of the socket at an untimely moment. For a number of reasons, 94 * these interfaces are not preferred, and should be avoided. 95 */ 96 97#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. 4 * Copyright (c) 2004 The FreeBSD Foundation 5 * Copyright (c) 2004-2007 Robert N. M. Watson 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 81 unchanged lines hidden (view full) --- 90 * calls to explicitly manage socket references, soref(), and sorele(). 91 * Currently, these are generally required only when transitioning a socket 92 * from a listen queue to a file descriptor, in order to prevent garbage 93 * collection of the socket at an untimely moment. For a number of reasons, 94 * these interfaces are not preferred, and should be avoided. 95 */ 96 97#include <sys/cdefs.h> |
98__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 169375 2007-05-08 12:34:14Z yongari $"); | 98__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 169624 2007-05-16 20:41:08Z rwatson $"); |
99 100#include "opt_inet.h" 101#include "opt_mac.h" 102#include "opt_zero.h" 103#include "opt_compat.h" 104 105#include <sys/param.h> 106#include <sys/systm.h> --- 215 unchanged lines hidden (view full) --- 322 uma_zfree(socket_zone, so); 323} 324 325/* 326 * socreate returns a socket with a ref count of 1. The socket should be 327 * closed with soclose(). 328 */ 329int | 99 100#include "opt_inet.h" 101#include "opt_mac.h" 102#include "opt_zero.h" 103#include "opt_compat.h" 104 105#include <sys/param.h> 106#include <sys/systm.h> --- 215 unchanged lines hidden (view full) --- 322 uma_zfree(socket_zone, so); 323} 324 325/* 326 * socreate returns a socket with a ref count of 1. The socket should be 327 * closed with soclose(). 328 */ 329int |
330socreate(dom, aso, type, proto, cred, td) 331 int dom; 332 struct socket **aso; 333 int type; 334 int proto; 335 struct ucred *cred; 336 struct thread *td; | 330socreate(int dom, struct socket **aso, int type, int proto, 331 struct ucred *cred, struct thread *td) |
337{ 338 struct protosw *prp; 339 struct socket *so; 340 int error; 341 342 if (proto) 343 prp = pffindproto(dom, proto, type); 344 else --- 56 unchanged lines hidden (view full) --- 401 * connections, sonewconn is called. If the connection is possible (subject 402 * to space constraints, etc.) then we allocate a new structure, propoerly 403 * linked into the data structure of the original socket, and return this. 404 * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED. 405 * 406 * Note: the ref count on the socket is 0 on return. 407 */ 408struct socket * | 332{ 333 struct protosw *prp; 334 struct socket *so; 335 int error; 336 337 if (proto) 338 prp = pffindproto(dom, proto, type); 339 else --- 56 unchanged lines hidden (view full) --- 396 * connections, sonewconn is called. If the connection is possible (subject 397 * to space constraints, etc.) then we allocate a new structure, propoerly 398 * linked into the data structure of the original socket, and return this. 399 * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED. 400 * 401 * Note: the ref count on the socket is 0 on return. 402 */ 403struct socket * |
409sonewconn(head, connstatus) 410 register struct socket *head; 411 int connstatus; | 404sonewconn(struct socket *head, int connstatus) |
412{ | 405{ |
413 register struct socket *so; | 406 struct socket *so; |
414 int over; 415 416 ACCEPT_LOCK(); 417 over = (head->so_qlen > 3 * head->so_qlimit / 2); 418 ACCEPT_UNLOCK(); 419#ifdef REGRESSION 420 if (regression_sonewconn_earlytest && over) 421#else --- 65 unchanged lines hidden (view full) --- 487 if (connstatus) { 488 sorwakeup(head); 489 wakeup_one(&head->so_timeo); 490 } 491 return (so); 492} 493 494int | 407 int over; 408 409 ACCEPT_LOCK(); 410 over = (head->so_qlen > 3 * head->so_qlimit / 2); 411 ACCEPT_UNLOCK(); 412#ifdef REGRESSION 413 if (regression_sonewconn_earlytest && over) 414#else --- 65 unchanged lines hidden (view full) --- 480 if (connstatus) { 481 sorwakeup(head); 482 wakeup_one(&head->so_timeo); 483 } 484 return (so); 485} 486 487int |
495sobind(so, nam, td) 496 struct socket *so; 497 struct sockaddr *nam; 498 struct thread *td; | 488sobind(struct socket *so, struct sockaddr *nam, struct thread *td) |
499{ 500 501 return ((*so->so_proto->pr_usrreqs->pru_bind)(so, nam, td)); 502} 503 504/* 505 * solisten() transitions a socket from a non-listening state to a listening 506 * state, but can also be used to update the listen queue depth on an 507 * existing listen socket. The protocol will call back into the sockets 508 * layer using solisten_proto_check() and solisten_proto() to check and set 509 * socket-layer listen state. Call backs are used so that the protocol can 510 * acquire both protocol and socket layer locks in whatever order is required 511 * by the protocol. 512 * 513 * Protocol implementors are advised to hold the socket lock across the 514 * socket-layer test and set to avoid races at the socket layer. 515 */ 516int | 489{ 490 491 return ((*so->so_proto->pr_usrreqs->pru_bind)(so, nam, td)); 492} 493 494/* 495 * solisten() transitions a socket from a non-listening state to a listening 496 * state, but can also be used to update the listen queue depth on an 497 * existing listen socket. The protocol will call back into the sockets 498 * layer using solisten_proto_check() and solisten_proto() to check and set 499 * socket-layer listen state. Call backs are used so that the protocol can 500 * acquire both protocol and socket layer locks in whatever order is required 501 * by the protocol. 502 * 503 * Protocol implementors are advised to hold the socket lock across the 504 * socket-layer test and set to avoid races at the socket layer. 505 */ 506int |
517solisten(so, backlog, td) 518 struct socket *so; 519 int backlog; 520 struct thread *td; | 507solisten(struct socket *so, int backlog, struct thread *td) |
521{ 522 523 return ((*so->so_proto->pr_usrreqs->pru_listen)(so, backlog, td)); 524} 525 526int | 508{ 509 510 return ((*so->so_proto->pr_usrreqs->pru_listen)(so, backlog, td)); 511} 512 513int |
527solisten_proto_check(so) 528 struct socket *so; | 514solisten_proto_check(struct socket *so) |
529{ 530 531 SOCK_LOCK_ASSERT(so); 532 533 if (so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | 534 SS_ISDISCONNECTING)) 535 return (EINVAL); 536 return (0); 537} 538 539void | 515{ 516 517 SOCK_LOCK_ASSERT(so); 518 519 if (so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | 520 SS_ISDISCONNECTING)) 521 return (EINVAL); 522 return (0); 523} 524 525void |
540solisten_proto(so, backlog) 541 struct socket *so; 542 int backlog; | 526solisten_proto(struct socket *so, int backlog) |
543{ 544 545 SOCK_LOCK_ASSERT(so); 546 547 if (backlog < 0 || backlog > somaxconn) 548 backlog = somaxconn; 549 so->so_qlimit = backlog; 550 so->so_options |= SO_ACCEPTCONN; --- 15 unchanged lines hidden (view full) --- 566 * - The socket is not in a completed connection queue, so a process has been 567 * notified that it is present. If it is removed, the user process may 568 * block in accept() despite select() saying the socket was ready. 569 * 570 * Otherwise, it will quietly abort so that a future call to sofree(), when 571 * conditions are right, can succeed. 572 */ 573void | 527{ 528 529 SOCK_LOCK_ASSERT(so); 530 531 if (backlog < 0 || backlog > somaxconn) 532 backlog = somaxconn; 533 so->so_qlimit = backlog; 534 so->so_options |= SO_ACCEPTCONN; --- 15 unchanged lines hidden (view full) --- 550 * - The socket is not in a completed connection queue, so a process has been 551 * notified that it is present. If it is removed, the user process may 552 * block in accept() despite select() saying the socket was ready. 553 * 554 * Otherwise, it will quietly abort so that a future call to sofree(), when 555 * conditions are right, can succeed. 556 */ 557void |
574sofree(so) 575 struct socket *so; | 558sofree(struct socket *so) |
576{ 577 struct protosw *pr = so->so_proto; 578 struct socket *head; 579 580 ACCEPT_LOCK_ASSERT(); 581 SOCK_LOCK_ASSERT(so); 582 583 if ((so->so_state & SS_NOFDREF) == 0 || so->so_count != 0 || --- 58 unchanged lines hidden (view full) --- 642 * Close a socket on last file table reference removal. Initiate disconnect 643 * if connected. Free socket when disconnect complete. 644 * 645 * This function will sorele() the socket. Note that soclose() may be called 646 * prior to the ref count reaching zero. The actual socket structure will 647 * not be freed until the ref count reaches zero. 648 */ 649int | 559{ 560 struct protosw *pr = so->so_proto; 561 struct socket *head; 562 563 ACCEPT_LOCK_ASSERT(); 564 SOCK_LOCK_ASSERT(so); 565 566 if ((so->so_state & SS_NOFDREF) == 0 || so->so_count != 0 || --- 58 unchanged lines hidden (view full) --- 625 * Close a socket on last file table reference removal. Initiate disconnect 626 * if connected. Free socket when disconnect complete. 627 * 628 * This function will sorele() the socket. Note that soclose() may be called 629 * prior to the ref count reaching zero. The actual socket structure will 630 * not be freed until the ref count reaches zero. 631 */ 632int |
650soclose(so) 651 struct socket *so; | 633soclose(struct socket *so) |
652{ 653 int error = 0; 654 655 KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter")); 656 657 funsetown(&so->so_sigio); 658 if (so->so_state & SS_ISCONNECTED) { 659 if ((so->so_state & SS_ISDISCONNECTING) == 0) { --- 58 unchanged lines hidden (view full) --- 718 * from the listen queue it was on, or races with other threads are risked. 719 * 720 * This interface will call into the protocol code, so must not be called 721 * with any socket locks held. Protocols do call it while holding their own 722 * recursible protocol mutexes, but this is something that should be subject 723 * to review in the future. 724 */ 725void | 634{ 635 int error = 0; 636 637 KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter")); 638 639 funsetown(&so->so_sigio); 640 if (so->so_state & SS_ISCONNECTED) { 641 if ((so->so_state & SS_ISDISCONNECTING) == 0) { --- 58 unchanged lines hidden (view full) --- 700 * from the listen queue it was on, or races with other threads are risked. 701 * 702 * This interface will call into the protocol code, so must not be called 703 * with any socket locks held. Protocols do call it while holding their own 704 * recursible protocol mutexes, but this is something that should be subject 705 * to review in the future. 706 */ 707void |
726soabort(so) 727 struct socket *so; | 708soabort(struct socket *so) |
728{ 729 730 /* 731 * In as much as is possible, assert that no references to this 732 * socket are held. This is not quite the same as asserting that the 733 * current thread is responsible for arranging for no references, but 734 * is as close as we can get for now. 735 */ --- 6 unchanged lines hidden (view full) --- 742 if (so->so_proto->pr_usrreqs->pru_abort != NULL) 743 (*so->so_proto->pr_usrreqs->pru_abort)(so); 744 ACCEPT_LOCK(); 745 SOCK_LOCK(so); 746 sofree(so); 747} 748 749int | 709{ 710 711 /* 712 * In as much as is possible, assert that no references to this 713 * socket are held. This is not quite the same as asserting that the 714 * current thread is responsible for arranging for no references, but 715 * is as close as we can get for now. 716 */ --- 6 unchanged lines hidden (view full) --- 723 if (so->so_proto->pr_usrreqs->pru_abort != NULL) 724 (*so->so_proto->pr_usrreqs->pru_abort)(so); 725 ACCEPT_LOCK(); 726 SOCK_LOCK(so); 727 sofree(so); 728} 729 730int |
750soaccept(so, nam) 751 struct socket *so; 752 struct sockaddr **nam; | 731soaccept(struct socket *so, struct sockaddr **nam) |
753{ 754 int error; 755 756 SOCK_LOCK(so); 757 KASSERT((so->so_state & SS_NOFDREF) != 0, ("soaccept: !NOFDREF")); 758 so->so_state &= ~SS_NOFDREF; 759 SOCK_UNLOCK(so); 760 error = (*so->so_proto->pr_usrreqs->pru_accept)(so, nam); 761 return (error); 762} 763 764int | 732{ 733 int error; 734 735 SOCK_LOCK(so); 736 KASSERT((so->so_state & SS_NOFDREF) != 0, ("soaccept: !NOFDREF")); 737 so->so_state &= ~SS_NOFDREF; 738 SOCK_UNLOCK(so); 739 error = (*so->so_proto->pr_usrreqs->pru_accept)(so, nam); 740 return (error); 741} 742 743int |
765soconnect(so, nam, td) 766 struct socket *so; 767 struct sockaddr *nam; 768 struct thread *td; | 744soconnect(struct socket *so, struct sockaddr *nam, struct thread *td) |
769{ 770 int error; 771 772 if (so->so_options & SO_ACCEPTCONN) 773 return (EOPNOTSUPP); 774 /* 775 * If protocol is connection-based, can only connect once. 776 * Otherwise, if connected, try to disconnect first. This allows --- 11 unchanged lines hidden (view full) --- 788 so->so_error = 0; 789 error = (*so->so_proto->pr_usrreqs->pru_connect)(so, nam, td); 790 } 791 792 return (error); 793} 794 795int | 745{ 746 int error; 747 748 if (so->so_options & SO_ACCEPTCONN) 749 return (EOPNOTSUPP); 750 /* 751 * If protocol is connection-based, can only connect once. 752 * Otherwise, if connected, try to disconnect first. This allows --- 11 unchanged lines hidden (view full) --- 764 so->so_error = 0; 765 error = (*so->so_proto->pr_usrreqs->pru_connect)(so, nam, td); 766 } 767 768 return (error); 769} 770 771int |
796soconnect2(so1, so2) 797 struct socket *so1; 798 struct socket *so2; | 772soconnect2(struct socket *so1, struct socket *so2) |
799{ 800 801 return ((*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2)); 802} 803 804int | 773{ 774 775 return ((*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2)); 776} 777 778int |
805sodisconnect(so) 806 struct socket *so; | 779sodisconnect(struct socket *so) |
807{ 808 int error; 809 810 if ((so->so_state & SS_ISCONNECTED) == 0) 811 return (ENOTCONN); 812 if (so->so_state & SS_ISDISCONNECTING) 813 return (EALREADY); 814 error = (*so->so_proto->pr_usrreqs->pru_disconnect)(so); --- 126 unchanged lines hidden (view full) --- 941 *retmp = top; 942 return (error); 943} 944#endif /*ZERO_COPY_SOCKETS*/ 945 946#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK) 947 948int | 780{ 781 int error; 782 783 if ((so->so_state & SS_ISCONNECTED) == 0) 784 return (ENOTCONN); 785 if (so->so_state & SS_ISDISCONNECTING) 786 return (EALREADY); 787 error = (*so->so_proto->pr_usrreqs->pru_disconnect)(so); --- 126 unchanged lines hidden (view full) --- 914 *retmp = top; 915 return (error); 916} 917#endif /*ZERO_COPY_SOCKETS*/ 918 919#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK) 920 921int |
949sosend_dgram(so, addr, uio, top, control, flags, td) 950 struct socket *so; 951 struct sockaddr *addr; 952 struct uio *uio; 953 struct mbuf *top; 954 struct mbuf *control; 955 int flags; 956 struct thread *td; | 922sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, 923 struct mbuf *top, struct mbuf *control, int flags, struct thread *td) |
957{ 958 long space, resid; 959 int clen = 0, error, dontroute; 960#ifdef ZERO_COPY_SOCKETS 961 int atomic = sosendallatonce(so) || top; 962#endif 963 964 KASSERT(so->so_type == SOCK_DGRAM, ("sodgram_send: !SOCK_DGRAM")); --- 156 unchanged lines hidden (view full) --- 1121 * by the mbuf chain "top" (which must be null if uio is not). Data provided 1122 * in mbuf chain must be small enough to send all at once. 1123 * 1124 * Returns nonzero on error, timeout or signal; callers must check for short 1125 * counts if EINTR/ERESTART are returned. Data and control buffers are freed 1126 * on return. 1127 */ 1128int | 924{ 925 long space, resid; 926 int clen = 0, error, dontroute; 927#ifdef ZERO_COPY_SOCKETS 928 int atomic = sosendallatonce(so) || top; 929#endif 930 931 KASSERT(so->so_type == SOCK_DGRAM, ("sodgram_send: !SOCK_DGRAM")); --- 156 unchanged lines hidden (view full) --- 1088 * by the mbuf chain "top" (which must be null if uio is not). Data provided 1089 * in mbuf chain must be small enough to send all at once. 1090 * 1091 * Returns nonzero on error, timeout or signal; callers must check for short 1092 * counts if EINTR/ERESTART are returned. Data and control buffers are freed 1093 * on return. 1094 */ 1095int |
1129sosend_generic(so, addr, uio, top, control, flags, td) 1130 struct socket *so; 1131 struct sockaddr *addr; 1132 struct uio *uio; 1133 struct mbuf *top; 1134 struct mbuf *control; 1135 int flags; 1136 struct thread *td; | 1096sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, 1097 struct mbuf *top, struct mbuf *control, int flags, struct thread *td) |
1137{ 1138 long space, resid; 1139 int clen = 0, error, dontroute; 1140 int atomic = sosendallatonce(so) || top; 1141 1142 if (uio != NULL) 1143 resid = uio->uio_resid; 1144 else --- 164 unchanged lines hidden (view full) --- 1309 if (top != NULL) 1310 m_freem(top); 1311 if (control != NULL) 1312 m_freem(control); 1313 return (error); 1314} 1315 1316int | 1098{ 1099 long space, resid; 1100 int clen = 0, error, dontroute; 1101 int atomic = sosendallatonce(so) || top; 1102 1103 if (uio != NULL) 1104 resid = uio->uio_resid; 1105 else --- 164 unchanged lines hidden (view full) --- 1270 if (top != NULL) 1271 m_freem(top); 1272 if (control != NULL) 1273 m_freem(control); 1274 return (error); 1275} 1276 1277int |
1317sosend(so, addr, uio, top, control, flags, td) 1318 struct socket *so; 1319 struct sockaddr *addr; 1320 struct uio *uio; 1321 struct mbuf *top; 1322 struct mbuf *control; 1323 int flags; 1324 struct thread *td; | 1278sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, 1279 struct mbuf *top, struct mbuf *control, int flags, struct thread *td) |
1325{ 1326 1327 /* XXXRW: Temporary debugging. */ 1328 KASSERT(so->so_proto->pr_usrreqs->pru_sosend != sosend, 1329 ("sosend: protocol calls sosend")); 1330 1331 return (so->so_proto->pr_usrreqs->pru_sosend(so, addr, uio, top, 1332 control, flags, td)); 1333} 1334 1335/* 1336 * The part of soreceive() that implements reading non-inline out-of-band 1337 * data from a socket. For more complete comments, see soreceive(), from 1338 * which this code originated. 1339 * 1340 * Note that soreceive_rcvoob(), unlike the remainder of soreceive(), is 1341 * unable to return an mbuf chain to the caller. 1342 */ 1343static int | 1280{ 1281 1282 /* XXXRW: Temporary debugging. */ 1283 KASSERT(so->so_proto->pr_usrreqs->pru_sosend != sosend, 1284 ("sosend: protocol calls sosend")); 1285 1286 return (so->so_proto->pr_usrreqs->pru_sosend(so, addr, uio, top, 1287 control, flags, td)); 1288} 1289 1290/* 1291 * The part of soreceive() that implements reading non-inline out-of-band 1292 * data from a socket. For more complete comments, see soreceive(), from 1293 * which this code originated. 1294 * 1295 * Note that soreceive_rcvoob(), unlike the remainder of soreceive(), is 1296 * unable to return an mbuf chain to the caller. 1297 */ 1298static int |
1344soreceive_rcvoob(so, uio, flags) 1345 struct socket *so; 1346 struct uio *uio; 1347 int flags; | 1299soreceive_rcvoob(struct socket *so, struct uio *uio, int flags) |
1348{ 1349 struct protosw *pr = so->so_proto; 1350 struct mbuf *m; 1351 int error; 1352 1353 KASSERT(flags & MSG_OOB, ("soreceive_rcvoob: (flags & MSG_OOB) == 0")); 1354 1355 m = m_get(M_TRYWAIT, MT_DATA); --- 76 unchanged lines hidden (view full) --- 1432 * appended, and thus we must maintain consistency of the sockbuf during that 1433 * time. 1434 * 1435 * The caller may receive the data as a single mbuf chain by supplying an 1436 * mbuf **mp0 for use in returning the chain. The uio is then used only for 1437 * the count in uio_resid. 1438 */ 1439int | 1300{ 1301 struct protosw *pr = so->so_proto; 1302 struct mbuf *m; 1303 int error; 1304 1305 KASSERT(flags & MSG_OOB, ("soreceive_rcvoob: (flags & MSG_OOB) == 0")); 1306 1307 m = m_get(M_TRYWAIT, MT_DATA); --- 76 unchanged lines hidden (view full) --- 1384 * appended, and thus we must maintain consistency of the sockbuf during that 1385 * time. 1386 * 1387 * The caller may receive the data as a single mbuf chain by supplying an 1388 * mbuf **mp0 for use in returning the chain. The uio is then used only for 1389 * the count in uio_resid. 1390 */ 1391int |
1440soreceive_generic(so, psa, uio, mp0, controlp, flagsp) 1441 struct socket *so; 1442 struct sockaddr **psa; 1443 struct uio *uio; 1444 struct mbuf **mp0; 1445 struct mbuf **controlp; 1446 int *flagsp; | 1392soreceive_generic(struct socket *so, struct sockaddr **psa, struct uio *uio, 1393 struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
1447{ 1448 struct mbuf *m, **mp; 1449 int flags, len, error, offset; 1450 struct protosw *pr = so->so_proto; 1451 struct mbuf *nextrecord; 1452 int moff, type = 0; 1453 int orig_resid = uio->uio_resid; 1454 --- 435 unchanged lines hidden (view full) --- 1890 if (flagsp != NULL) 1891 *flagsp |= flags; 1892release: 1893 sbunlock(&so->so_rcv); 1894 return (error); 1895} 1896 1897int | 1394{ 1395 struct mbuf *m, **mp; 1396 int flags, len, error, offset; 1397 struct protosw *pr = so->so_proto; 1398 struct mbuf *nextrecord; 1399 int moff, type = 0; 1400 int orig_resid = uio->uio_resid; 1401 --- 435 unchanged lines hidden (view full) --- 1837 if (flagsp != NULL) 1838 *flagsp |= flags; 1839release: 1840 sbunlock(&so->so_rcv); 1841 return (error); 1842} 1843 1844int |
1898soreceive(so, psa, uio, mp0, controlp, flagsp) 1899 struct socket *so; 1900 struct sockaddr **psa; 1901 struct uio *uio; 1902 struct mbuf **mp0; 1903 struct mbuf **controlp; 1904 int *flagsp; | 1845soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, 1846 struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
1905{ 1906 1907 /* XXXRW: Temporary debugging. */ 1908 KASSERT(so->so_proto->pr_usrreqs->pru_soreceive != soreceive, 1909 ("soreceive: protocol calls soreceive")); 1910 1911 return (so->so_proto->pr_usrreqs->pru_soreceive(so, psa, uio, mp0, 1912 controlp, flagsp)); 1913} 1914 1915int | 1847{ 1848 1849 /* XXXRW: Temporary debugging. */ 1850 KASSERT(so->so_proto->pr_usrreqs->pru_soreceive != soreceive, 1851 ("soreceive: protocol calls soreceive")); 1852 1853 return (so->so_proto->pr_usrreqs->pru_soreceive(so, psa, uio, mp0, 1854 controlp, flagsp)); 1855} 1856 1857int |
1916soshutdown(so, how) 1917 struct socket *so; 1918 int how; | 1858soshutdown(struct socket *so, int how) |
1919{ 1920 struct protosw *pr = so->so_proto; 1921 1922 if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) 1923 return (EINVAL); 1924 1925 if (how != SHUT_WR) 1926 sorflush(so); 1927 if (how != SHUT_RD) 1928 return ((*pr->pr_usrreqs->pru_shutdown)(so)); 1929 return (0); 1930} 1931 1932void | 1859{ 1860 struct protosw *pr = so->so_proto; 1861 1862 if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) 1863 return (EINVAL); 1864 1865 if (how != SHUT_WR) 1866 sorflush(so); 1867 if (how != SHUT_RD) 1868 return ((*pr->pr_usrreqs->pru_shutdown)(so)); 1869 return (0); 1870} 1871 1872void |
1933sorflush(so) 1934 struct socket *so; | 1873sorflush(struct socket *so) |
1935{ 1936 struct sockbuf *sb = &so->so_rcv; 1937 struct protosw *pr = so->so_proto; 1938 struct sockbuf asb; 1939 1940 /* 1941 * XXXRW: This is quite ugly. Previously, this code made a copy of 1942 * the socket buffer, then zero'd the original to clear the buffer --- 29 unchanged lines hidden (view full) --- 1972/* 1973 * Perhaps this routine, and sooptcopyout(), below, ought to come in an 1974 * additional variant to handle the case where the option value needs to be 1975 * some kind of integer, but not a specific size. In addition to their use 1976 * here, these functions are also called by the protocol-level pr_ctloutput() 1977 * routines. 1978 */ 1979int | 1874{ 1875 struct sockbuf *sb = &so->so_rcv; 1876 struct protosw *pr = so->so_proto; 1877 struct sockbuf asb; 1878 1879 /* 1880 * XXXRW: This is quite ugly. Previously, this code made a copy of 1881 * the socket buffer, then zero'd the original to clear the buffer --- 29 unchanged lines hidden (view full) --- 1911/* 1912 * Perhaps this routine, and sooptcopyout(), below, ought to come in an 1913 * additional variant to handle the case where the option value needs to be 1914 * some kind of integer, but not a specific size. In addition to their use 1915 * here, these functions are also called by the protocol-level pr_ctloutput() 1916 * routines. 1917 */ 1918int |
1980sooptcopyin(sopt, buf, len, minlen) 1981 struct sockopt *sopt; 1982 void *buf; 1983 size_t len; 1984 size_t minlen; | 1919sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen) |
1985{ 1986 size_t valsize; 1987 1988 /* 1989 * If the user gives us more than we wanted, we ignore it, but if we 1990 * don't get the minimum length the caller wants, we return EINVAL. 1991 * On success, sopt->sopt_valsize is set to however much we actually 1992 * retrieved. --- 26 unchanged lines hidden (view full) --- 2019 sopt.sopt_dir = SOPT_SET; 2020 sopt.sopt_val = optval; 2021 sopt.sopt_valsize = optlen; 2022 sopt.sopt_td = NULL; 2023 return (sosetopt(so, &sopt)); 2024} 2025 2026int | 1920{ 1921 size_t valsize; 1922 1923 /* 1924 * If the user gives us more than we wanted, we ignore it, but if we 1925 * don't get the minimum length the caller wants, we return EINVAL. 1926 * On success, sopt->sopt_valsize is set to however much we actually 1927 * retrieved. --- 26 unchanged lines hidden (view full) --- 1954 sopt.sopt_dir = SOPT_SET; 1955 sopt.sopt_val = optval; 1956 sopt.sopt_valsize = optlen; 1957 sopt.sopt_td = NULL; 1958 return (sosetopt(so, &sopt)); 1959} 1960 1961int |
2027sosetopt(so, sopt) 2028 struct socket *so; 2029 struct sockopt *sopt; | 1962sosetopt(struct socket *so, struct sockopt *sopt) |
2030{ 2031 int error, optval; 2032 struct linger l; 2033 struct timeval tv; 2034 u_long val; 2035#ifdef MAC 2036 struct mac extmac; 2037#endif --- 198 unchanged lines hidden (view full) --- 2236 error = copyout(buf, sopt->sopt_val, valsize); 2237 else 2238 bcopy(buf, sopt->sopt_val, valsize); 2239 } 2240 return (error); 2241} 2242 2243int | 1963{ 1964 int error, optval; 1965 struct linger l; 1966 struct timeval tv; 1967 u_long val; 1968#ifdef MAC 1969 struct mac extmac; 1970#endif --- 198 unchanged lines hidden (view full) --- 2169 error = copyout(buf, sopt->sopt_val, valsize); 2170 else 2171 bcopy(buf, sopt->sopt_val, valsize); 2172 } 2173 return (error); 2174} 2175 2176int |
2244sogetopt(so, sopt) 2245 struct socket *so; 2246 struct sockopt *sopt; | 2177sogetopt(struct socket *so, struct sockopt *sopt) |
2247{ 2248 int error, optval; 2249 struct linger l; 2250 struct timeval tv; 2251#ifdef MAC 2252 struct mac extmac; 2253#endif 2254 --- 247 unchanged lines hidden (view full) --- 2502 return (0); 2503} 2504 2505/* 2506 * sohasoutofband(): protocol notifies socket layer of the arrival of new 2507 * out-of-band data, which will then notify socket consumers. 2508 */ 2509void | 2178{ 2179 int error, optval; 2180 struct linger l; 2181 struct timeval tv; 2182#ifdef MAC 2183 struct mac extmac; 2184#endif 2185 --- 247 unchanged lines hidden (view full) --- 2433 return (0); 2434} 2435 2436/* 2437 * sohasoutofband(): protocol notifies socket layer of the arrival of new 2438 * out-of-band data, which will then notify socket consumers. 2439 */ 2440void |
2510sohasoutofband(so) 2511 struct socket *so; | 2441sohasoutofband(struct socket *so) |
2512{ | 2442{ |
2443 |
|
2513 if (so->so_sigio != NULL) 2514 pgsigio(&so->so_sigio, SIGURG, 0); 2515 selwakeuppri(&so->so_rcv.sb_sel, PSOCK); 2516} 2517 2518int 2519sopoll(struct socket *so, int events, struct ucred *active_cred, 2520 struct thread *td) --- 82 unchanged lines hidden (view full) --- 2603 2604/* 2605 * Some routines that return EOPNOTSUPP for entry points that are not 2606 * supported by a protocol. Fill in as needed. 2607 */ 2608int 2609pru_accept_notsupp(struct socket *so, struct sockaddr **nam) 2610{ | 2444 if (so->so_sigio != NULL) 2445 pgsigio(&so->so_sigio, SIGURG, 0); 2446 selwakeuppri(&so->so_rcv.sb_sel, PSOCK); 2447} 2448 2449int 2450sopoll(struct socket *so, int events, struct ucred *active_cred, 2451 struct thread *td) --- 82 unchanged lines hidden (view full) --- 2534 2535/* 2536 * Some routines that return EOPNOTSUPP for entry points that are not 2537 * supported by a protocol. Fill in as needed. 2538 */ 2539int 2540pru_accept_notsupp(struct socket *so, struct sockaddr **nam) 2541{ |
2542 |
|
2611 return EOPNOTSUPP; 2612} 2613 2614int 2615pru_attach_notsupp(struct socket *so, int proto, struct thread *td) 2616{ | 2543 return EOPNOTSUPP; 2544} 2545 2546int 2547pru_attach_notsupp(struct socket *so, int proto, struct thread *td) 2548{ |
2549 |
|
2617 return EOPNOTSUPP; 2618} 2619 2620int 2621pru_bind_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td) 2622{ | 2550 return EOPNOTSUPP; 2551} 2552 2553int 2554pru_bind_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td) 2555{ |
2556 |
|
2623 return EOPNOTSUPP; 2624} 2625 2626int 2627pru_connect_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td) 2628{ | 2557 return EOPNOTSUPP; 2558} 2559 2560int 2561pru_connect_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td) 2562{ |
2563 |
|
2629 return EOPNOTSUPP; 2630} 2631 2632int 2633pru_connect2_notsupp(struct socket *so1, struct socket *so2) 2634{ | 2564 return EOPNOTSUPP; 2565} 2566 2567int 2568pru_connect2_notsupp(struct socket *so1, struct socket *so2) 2569{ |
2570 |
|
2635 return EOPNOTSUPP; 2636} 2637 2638int 2639pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data, | 2571 return EOPNOTSUPP; 2572} 2573 2574int 2575pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data, |
2640 struct ifnet *ifp, struct thread *td) | 2576 struct ifnet *ifp, struct thread *td) |
2641{ | 2577{ |
2578 |
|
2642 return EOPNOTSUPP; 2643} 2644 2645int 2646pru_disconnect_notsupp(struct socket *so) 2647{ | 2579 return EOPNOTSUPP; 2580} 2581 2582int 2583pru_disconnect_notsupp(struct socket *so) 2584{ |
2585 |
|
2648 return EOPNOTSUPP; 2649} 2650 2651int 2652pru_listen_notsupp(struct socket *so, int backlog, struct thread *td) 2653{ | 2586 return EOPNOTSUPP; 2587} 2588 2589int 2590pru_listen_notsupp(struct socket *so, int backlog, struct thread *td) 2591{ |
2592 |
|
2654 return EOPNOTSUPP; 2655} 2656 2657int 2658pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam) 2659{ | 2593 return EOPNOTSUPP; 2594} 2595 2596int 2597pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam) 2598{ |
2599 |
|
2660 return EOPNOTSUPP; 2661} 2662 2663int 2664pru_rcvd_notsupp(struct socket *so, int flags) 2665{ | 2600 return EOPNOTSUPP; 2601} 2602 2603int 2604pru_rcvd_notsupp(struct socket *so, int flags) 2605{ |
2606 |
|
2666 return EOPNOTSUPP; 2667} 2668 2669int 2670pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags) 2671{ | 2607 return EOPNOTSUPP; 2608} 2609 2610int 2611pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags) 2612{ |
2613 |
|
2672 return EOPNOTSUPP; 2673} 2674 2675int 2676pru_send_notsupp(struct socket *so, int flags, struct mbuf *m, | 2614 return EOPNOTSUPP; 2615} 2616 2617int 2618pru_send_notsupp(struct socket *so, int flags, struct mbuf *m, |
2677 struct sockaddr *addr, struct mbuf *control, struct thread *td) | 2619 struct sockaddr *addr, struct mbuf *control, struct thread *td) |
2678{ | 2620{ |
2621 |
|
2679 return EOPNOTSUPP; 2680} 2681 2682/* 2683 * This isn't really a ``null'' operation, but it's the default one and 2684 * doesn't do anything destructive. 2685 */ 2686int 2687pru_sense_null(struct socket *so, struct stat *sb) 2688{ | 2622 return EOPNOTSUPP; 2623} 2624 2625/* 2626 * This isn't really a ``null'' operation, but it's the default one and 2627 * doesn't do anything destructive. 2628 */ 2629int 2630pru_sense_null(struct socket *so, struct stat *sb) 2631{ |
2632 |
|
2689 sb->st_blksize = so->so_snd.sb_hiwat; 2690 return 0; 2691} 2692 2693int 2694pru_shutdown_notsupp(struct socket *so) 2695{ | 2633 sb->st_blksize = so->so_snd.sb_hiwat; 2634 return 0; 2635} 2636 2637int 2638pru_shutdown_notsupp(struct socket *so) 2639{ |
2640 |
|
2696 return EOPNOTSUPP; 2697} 2698 2699int 2700pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam) 2701{ | 2641 return EOPNOTSUPP; 2642} 2643 2644int 2645pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam) 2646{ |
2647 |
|
2702 return EOPNOTSUPP; 2703} 2704 2705int 2706pru_sosend_notsupp(struct socket *so, struct sockaddr *addr, struct uio *uio, | 2648 return EOPNOTSUPP; 2649} 2650 2651int 2652pru_sosend_notsupp(struct socket *so, struct sockaddr *addr, struct uio *uio, |
2707 struct mbuf *top, struct mbuf *control, int flags, struct thread *td) | 2653 struct mbuf *top, struct mbuf *control, int flags, struct thread *td) |
2708{ | 2654{ |
2655 |
|
2709 return EOPNOTSUPP; 2710} 2711 2712int 2713pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr, | 2656 return EOPNOTSUPP; 2657} 2658 2659int 2660pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr, |
2714 struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, 2715 int *flagsp) | 2661 struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
2716{ | 2662{ |
2663 |
|
2717 return EOPNOTSUPP; 2718} 2719 2720int 2721pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred, | 2664 return EOPNOTSUPP; 2665} 2666 2667int 2668pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred, |
2722 struct thread *td) | 2669 struct thread *td) |
2723{ | 2670{ |
2671 |
|
2724 return EOPNOTSUPP; 2725} 2726 2727static void 2728filt_sordetach(struct knote *kn) 2729{ 2730 struct socket *so = kn->kn_fp->f_data; 2731 --- 129 unchanged lines hidden (view full) --- 2861 * 2862 * If a socket is closed with sockets on either so_incomp or so_comp, these 2863 * sockets are dropped. 2864 * 2865 * If higher-level protocols are implemented in the kernel, the wakeups done 2866 * here will sometimes cause software-interrupt process scheduling. 2867 */ 2868void | 2672 return EOPNOTSUPP; 2673} 2674 2675static void 2676filt_sordetach(struct knote *kn) 2677{ 2678 struct socket *so = kn->kn_fp->f_data; 2679 --- 129 unchanged lines hidden (view full) --- 2809 * 2810 * If a socket is closed with sockets on either so_incomp or so_comp, these 2811 * sockets are dropped. 2812 * 2813 * If higher-level protocols are implemented in the kernel, the wakeups done 2814 * here will sometimes cause software-interrupt process scheduling. 2815 */ 2816void |
2869soisconnecting(so) 2870 register struct socket *so; | 2817soisconnecting(struct socket *so) |
2871{ 2872 2873 SOCK_LOCK(so); 2874 so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING); 2875 so->so_state |= SS_ISCONNECTING; 2876 SOCK_UNLOCK(so); 2877} 2878 2879void | 2818{ 2819 2820 SOCK_LOCK(so); 2821 so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING); 2822 so->so_state |= SS_ISCONNECTING; 2823 SOCK_UNLOCK(so); 2824} 2825 2826void |
2880soisconnected(so) 2881 struct socket *so; | 2827soisconnected(struct socket *so) |
2882{ 2883 struct socket *head; 2884 2885 ACCEPT_LOCK(); 2886 SOCK_LOCK(so); 2887 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING); 2888 so->so_state |= SS_ISCONNECTED; 2889 head = so->so_head; --- 24 unchanged lines hidden (view full) --- 2914 SOCK_UNLOCK(so); 2915 ACCEPT_UNLOCK(); 2916 wakeup(&so->so_timeo); 2917 sorwakeup(so); 2918 sowwakeup(so); 2919} 2920 2921void | 2828{ 2829 struct socket *head; 2830 2831 ACCEPT_LOCK(); 2832 SOCK_LOCK(so); 2833 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING); 2834 so->so_state |= SS_ISCONNECTED; 2835 head = so->so_head; --- 24 unchanged lines hidden (view full) --- 2860 SOCK_UNLOCK(so); 2861 ACCEPT_UNLOCK(); 2862 wakeup(&so->so_timeo); 2863 sorwakeup(so); 2864 sowwakeup(so); 2865} 2866 2867void |
2922soisdisconnecting(so) 2923 register struct socket *so; | 2868soisdisconnecting(struct socket *so) |
2924{ 2925 2926 /* 2927 * Note: This code assumes that SOCK_LOCK(so) and 2928 * SOCKBUF_LOCK(&so->so_rcv) are the same. 2929 */ 2930 SOCKBUF_LOCK(&so->so_rcv); 2931 so->so_state &= ~SS_ISCONNECTING; 2932 so->so_state |= SS_ISDISCONNECTING; 2933 so->so_rcv.sb_state |= SBS_CANTRCVMORE; 2934 sorwakeup_locked(so); 2935 SOCKBUF_LOCK(&so->so_snd); 2936 so->so_snd.sb_state |= SBS_CANTSENDMORE; 2937 sowwakeup_locked(so); 2938 wakeup(&so->so_timeo); 2939} 2940 2941void | 2869{ 2870 2871 /* 2872 * Note: This code assumes that SOCK_LOCK(so) and 2873 * SOCKBUF_LOCK(&so->so_rcv) are the same. 2874 */ 2875 SOCKBUF_LOCK(&so->so_rcv); 2876 so->so_state &= ~SS_ISCONNECTING; 2877 so->so_state |= SS_ISDISCONNECTING; 2878 so->so_rcv.sb_state |= SBS_CANTRCVMORE; 2879 sorwakeup_locked(so); 2880 SOCKBUF_LOCK(&so->so_snd); 2881 so->so_snd.sb_state |= SBS_CANTSENDMORE; 2882 sowwakeup_locked(so); 2883 wakeup(&so->so_timeo); 2884} 2885 2886void |
2942soisdisconnected(so) 2943 register struct socket *so; | 2887soisdisconnected(struct socket *so) |
2944{ 2945 2946 /* 2947 * Note: This code assumes that SOCK_LOCK(so) and 2948 * SOCKBUF_LOCK(&so->so_rcv) are the same. 2949 */ 2950 SOCKBUF_LOCK(&so->so_rcv); 2951 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING); --- 27 unchanged lines hidden (view full) --- 2979 * reduce the spew of irrelevant information over this interface, to isolate 2980 * user code from changes in the kernel structure, and potentially to provide 2981 * information-hiding if we decide that some of this information should be 2982 * hidden from users. 2983 */ 2984void 2985sotoxsocket(struct socket *so, struct xsocket *xso) 2986{ | 2888{ 2889 2890 /* 2891 * Note: This code assumes that SOCK_LOCK(so) and 2892 * SOCKBUF_LOCK(&so->so_rcv) are the same. 2893 */ 2894 SOCKBUF_LOCK(&so->so_rcv); 2895 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING); --- 27 unchanged lines hidden (view full) --- 2923 * reduce the spew of irrelevant information over this interface, to isolate 2924 * user code from changes in the kernel structure, and potentially to provide 2925 * information-hiding if we decide that some of this information should be 2926 * hidden from users. 2927 */ 2928void 2929sotoxsocket(struct socket *so, struct xsocket *xso) 2930{ |
2931 |
|
2987 xso->xso_len = sizeof *xso; 2988 xso->xso_so = so; 2989 xso->so_type = so->so_type; 2990 xso->so_options = so->so_options; 2991 xso->so_linger = so->so_linger; 2992 xso->so_state = so->so_state; 2993 xso->so_pcb = so->so_pcb; 2994 xso->xso_protocol = so->so_proto->pr_protocol; --- 12 unchanged lines hidden --- | 2932 xso->xso_len = sizeof *xso; 2933 xso->xso_so = so; 2934 xso->so_type = so->so_type; 2935 xso->so_options = so->so_options; 2936 xso->so_linger = so->so_linger; 2937 xso->so_state = so->so_state; 2938 xso->so_pcb = so->so_pcb; 2939 xso->xso_protocol = so->so_proto->pr_protocol; --- 12 unchanged lines hidden --- |