xref: /titanic_50/usr/src/uts/common/inet/ip_impl.h (revision 71269a2275bf5a143dad6461eee2710a344e7261)
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 2008 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 
44 #define	IP_MOD_ID		5701
45 
46 #ifdef	_BIG_ENDIAN
47 #define	IP_HDR_CSUM_TTL_ADJUST	256
48 #define	IP_TCP_CSUM_COMP	IPPROTO_TCP
49 #define	IP_UDP_CSUM_COMP	IPPROTO_UDP
50 #else
51 #define	IP_HDR_CSUM_TTL_ADJUST	1
52 #define	IP_TCP_CSUM_COMP	(IPPROTO_TCP << 8)
53 #define	IP_UDP_CSUM_COMP	(IPPROTO_UDP << 8)
54 #endif
55 
56 #define	TCP_CHECKSUM_OFFSET	16
57 #define	TCP_CHECKSUM_SIZE	2
58 
59 #define	UDP_CHECKSUM_OFFSET	6
60 #define	UDP_CHECKSUM_SIZE	2
61 
62 #define	IPH_TCPH_CHECKSUMP(ipha, hlen)	\
63 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + TCP_CHECKSUM_OFFSET)))
64 
65 #define	IPH_UDPH_CHECKSUMP(ipha, hlen)	\
66 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + UDP_CHECKSUM_OFFSET)))
67 
68 #define	ILL_HCKSUM_CAPABLE(ill)		\
69 	(((ill)->ill_capabilities & ILL_CAPAB_HCKSUM) != 0)
70 /*
71  * Macro that performs software checksum calculation on the IP header.
72  */
73 #define	IP_HDR_CKSUM(ipha, sum, v_hlen_tos_len, ttl_protocol) {		\
74 	(sum) += (ttl_protocol) + (ipha)->ipha_ident +			\
75 	    ((v_hlen_tos_len) >> 16) +					\
76 	    ((v_hlen_tos_len) & 0xFFFF) +				\
77 	    (ipha)->ipha_fragment_offset_and_flags;			\
78 	(sum) = (((sum) & 0xFFFF) + ((sum) >> 16));			\
79 	(sum) = ~((sum) + ((sum) >> 16));				\
80 	(ipha)->ipha_hdr_checksum = (uint16_t)(sum);			\
81 }
82 
83 #define	IS_IP_HDR_HWCKSUM(ipsec, mp, ill)				\
84 	((!ipsec) && (DB_CKSUMFLAGS(mp) & HCK_IPV4_HDRCKSUM) &&		\
85 	ILL_HCKSUM_CAPABLE(ill) && dohwcksum)
86 
87 /*
88  * This macro acts as a wrapper around IP_CKSUM_XMIT_FAST, and it performs
89  * several checks on the IRE and ILL (among other things) in order to see
90  * whether or not hardware checksum offload is allowed for the outgoing
91  * packet.  It assumes that the caller has held a reference to the IRE.
92  */
93 #define	IP_CKSUM_XMIT(ill, ire, mp, ihp, up, proto, start, end,		\
94 	    max_frag, ipsec_len, pseudo) {				\
95 	uint32_t _hck_flags;						\
96 	/*								\
97 	 * We offload checksum calculation to hardware when IPsec isn't	\
98 	 * present and if fragmentation isn't required.  We also check	\
99 	 * if M_DATA fastpath is safe to be used on the	corresponding	\
100 	 * IRE; this check is performed without grabbing ire_lock but	\
101 	 * instead by holding a reference to it.  This is sufficient	\
102 	 * for IRE_CACHE; for IRE_BROADCAST on non-Ethernet links, the	\
103 	 * DL_NOTE_FASTPATH_FLUSH indication could come up from the	\
104 	 * driver and trigger the IRE (hence fp_mp) deletion.  This is	\
105 	 * why only IRE_CACHE type is eligible for offload.		\
106 	 *								\
107 	 * The presense of IP options also forces the network stack to	\
108 	 * calculate the checksum in software.  This is because:	\
109 	 *								\
110 	 * Wrap around: certain partial-checksum NICs (eri, ce) limit	\
111 	 * the size of "start offset" width to 6-bit.  This effectively	\
112 	 * sets the largest value of the offset to 64-bytes, starting	\
113 	 * from the MAC header.  When the cumulative MAC and IP headers	\
114 	 * exceed such limit, the offset will wrap around.  This causes	\
115 	 * the checksum to be calculated at the wrong place.		\
116 	 *								\
117 	 * IPv4 source routing: none of the full-checksum capable NICs	\
118 	 * is capable of correctly handling the	IPv4 source-routing	\
119 	 * option for purposes of calculating the pseudo-header; the	\
120 	 * actual destination is different from the destination in the	\
121 	 * header which is that of the next-hop.  (This case may not be	\
122 	 * true for NICs which can parse IPv6 extension headers, but	\
123 	 * we choose to simplify the implementation by not offloading	\
124 	 * checksum when they are present.)				\
125 	 *								\
126 	 */								\
127 	if ((ill) != NULL && ILL_HCKSUM_CAPABLE(ill) &&			\
128 	    !((ire)->ire_flags & RTF_MULTIRT) &&			\
129 	    (!((ire)->ire_type & IRE_BROADCAST) ||			\
130 	    (ill)->ill_type == IFT_ETHER) &&			\
131 	    (ipsec_len) == 0 &&						\
132 	    (((ire)->ire_ipversion == IPV4_VERSION &&			\
133 	    (start) == IP_SIMPLE_HDR_LENGTH &&				\
134 	    ((ire)->ire_nce != NULL &&					\
135 	    (ire)->ire_nce->nce_fp_mp != NULL &&	\
136 	    MBLKHEAD(mp) >= MBLKL((ire)->ire_nce->nce_fp_mp))) ||	\
137 	    ((ire)->ire_ipversion == IPV6_VERSION &&			\
138 	    (start) == IPV6_HDR_LEN &&					\
139 	    (ire)->ire_nce->nce_fp_mp != NULL &&			\
140 	    MBLKHEAD(mp) >= MBLKL((ire)->ire_nce->nce_fp_mp))) &&	\
141 	    (max_frag) >= (uint_t)((end) + (ipsec_len)) &&		\
142 	    dohwcksum) {						\
143 		_hck_flags = (ill)->ill_hcksum_capab->ill_hcksum_txflags; \
144 	} else {							\
145 		_hck_flags = 0;						\
146 	}								\
147 	IP_CKSUM_XMIT_FAST((ire)->ire_ipversion, _hck_flags, mp, ihp,	\
148 	    up, proto, start, end, pseudo);				\
149 }
150 
151 /*
152  * Based on the device capabilities, this macro either marks an outgoing
153  * packet with hardware checksum offload information or calculate the
154  * checksum in software.  If the latter is performed, the checksum field
155  * of the dblk is cleared; otherwise it will be non-zero and contain the
156  * necessary flag(s) for the driver.
157  */
158 #define	IP_CKSUM_XMIT_FAST(ipver, hck_flags, mp, ihp, up, proto, start,	\
159 	    end, pseudo) {						\
160 	uint32_t _sum;							\
161 	/*								\
162 	 * Underlying interface supports hardware checksum offload for	\
163 	 * the payload; leave the payload checksum for the hardware to	\
164 	 * calculate.  N.B: We only need to set up checksum info on the	\
165 	 * first mblk.							\
166 	 */								\
167 	DB_CKSUMFLAGS(mp) = 0;						\
168 	if (((ipver) == IPV4_VERSION &&					\
169 	    ((hck_flags) & HCKSUM_INET_FULL_V4)) ||			\
170 	    ((ipver) == IPV6_VERSION &&					\
171 	    ((hck_flags) & HCKSUM_INET_FULL_V6))) {			\
172 		/*							\
173 		 * Hardware calculates pseudo-header, header and the	\
174 		 * payload checksums, so clear the checksum field in	\
175 		 * the protocol header.					\
176 		 */							\
177 		*(up) = 0;						\
178 		DB_CKSUMFLAGS(mp) |= HCK_FULLCKSUM;			\
179 	} else if ((hck_flags) & HCKSUM_INET_PARTIAL)  {		\
180 		/*							\
181 		 * Partial checksum offload has been enabled.  Fill	\
182 		 * the checksum field in the protocl header with the	\
183 		 * pseudo-header checksum value.			\
184 		 */							\
185 		_sum = ((proto) == IPPROTO_UDP) ?			\
186 		    IP_UDP_CSUM_COMP : IP_TCP_CSUM_COMP;		\
187 		_sum += *(up) + (pseudo);				\
188 		_sum = (_sum & 0xFFFF) + (_sum >> 16);			\
189 		*(up) = (_sum & 0xFFFF) + (_sum >> 16);			\
190 		/*							\
191 		 * Offsets are relative to beginning of IP header.	\
192 		 */							\
193 		DB_CKSUMSTART(mp) = (start);				\
194 		DB_CKSUMSTUFF(mp) = ((proto) == IPPROTO_UDP) ?		\
195 		    (start) + UDP_CHECKSUM_OFFSET :			\
196 		    (start) + TCP_CHECKSUM_OFFSET;			\
197 		DB_CKSUMEND(mp) = (end);				\
198 		DB_CKSUMFLAGS(mp) |= HCK_PARTIALCKSUM;			\
199 	} else {							\
200 		/*							\
201 		 * Software checksumming.				\
202 		 */							\
203 		_sum = ((proto) == IPPROTO_UDP) ?			\
204 		    IP_UDP_CSUM_COMP : IP_TCP_CSUM_COMP;		\
205 		_sum += (pseudo);					\
206 		_sum = IP_CSUM(mp, start, _sum);			\
207 		*(up) = (uint16_t)(((proto) == IPPROTO_UDP) ?		\
208 		    (_sum ? _sum : ~_sum) : _sum);			\
209 	}								\
210 	/*								\
211 	 * Hardware supports IP header checksum offload; clear the	\
212 	 * contents of IP header checksum field as expected by NIC.	\
213 	 * Do this only if we offloaded either full or partial sum.	\
214 	 */								\
215 	if ((ipver) == IPV4_VERSION && DB_CKSUMFLAGS(mp) != 0 &&	\
216 	    ((hck_flags) & HCKSUM_IPHDRCKSUM)) {			\
217 		DB_CKSUMFLAGS(mp) |= HCK_IPV4_HDRCKSUM;			\
218 		((ipha_t *)(ihp))->ipha_hdr_checksum = 0;		\
219 	}								\
220 }
221 
222 /*
223  * Macro to inspect the checksum of a fully-reassembled incoming datagram.
224  */
225 #define	IP_CKSUM_RECV_REASS(hck_flags, off, pseudo, sum, err) {		\
226 	(err) = B_FALSE;						\
227 	if ((hck_flags) & HCK_FULLCKSUM) {				\
228 		/*							\
229 		 * The sum of all fragment checksums should		\
230 		 * result in -0 (0xFFFF) or otherwise invalid.		\
231 		 */							\
232 		if ((sum) != 0xFFFF)					\
233 			(err) = B_TRUE;					\
234 	} else if ((hck_flags) & HCK_PARTIALCKSUM) {			\
235 		(sum) += (pseudo);					\
236 		(sum) = ((sum) & 0xFFFF) + ((sum) >> 16);		\
237 		(sum) = ((sum) & 0xFFFF) + ((sum) >> 16);		\
238 		if (~(sum) & 0xFFFF)					\
239 			(err) = B_TRUE;					\
240 	} else if (((sum) = IP_CSUM(mp, off, pseudo)) != 0) {		\
241 		(err) = B_TRUE;						\
242 	}								\
243 }
244 
245 /*
246  * This macro inspects an incoming packet to see if the checksum value
247  * contained in it is valid; if the hardware has provided the information,
248  * the value is verified, otherwise it performs software checksumming.
249  * The checksum value is returned to caller.
250  */
251 #define	IP_CKSUM_RECV(hck_flags, sum, cksum_start, ulph_off, mp, mp1, err) { \
252 	int32_t _len;							\
253 									\
254 	(err) = B_FALSE;						\
255 	if ((hck_flags) & HCK_FULLCKSUM) {				\
256 		/*							\
257 		 * Full checksum has been computed by the hardware	\
258 		 * and has been attached.  If the driver wants us to	\
259 		 * verify the correctness of the attached value, in	\
260 		 * order to protect against faulty hardware, compare	\
261 		 * it against -0 (0xFFFF) to see if it's valid.		\
262 		 */							\
263 		(sum) = DB_CKSUM16(mp);					\
264 		if (!((hck_flags) & HCK_FULLCKSUM_OK) && (sum) != 0xFFFF) \
265 			(err) = B_TRUE;					\
266 	} else if (((hck_flags) & HCK_PARTIALCKSUM) &&			\
267 	    ((mp1) == NULL || (mp1)->b_cont == NULL) &&			\
268 	    (ulph_off) >= DB_CKSUMSTART(mp) &&				\
269 	    ((_len = (ulph_off) - DB_CKSUMSTART(mp)) & 1) == 0) {	\
270 		uint32_t _adj;						\
271 		/*							\
272 		 * Partial checksum has been calculated by hardware	\
273 		 * and attached to the packet; in addition, any		\
274 		 * prepended extraneous data is even byte aligned,	\
275 		 * and there are at most two mblks associated with	\
276 		 * the packet.  If any such data exists, we adjust	\
277 		 * the checksum; also take care any postpended data.	\
278 		 */							\
279 		IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, _len, _adj);	\
280 		/*							\
281 		 * One's complement subtract extraneous checksum	\
282 		 */							\
283 		(sum) += DB_CKSUM16(mp);				\
284 		if (_adj >= (sum))					\
285 			(sum) = ~(_adj - (sum)) & 0xFFFF;		\
286 		else							\
287 			(sum) -= _adj;					\
288 		(sum) = ((sum) & 0xFFFF) + ((int)(sum) >> 16);		\
289 		(sum) = ((sum) & 0xFFFF) + ((int)(sum) >> 16);		\
290 		if (~(sum) & 0xFFFF)					\
291 			(err) = B_TRUE;					\
292 	} else if (((sum) = IP_CSUM(mp, ulph_off, sum)) != 0) {		\
293 		(err) = B_TRUE;						\
294 	}								\
295 }
296 
297 /*
298  * Macro to adjust a given checksum value depending on any prepended
299  * or postpended data on the packet.  It expects the start offset to
300  * begin at an even boundary and that the packet consists of at most
301  * two mblks.
302  */
303 #define	IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj) {		\
304 	/*								\
305 	 * Prepended extraneous data; adjust checksum.			\
306 	 */								\
307 	if ((len) > 0)							\
308 		(adj) = IP_BCSUM_PARTIAL(cksum_start, len, 0);		\
309 	else								\
310 		(adj) = 0;						\
311 	/*								\
312 	 * len is now the total length of mblk(s)			\
313 	 */								\
314 	(len) = MBLKL(mp);						\
315 	if ((mp1) == NULL)						\
316 		(mp1) = (mp);						\
317 	else								\
318 		(len) += MBLKL(mp1);					\
319 	/*								\
320 	 * Postpended extraneous data; adjust checksum.			\
321 	 */								\
322 	if (((len) = (DB_CKSUMEND(mp) - len)) > 0) {			\
323 		uint32_t _pad;						\
324 									\
325 		_pad = IP_BCSUM_PARTIAL((mp1)->b_wptr, len, 0);		\
326 		/*							\
327 		 * If the postpended extraneous data was odd		\
328 		 * byte aligned, swap resulting checksum bytes.		\
329 		 */							\
330 		if ((uintptr_t)(mp1)->b_wptr & 1)			\
331 			(adj) += ((_pad << 8) & 0xFFFF) | (_pad >> 8);	\
332 		else							\
333 			(adj) += _pad;					\
334 		(adj) = ((adj) & 0xFFFF) + ((int)(adj) >> 16);		\
335 	}								\
336 }
337 
338 #define	ILL_MDT_CAPABLE(ill)		\
339 	(((ill)->ill_capabilities & ILL_CAPAB_MDT) != 0)
340 
341 /*
342  * ioctl identifier and structure for Multidata Transmit update
343  * private M_CTL communication from IP to ULP.
344  */
345 #define	MDT_IOC_INFO_UPDATE	(('M' << 8) + 1020)
346 
347 typedef struct ip_mdt_info_s {
348 	uint_t	mdt_info_id;	/* MDT_IOC_INFO_UPDATE */
349 	ill_mdt_capab_t	mdt_capab; /* ILL MDT capabilities */
350 } ip_mdt_info_t;
351 
352 /*
353  * Macro that determines whether or not a given ILL is allowed for MDT.
354  */
355 #define	ILL_MDT_USABLE(ill)						\
356 	(ILL_MDT_CAPABLE(ill) &&					\
357 	ill->ill_mdt_capab != NULL &&					\
358 	ill->ill_mdt_capab->ill_mdt_version == MDT_VERSION_2 &&		\
359 	ill->ill_mdt_capab->ill_mdt_on != 0)
360 
361 #define	ILL_LSO_CAPABLE(ill)		\
362 	(((ill)->ill_capabilities & ILL_CAPAB_LSO) != 0)
363 
364 /*
365  * ioctl identifier and structure for Large Segment Offload
366  * private M_CTL communication from IP to ULP.
367  */
368 #define	LSO_IOC_INFO_UPDATE	(('L' << 24) + ('S' << 16) + ('O' << 8))
369 
370 typedef struct ip_lso_info_s {
371 	uint_t	lso_info_id;	/* LSO_IOC_INFO_UPDATE */
372 	ill_lso_capab_t	lso_capab; /* ILL LSO capabilities */
373 } ip_lso_info_t;
374 
375 /*
376  * Macro that determines whether or not a given ILL is allowed for LSO.
377  */
378 #define	ILL_LSO_USABLE(ill)						\
379 	(ILL_LSO_CAPABLE(ill) &&					\
380 	ill->ill_lso_capab != NULL &&					\
381 	ill->ill_lso_capab->ill_lso_version == LSO_VERSION_1 &&		\
382 	ill->ill_lso_capab->ill_lso_on != 0)
383 
384 #define	ILL_LSO_TCP_USABLE(ill)						\
385 	(ILL_LSO_USABLE(ill) &&						\
386 	ill->ill_lso_capab->ill_lso_flags & LSO_TX_BASIC_TCP_IPV4)
387 
388 /*
389  * Macro that determines whether or not a given CONN may be considered
390  * for fast path prior to proceeding further with LSO or Multidata.
391  */
392 #define	CONN_IS_LSO_MD_FASTPATH(connp)	\
393 	((connp)->conn_dontroute == 0 &&	/* SO_DONTROUTE */	\
394 	!((connp)->conn_nexthop_set) &&		/* IP_NEXTHOP */	\
395 	(connp)->conn_nofailover_ill == NULL &&	/* IPIF_NOFAILOVER */	\
396 	(connp)->conn_outgoing_pill == NULL &&	/* IP{V6}_BOUND_PIF */	\
397 	(connp)->conn_outgoing_ill == NULL)	/* IP{V6}_BOUND_IF */
398 
399 /* Definitons for fragmenting IP packets using MDT. */
400 
401 /*
402  * Smaller and private version of pdescinfo_t used specifically for IP,
403  * which allows for only a single payload span per packet.
404  */
405 typedef struct ip_pdescinfo_s PDESCINFO_STRUCT(2)	ip_pdescinfo_t;
406 
407 /*
408  * Macro version of ip_can_frag_mdt() which avoids the function call if we
409  * only examine a single message block.
410  */
411 #define	IP_CAN_FRAG_MDT(mp, hdr_len, len)			\
412 	(((mp)->b_cont == NULL) ?				\
413 	(MBLKL(mp) >= ((hdr_len) + ip_wput_frag_mdt_min)) :	\
414 	ip_can_frag_mdt((mp), (hdr_len), (len)))
415 
416 /*
417  * Macro that determines whether or not a given IPC requires
418  * outbound IPSEC processing.
419  */
420 #define	CONN_IPSEC_OUT_ENCAPSULATED(connp)	\
421 	((connp)->conn_out_enforce_policy ||	\
422 	((connp)->conn_latch != NULL &&		\
423 	(connp)->conn_latch->ipl_out_policy != NULL))
424 
425 /*
426  * These are used by the synchronous streams code in tcp and udp.
427  * When we set the flags for a wakeup from a synchronous stream we
428  * always set RSLEEP in sd_wakeq, even if we have a read thread waiting
429  * to do the io. This is in case the read thread gets interrupted
430  * before completing the io. The RSLEEP flag in sd_wakeq is used to
431  * indicate that there is data available at the synchronous barrier.
432  * The assumption is that subsequent functions calls through rwnext()
433  * will reset sd_wakeq appropriately.
434  */
435 #define	STR_WAKEUP_CLEAR(stp) {						\
436 	mutex_enter(&stp->sd_lock);					\
437 	stp->sd_wakeq &= ~RSLEEP;					\
438 	mutex_exit(&stp->sd_lock);					\
439 }
440 
441 #define	STR_WAKEUP_SET(stp) {						\
442 	mutex_enter(&stp->sd_lock);					\
443 	if (stp->sd_flag & RSLEEP) {					\
444 		stp->sd_flag &= ~RSLEEP;				\
445 		cv_broadcast(&_RD(stp->sd_wrq)->q_wait);		\
446 	}								\
447 	stp->sd_wakeq |= RSLEEP;					\
448 	mutex_exit(&stp->sd_lock);					\
449 }
450 
451 /*
452  * Combined wakeup and sendsig to avoid dropping and reacquiring the
453  * sd_lock. The list of messages waiting at the synchronous barrier is
454  * supplied in order to determine whether a wakeup needs to occur. We
455  * only send a wakeup to the application when necessary, i.e. during
456  * the first enqueue when the received messages list will be NULL.
457  */
458 #define	STR_WAKEUP_SENDSIG(stp, rcv_list) {				\
459 	int _events;							\
460 	mutex_enter(&stp->sd_lock);					\
461 	if (rcv_list == NULL) {						\
462 		if (stp->sd_flag & RSLEEP) {				\
463 			stp->sd_flag &= ~RSLEEP;			\
464 			cv_broadcast(&_RD(stp->sd_wrq)->q_wait);	\
465 		}							\
466 		stp->sd_wakeq |= RSLEEP;				\
467 	}								\
468 	if ((_events = stp->sd_sigflags & (S_INPUT | S_RDNORM)) != 0)	\
469 		strsendsig(stp->sd_siglist, _events, 0, 0);		\
470 	if (stp->sd_rput_opt & SR_POLLIN) {				\
471 		stp->sd_rput_opt &= ~SR_POLLIN;				\
472 		mutex_exit(&stp->sd_lock);				\
473 		pollwakeup(&stp->sd_pollist, POLLIN | POLLRDNORM);	\
474 	} else {							\
475 		mutex_exit(&stp->sd_lock);				\
476 	}								\
477 }
478 
479 #define	CONN_UDP_SYNCSTR(connp)						\
480 	(IPCL_IS_UDP(connp) && (connp)->conn_udp->udp_direct_sockfs)
481 
482 /*
483  * Macro that checks whether or not a particular UDP conn is
484  * flow-controlling on the read-side.  If udp module is directly
485  * above ip, check to see if the drain queue is full; note here
486  * that we check this without any lock protection because this
487  * is a coarse granularity inbound flow-control.  If the module
488  * above ip is not udp, then use canputnext to determine the
489  * flow-control.
490  *
491  * Note that these checks are done after the conn is found in
492  * the UDP fanout table.
493  * FIXME? Might be faster to check both udp_drain_qfull and canputnext.
494  */
495 #define	CONN_UDP_FLOWCTLD(connp)					\
496 	(CONN_UDP_SYNCSTR(connp) ?					\
497 	(connp)->conn_udp->udp_drain_qfull :				\
498 	!canputnext((connp)->conn_rq))
499 
500 #define	ILL_DLS_CAPABLE(ill)	\
501 	(((ill)->ill_capabilities &		\
502 	(ILL_CAPAB_POLL|ILL_CAPAB_SOFT_RING)) != 0)
503 
504 /*
505  * Macro that hands off one or more messages directly to DLD
506  * when the interface is marked with ILL_CAPAB_POLL.
507  */
508 #define	IP_DLS_ILL_TX(ill, ipha, mp, ipst, hlen) {			\
509 	ill_dls_capab_t *ill_dls = ill->ill_dls_capab;			\
510 	ASSERT(ILL_DLS_CAPABLE(ill));					\
511 	ASSERT(ill_dls != NULL);					\
512 	ASSERT(ill_dls->ill_tx != NULL);				\
513 	ASSERT(ill_dls->ill_tx_handle != NULL);				\
514 	DTRACE_PROBE4(ip4__physical__out__start,			\
515 	    ill_t *, NULL, ill_t *, ill,				\
516 	    ipha_t *, ipha, mblk_t *, mp);				\
517 	FW_HOOKS(ipst->ips_ip4_physical_out_event,			\
518 	    ipst->ips_ipv4firewall_physical_out,			\
519 	    NULL, ill, ipha, mp, mp, 0, ipst);				\
520 	DTRACE_PROBE1(ip4__physical__out__end, mblk_t *, mp);		\
521 	if (mp != NULL) {						\
522 		if (ipst->ips_ipobs_enabled) {				\
523 			zoneid_t szone;					\
524 									\
525 			szone = ip_get_zoneid_v4(ipha->ipha_src, mp,	\
526 			    ipst, ALL_ZONES);				\
527 			ipobs_hook(mp, IPOBS_HOOK_OUTBOUND, szone,	\
528 			    ALL_ZONES, ill, IPV4_VERSION, hlen, ipst);	\
529 		}							\
530 		DTRACE_IP7(send, mblk_t *, mp, conn_t *, NULL,		\
531 		    void_ip_t *, ipha, __dtrace_ipsr_ill_t *, ill,	\
532 		    ipha_t *, ipha, ip6_t *, NULL, int,	0);		\
533 		ill_dls->ill_tx(ill_dls->ill_tx_handle, mp);		\
534 	}								\
535 }
536 
537 /*
538  * In non-global zone exclusive IP stacks, data structures such as IRE
539  * entries pretend that they're in the global zone.  The following
540  * macro evaluates to the real zoneid instead of a pretend
541  * GLOBAL_ZONEID.
542  */
543 #define	IP_REAL_ZONEID(zoneid, ipst)					\
544 	(((zoneid) == GLOBAL_ZONEID) ?					\
545 	    netstackid_to_zoneid((ipst)->ips_netstack->netstack_stackid) : \
546 	    (zoneid))
547 
548 extern int	ip_wput_frag_mdt_min;
549 extern boolean_t ip_can_frag_mdt(mblk_t *, ssize_t, ssize_t);
550 extern mblk_t   *ip_prepend_zoneid(mblk_t *, zoneid_t, ip_stack_t *);
551 extern zoneid_t	ip_get_zoneid_v4(ipaddr_t, mblk_t *, ip_stack_t *, zoneid_t);
552 extern zoneid_t	ip_get_zoneid_v6(in6_addr_t *, mblk_t *, const ill_t *,
553     ip_stack_t *, zoneid_t);
554 
555 #endif	/* _KERNEL */
556 
557 #ifdef	__cplusplus
558 }
559 #endif
560 
561 #endif	/* _INET_IP_IMPL_H */
562