37 #include <sys/tihdr.h>
38 #include <sys/timod.h>
39 #include <sys/tpicommon.h>
40 #include <sys/socketvar.h>
41
42 #include <inet/common.h>
43 #include <inet/proto_set.h>
44 #include <inet/ip.h>
45 #include <inet/tcp.h>
46 #include <inet/tcp_impl.h>
47
48 static void tcp_activate(sock_lower_handle_t, sock_upper_handle_t,
49 sock_upcalls_t *, int, cred_t *);
50 static int tcp_accept(sock_lower_handle_t, sock_lower_handle_t,
51 sock_upper_handle_t, cred_t *);
52 static int tcp_bind(sock_lower_handle_t, struct sockaddr *,
53 socklen_t, cred_t *);
54 static int tcp_listen(sock_lower_handle_t, int, cred_t *);
55 static int tcp_connect(sock_lower_handle_t, const struct sockaddr *,
56 socklen_t, sock_connid_t *, cred_t *);
57 static int tcp_getsockopt(sock_lower_handle_t, int, int, void *,
58 socklen_t *, cred_t *);
59 static int tcp_setsockopt(sock_lower_handle_t, int, int, const void *,
60 socklen_t, cred_t *);
61 static int tcp_sendmsg(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
62 cred_t *cr);
63 static int tcp_shutdown(sock_lower_handle_t, int, cred_t *);
64 static void tcp_clr_flowctrl(sock_lower_handle_t);
65 static int tcp_ioctl(sock_lower_handle_t, int, intptr_t, int, int32_t *,
66 cred_t *);
67 static int tcp_close(sock_lower_handle_t, int, cred_t *);
68
69 sock_downcalls_t sock_tcp_downcalls = {
70 tcp_activate,
71 tcp_accept,
72 tcp_bind,
73 tcp_listen,
74 tcp_connect,
75 tcp_getpeername,
76 tcp_getsockname,
77 tcp_getsockopt,
78 tcp_setsockopt,
79 tcp_sendmsg,
80 NULL,
81 NULL,
82 NULL,
735 * We can't assert the references because there might be other
736 * transient reference places because of some walkers or queued
737 * packets in squeue for the timewait state.
738 */
739 CONN_DEC_REF(connp);
740
741 /*
742 * EINPROGRESS tells sockfs to wait for a 'closed' upcall before
743 * freeing the socket.
744 */
745 return (EINPROGRESS);
746 }
747
748 /* ARGSUSED */
749 sock_lower_handle_t
750 tcp_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls,
751 uint_t *smodep, int *errorp, int flags, cred_t *credp)
752 {
753 conn_t *connp;
754 boolean_t isv6 = family == AF_INET6;
755 if (type != SOCK_STREAM || (family != AF_INET && family != AF_INET6) ||
756 (proto != 0 && proto != IPPROTO_TCP)) {
757 *errorp = EPROTONOSUPPORT;
758 return (NULL);
759 }
760
761 connp = tcp_create_common(credp, isv6, B_TRUE, errorp);
762 if (connp == NULL) {
763 return (NULL);
764 }
765
766 /*
767 * Put the ref for TCP. Ref for IP was already put
768 * by ipcl_conn_create. Also Make the conn_t globally
769 * visible to walkers
770 */
771 mutex_enter(&connp->conn_lock);
772 CONN_INC_REF_LOCKED(connp);
773 ASSERT(connp->conn_ref == 2);
774 connp->conn_state_flags &= ~CONN_INCIPIENT;
775
776 connp->conn_flags |= IPCL_NONSTR;
777 mutex_exit(&connp->conn_lock);
778
779 ASSERT(errorp != NULL);
780 *errorp = 0;
781 *sock_downcalls = &sock_tcp_downcalls;
782 *smodep = SM_CONNREQUIRED | SM_EXDATA | SM_ACCEPTSUPP |
783 SM_SENDFILESUPP;
784
785 return ((sock_lower_handle_t)connp);
786 }
787
788 /*
789 * tcp_fallback
|
37 #include <sys/tihdr.h>
38 #include <sys/timod.h>
39 #include <sys/tpicommon.h>
40 #include <sys/socketvar.h>
41
42 #include <inet/common.h>
43 #include <inet/proto_set.h>
44 #include <inet/ip.h>
45 #include <inet/tcp.h>
46 #include <inet/tcp_impl.h>
47
48 static void tcp_activate(sock_lower_handle_t, sock_upper_handle_t,
49 sock_upcalls_t *, int, cred_t *);
50 static int tcp_accept(sock_lower_handle_t, sock_lower_handle_t,
51 sock_upper_handle_t, cred_t *);
52 static int tcp_bind(sock_lower_handle_t, struct sockaddr *,
53 socklen_t, cred_t *);
54 static int tcp_listen(sock_lower_handle_t, int, cred_t *);
55 static int tcp_connect(sock_lower_handle_t, const struct sockaddr *,
56 socklen_t, sock_connid_t *, cred_t *);
57 static int tcp_getpeername(sock_lower_handle_t, struct sockaddr *,
58 socklen_t *, cred_t *);
59 static int tcp_getsockname(sock_lower_handle_t, struct sockaddr *,
60 socklen_t *, cred_t *);
61 static int tcp_getsockopt(sock_lower_handle_t, int, int, void *,
62 socklen_t *, cred_t *);
63 static int tcp_setsockopt(sock_lower_handle_t, int, int, const void *,
64 socklen_t, cred_t *);
65 static int tcp_sendmsg(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
66 cred_t *);
67 static int tcp_shutdown(sock_lower_handle_t, int, cred_t *);
68 static void tcp_clr_flowctrl(sock_lower_handle_t);
69 static int tcp_ioctl(sock_lower_handle_t, int, intptr_t, int, int32_t *,
70 cred_t *);
71 static int tcp_close(sock_lower_handle_t, int, cred_t *);
72
73 sock_downcalls_t sock_tcp_downcalls = {
74 tcp_activate,
75 tcp_accept,
76 tcp_bind,
77 tcp_listen,
78 tcp_connect,
79 tcp_getpeername,
80 tcp_getsockname,
81 tcp_getsockopt,
82 tcp_setsockopt,
83 tcp_sendmsg,
84 NULL,
85 NULL,
86 NULL,
739 * We can't assert the references because there might be other
740 * transient reference places because of some walkers or queued
741 * packets in squeue for the timewait state.
742 */
743 CONN_DEC_REF(connp);
744
745 /*
746 * EINPROGRESS tells sockfs to wait for a 'closed' upcall before
747 * freeing the socket.
748 */
749 return (EINPROGRESS);
750 }
751
752 /* ARGSUSED */
753 sock_lower_handle_t
754 tcp_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls,
755 uint_t *smodep, int *errorp, int flags, cred_t *credp)
756 {
757 conn_t *connp;
758 boolean_t isv6 = family == AF_INET6;
759
760 if (type != SOCK_STREAM || (family != AF_INET && family != AF_INET6) ||
761 (proto != 0 && proto != IPPROTO_TCP)) {
762 *errorp = EPROTONOSUPPORT;
763 return (NULL);
764 }
765
766 connp = tcp_create_common(credp, isv6, B_TRUE, errorp);
767 if (connp == NULL) {
768 return (NULL);
769 }
770
771 /*
772 * Put the ref for TCP. Ref for IP was already put
773 * by ipcl_conn_create. Also make the conn_t globally
774 * visible to walkers.
775 */
776 mutex_enter(&connp->conn_lock);
777 CONN_INC_REF_LOCKED(connp);
778 ASSERT(connp->conn_ref == 2);
779 connp->conn_state_flags &= ~CONN_INCIPIENT;
780
781 connp->conn_flags |= IPCL_NONSTR;
782 mutex_exit(&connp->conn_lock);
783
784 ASSERT(errorp != NULL);
785 *errorp = 0;
786 *sock_downcalls = &sock_tcp_downcalls;
787 *smodep = SM_CONNREQUIRED | SM_EXDATA | SM_ACCEPTSUPP |
788 SM_SENDFILESUPP;
789
790 return ((sock_lower_handle_t)connp);
791 }
792
793 /*
794 * tcp_fallback
|