xref: /titanic_41/usr/src/uts/common/inet/ip_impl.h (revision 96d9f183facd90dbbc2268c9a51689be0b6a0b46)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_IP_IMPL_H
27 #define	_INET_IP_IMPL_H
28 
29 /*
30  * IP implementation private declarations.  These interfaces are
31  * used to build the IP module and are not meant to be accessed
32  * by any modules except IP itself.  They are undocumented and are
33  * subject to change without notice.
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 #include <sys/sdt.h>
43 #include <sys/dld.h>
44 
45 #define	IP_MOD_ID		5701
46 
47 #define	INET_NAME	"ip"
48 
49 #ifdef	_BIG_ENDIAN
50 #define	IP_HDR_CSUM_TTL_ADJUST	256
51 #define	IP_TCP_CSUM_COMP	IPPROTO_TCP
52 #define	IP_UDP_CSUM_COMP	IPPROTO_UDP
53 #define	IP_ICMPV6_CSUM_COMP	IPPROTO_ICMPV6
54 #else
55 #define	IP_HDR_CSUM_TTL_ADJUST	1
56 #define	IP_TCP_CSUM_COMP	(IPPROTO_TCP << 8)
57 #define	IP_UDP_CSUM_COMP	(IPPROTO_UDP << 8)
58 #define	IP_ICMPV6_CSUM_COMP	(IPPROTO_ICMPV6 << 8)
59 #endif
60 
61 #define	TCP_CHECKSUM_OFFSET	16
62 #define	TCP_CHECKSUM_SIZE	2
63 
64 #define	UDP_CHECKSUM_OFFSET	6
65 #define	UDP_CHECKSUM_SIZE	2
66 
67 #define	ICMPV6_CHECKSUM_OFFSET	2
68 #define	ICMPV6_CHECKSUM_SIZE	2
69 
70 #define	IPH_TCPH_CHECKSUMP(ipha, hlen)	\
71 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + TCP_CHECKSUM_OFFSET)))
72 
73 #define	IPH_UDPH_CHECKSUMP(ipha, hlen)	\
74 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + UDP_CHECKSUM_OFFSET)))
75 
76 #define	IPH_ICMPV6_CHECKSUMP(ipha, hlen)	\
77 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + ICMPV6_CHECKSUM_OFFSET)))
78 
79 #define	ILL_HCKSUM_CAPABLE(ill)		\
80 	(((ill)->ill_capabilities & ILL_CAPAB_HCKSUM) != 0)
81 
82 /*
83  * Macro to adjust a given checksum value depending on any prepended
84  * or postpended data on the packet.  It expects the start offset to
85  * begin at an even boundary and that the packet consists of at most
86  * two mblks.
87  */
88 #define	IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj) {		\
89 	/*								\
90 	 * Prepended extraneous data; adjust checksum.			\
91 	 */								\
92 	if ((len) > 0)							\
93 		(adj) = IP_BCSUM_PARTIAL(cksum_start, len, 0);		\
94 	else								\
95 		(adj) = 0;						\
96 	/*								\
97 	 * len is now the total length of mblk(s)			\
98 	 */								\
99 	(len) = MBLKL(mp);						\
100 	if ((mp1) == NULL)						\
101 		(mp1) = (mp);						\
102 	else								\
103 		(len) += MBLKL(mp1);					\
104 	/*								\
105 	 * Postpended extraneous data; adjust checksum.			\
106 	 */								\
107 	if (((len) = (DB_CKSUMEND(mp) - len)) > 0) {			\
108 		uint32_t _pad;						\
109 									\
110 		_pad = IP_BCSUM_PARTIAL((mp1)->b_wptr, len, 0);		\
111 		/*							\
112 		 * If the postpended extraneous data was odd		\
113 		 * byte aligned, swap resulting checksum bytes.		\
114 		 */							\
115 		if ((uintptr_t)(mp1)->b_wptr & 1)			\
116 			(adj) += ((_pad << 8) & 0xFFFF) | (_pad >> 8);	\
117 		else							\
118 			(adj) += _pad;					\
119 		(adj) = ((adj) & 0xFFFF) + ((int)(adj) >> 16);		\
120 	}								\
121 }
122 
123 #define	IS_SIMPLE_IPH(ipha)						\
124 	((ipha)->ipha_version_and_hdr_length == IP_SIMPLE_HDR_VERSION)
125 
126 /*
127  * Currently supported flags for LSO.
128  */
129 #define	LSO_BASIC_TCP_IPV4	DLD_LSO_BASIC_TCP_IPV4
130 #define	LSO_BASIC_TCP_IPV6	DLD_LSO_BASIC_TCP_IPV6
131 
132 #define	ILL_LSO_CAPABLE(ill)						\
133 	(((ill)->ill_capabilities & ILL_CAPAB_LSO) != 0)
134 
135 #define	ILL_LSO_USABLE(ill)						\
136 	(ILL_LSO_CAPABLE(ill) &&					\
137 	ill->ill_lso_capab != NULL)
138 
139 #define	ILL_LSO_TCP_IPV4_USABLE(ill)					\
140 	(ILL_LSO_USABLE(ill) &&						\
141 	ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV4)
142 
143 #define	ILL_LSO_TCP_IPV6_USABLE(ill)					\
144 	(ILL_LSO_USABLE(ill) &&						\
145 	ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV6)
146 
147 #define	ILL_ZCOPY_CAPABLE(ill)						\
148 	(((ill)->ill_capabilities & ILL_CAPAB_ZEROCOPY) != 0)
149 
150 #define	ILL_ZCOPY_USABLE(ill)						\
151 	(ILL_ZCOPY_CAPABLE(ill) && (ill->ill_zerocopy_capab != NULL) &&	\
152 	(ill->ill_zerocopy_capab->ill_zerocopy_flags != 0))
153 
154 
155 /* Macro that follows definitions of flags for mac_tx() (see mac_client.h) */
156 #define	IP_DROP_ON_NO_DESC	0x01	/* Equivalent to MAC_DROP_ON_NO_DESC */
157 
158 #define	ILL_DIRECT_CAPABLE(ill)						\
159 	(((ill)->ill_capabilities & ILL_CAPAB_DLD_DIRECT) != 0)
160 
161 /* This macro is used by the mac layer */
162 #define	MBLK_RX_FANOUT_SLOWPATH(mp, ipha)				\
163 	(DB_TYPE(mp) != M_DATA || DB_REF(mp) != 1 || !OK_32PTR(ipha) || \
164 	(((uchar_t *)ipha + IP_SIMPLE_HDR_LENGTH) >= (mp)->b_wptr))
165 
166 /*
167  * In non-global zone exclusive IP stacks, data structures such as IRE
168  * entries pretend that they're in the global zone.  The following
169  * macro evaluates to the real zoneid instead of a pretend
170  * GLOBAL_ZONEID.
171  */
172 #define	IP_REAL_ZONEID(zoneid, ipst)					\
173 	(((zoneid) == GLOBAL_ZONEID) ?					\
174 	    netstackid_to_zoneid((ipst)->ips_netstack->netstack_stackid) : \
175 	    (zoneid))
176 
177 extern void ill_flow_enable(void *, ip_mac_tx_cookie_t);
178 extern zoneid_t	ip_get_zoneid_v4(ipaddr_t, mblk_t *, ip_recv_attr_t *,
179     zoneid_t);
180 extern zoneid_t	ip_get_zoneid_v6(in6_addr_t *, mblk_t *, const ill_t *,
181     ip_recv_attr_t *, zoneid_t);
182 
183 /*
184  * flag passed in by IP based protocols to get a private ip stream with
185  * no conn_t. Note this flag has the same value as SO_FALLBACK
186  */
187 #define	IP_HELPER_STR	SO_FALLBACK
188 
189 #define	IP_MOD_MINPSZ	1
190 #define	IP_MOD_MAXPSZ	INFPSZ
191 #define	IP_MOD_HIWAT	65536
192 #define	IP_MOD_LOWAT	1024
193 
194 #define	DEV_IP	"/devices/pseudo/ip@0:ip"
195 #define	DEV_IP6	"/devices/pseudo/ip6@0:ip6"
196 
197 #endif	/* _KERNEL */
198 
199 #ifdef	__cplusplus
200 }
201 #endif
202 
203 #endif	/* _INET_IP_IMPL_H */
204