xref: /illumos-gate/usr/src/uts/common/inet/tcp_cluster.h (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_TCP_CLUSTER_H
27 #define	_INET_TCP_CLUSTER_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef _KERNEL
34 
35 /*
36  * Cluster hooks defined in tcp_cluster.c.
37  */
38 extern void (*cl_inet_listen)(netstackid_t, uint8_t, sa_family_t, uint8_t *,
39     in_port_t, void *);
40 extern void (*cl_inet_unlisten)(netstackid_t, uint8_t, sa_family_t, uint8_t *,
41     in_port_t, void *);
42 extern int (*cl_inet_connect2)(netstackid_t, uint8_t, boolean_t, sa_family_t,
43     uint8_t *, in_port_t, uint8_t *, in_port_t, void *);
44 extern void (*cl_inet_disconnect)(netstackid_t, uint8_t, sa_family_t,
45     uint8_t *, in_port_t, uint8_t *, in_port_t, void *);
46 
47 
48 /*
49  * Cluster networking hook for traversing current connection list.
50  * This routine is used to extract the current list of live connections
51  * which must continue to to be dispatched to this node.
52  */
53 extern int cl_tcp_walk_list(netstackid_t,
54     int (*callback)(cl_tcp_info_t *, void *), void *);
55 
56 /*
57  * int CL_INET_CONNECT(conn_t *cp, tcp_t *tcp, boolean_t is_outgoing, int err)
58  */
59 #define	CL_INET_CONNECT(connp, is_outgoing, err) {		\
60 	(err) = 0;						\
61 	if (cl_inet_connect2 != NULL) {				\
62 		/*						\
63 		 * Running in cluster mode - register active connection	\
64 		 * information						\
65 		 */							\
66 		if ((connp)->conn_ipversion == IPV4_VERSION) {		\
67 			if ((connp)->conn_laddr_v4 != 0) {		\
68 				(err) = (*cl_inet_connect2)(		\
69 				    (connp)->conn_netstack->netstack_stackid,\
70 				    IPPROTO_TCP, is_outgoing, AF_INET,	\
71 				    (uint8_t *)(&((connp)->conn_laddr_v4)),\
72 				    (in_port_t)(connp)->conn_lport,	\
73 				    (uint8_t *)(&((connp)->conn_faddr_v4)),\
74 				    (in_port_t)(connp)->conn_fport, NULL); \
75 			}						\
76 		} else {						\
77 			if (!IN6_IS_ADDR_UNSPECIFIED(			\
78 			    &(connp)->conn_laddr_v6)) {			\
79 				(err) = (*cl_inet_connect2)(		\
80 				    (connp)->conn_netstack->netstack_stackid,\
81 				    IPPROTO_TCP, is_outgoing, AF_INET6,	\
82 				    (uint8_t *)(&((connp)->conn_laddr_v6)),\
83 				    (in_port_t)(connp)->conn_lport,	\
84 				    (uint8_t *)(&((connp)->conn_faddr_v6)), \
85 				    (in_port_t)(connp)->conn_fport, NULL); \
86 			}						\
87 		}							\
88 	}								\
89 }
90 
91 #define	CL_INET_DISCONNECT(connp)	{				\
92 	if (cl_inet_disconnect != NULL) {				\
93 		/*							\
94 		 * Running in cluster mode - deregister active		\
95 		 * connection information				\
96 		 */							\
97 		if ((connp)->conn_ipversion == IPV4_VERSION) {		\
98 			if ((connp)->conn_laddr_v4 != 0) {		\
99 				(*cl_inet_disconnect)(			\
100 				    (connp)->conn_netstack->netstack_stackid,\
101 				    IPPROTO_TCP, AF_INET,		\
102 				    (uint8_t *)(&((connp)->conn_laddr_v4)),\
103 				    (in_port_t)(connp)->conn_lport,	\
104 				    (uint8_t *)(&((connp)->conn_faddr_v4)),\
105 				    (in_port_t)(connp)->conn_fport, NULL); \
106 			}						\
107 		} else {						\
108 			if (!IN6_IS_ADDR_UNSPECIFIED(			\
109 			    &(connp)->conn_laddr_v6)) {			\
110 				(*cl_inet_disconnect)(			\
111 				    (connp)->conn_netstack->netstack_stackid,\
112 				    IPPROTO_TCP, AF_INET6,		\
113 				    (uint8_t *)(&((connp)->conn_laddr_v6)),\
114 				    (in_port_t)(connp)->conn_lport,	\
115 				    (uint8_t *)(&((connp)->conn_faddr_v6)), \
116 				    (in_port_t)(connp)->conn_fport, NULL); \
117 			}						\
118 		}							\
119 	}								\
120 }
121 
122 #endif	/* _KERNEL */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _INET_TCP_CLUSTER_H */
129