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