xref: /illumos-gate/usr/src/uts/common/inet/ip_impl.h (revision c61a1653)
1ff550d0eSmasputra /*
2ff550d0eSmasputra  * CDDL HEADER START
3ff550d0eSmasputra  *
4ff550d0eSmasputra  * The contents of this file are subject to the terms of the
5592d29abSja  * Common Development and Distribution License (the "License").
6592d29abSja  * You may not use this file except in compliance with the License.
7ff550d0eSmasputra  *
8ff550d0eSmasputra  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ff550d0eSmasputra  * or http://www.opensolaris.org/os/licensing.
10ff550d0eSmasputra  * See the License for the specific language governing permissions
11ff550d0eSmasputra  * and limitations under the License.
12ff550d0eSmasputra  *
13ff550d0eSmasputra  * When distributing Covered Code, include this CDDL HEADER in each
14ff550d0eSmasputra  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ff550d0eSmasputra  * If applicable, add the following below this CDDL HEADER, with the
16ff550d0eSmasputra  * fields enclosed by brackets "[]" replaced with your own identifying
17ff550d0eSmasputra  * information: Portions Copyright [yyyy] [name of copyright owner]
18ff550d0eSmasputra  *
19ff550d0eSmasputra  * CDDL HEADER END
20ff550d0eSmasputra  */
21ff550d0eSmasputra /*
226e91bba0SGirish Moodalbail  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23ff550d0eSmasputra  * Use is subject to license terms.
24*c61a1653SRyan Zezeski  * Copyright 2019 Joyent, Inc.
25ff550d0eSmasputra  */
26ff550d0eSmasputra 
27ff550d0eSmasputra #ifndef	_INET_IP_IMPL_H
28ff550d0eSmasputra #define	_INET_IP_IMPL_H
29ff550d0eSmasputra 
30ff550d0eSmasputra /*
31ff550d0eSmasputra  * IP implementation private declarations.  These interfaces are
32ff550d0eSmasputra  * used to build the IP module and are not meant to be accessed
33ff550d0eSmasputra  * by any modules except IP itself.  They are undocumented and are
34ff550d0eSmasputra  * subject to change without notice.
35ff550d0eSmasputra  */
36ff550d0eSmasputra 
37ff550d0eSmasputra #ifdef	__cplusplus
38ff550d0eSmasputra extern "C" {
39ff550d0eSmasputra #endif
40ff550d0eSmasputra 
41ff550d0eSmasputra #ifdef _KERNEL
42ff550d0eSmasputra 
43381a2a9aSdr #include <sys/sdt.h>
44da14cebeSEric Cheng #include <sys/dld.h>
456e91bba0SGirish Moodalbail #include <inet/tunables.h>
46381a2a9aSdr 
47ff550d0eSmasputra #define	IP_MOD_ID		5701
48ff550d0eSmasputra 
490f1702c5SYu Xiangning #define	INET_NAME	"ip"
500f1702c5SYu Xiangning 
51ff550d0eSmasputra #ifdef	_BIG_ENDIAN
52ff550d0eSmasputra #define	IP_HDR_CSUM_TTL_ADJUST	256
53ff550d0eSmasputra #define	IP_TCP_CSUM_COMP	IPPROTO_TCP
54ff550d0eSmasputra #define	IP_UDP_CSUM_COMP	IPPROTO_UDP
55bd670b35SErik Nordmark #define	IP_ICMPV6_CSUM_COMP	IPPROTO_ICMPV6
56ff550d0eSmasputra #else
57ff550d0eSmasputra #define	IP_HDR_CSUM_TTL_ADJUST	1
58ff550d0eSmasputra #define	IP_TCP_CSUM_COMP	(IPPROTO_TCP << 8)
59ff550d0eSmasputra #define	IP_UDP_CSUM_COMP	(IPPROTO_UDP << 8)
60bd670b35SErik Nordmark #define	IP_ICMPV6_CSUM_COMP	(IPPROTO_ICMPV6 << 8)
61ff550d0eSmasputra #endif
62ff550d0eSmasputra 
63ff550d0eSmasputra #define	TCP_CHECKSUM_OFFSET	16
64ff550d0eSmasputra #define	TCP_CHECKSUM_SIZE	2
65ff550d0eSmasputra 
66ff550d0eSmasputra #define	UDP_CHECKSUM_OFFSET	6
67ff550d0eSmasputra #define	UDP_CHECKSUM_SIZE	2
68ff550d0eSmasputra 
69bd670b35SErik Nordmark #define	ICMPV6_CHECKSUM_OFFSET	2
70bd670b35SErik Nordmark #define	ICMPV6_CHECKSUM_SIZE	2
71bd670b35SErik Nordmark 
72ff550d0eSmasputra #define	IPH_TCPH_CHECKSUMP(ipha, hlen)	\
73ff550d0eSmasputra 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + TCP_CHECKSUM_OFFSET)))
74ff550d0eSmasputra 
75ff550d0eSmasputra #define	IPH_UDPH_CHECKSUMP(ipha, hlen)	\
76ff550d0eSmasputra 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + UDP_CHECKSUM_OFFSET)))
77ff550d0eSmasputra 
78bd670b35SErik Nordmark #define	IPH_ICMPV6_CHECKSUMP(ipha, hlen)	\
79bd670b35SErik Nordmark 	((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + ICMPV6_CHECKSUM_OFFSET)))
80bd670b35SErik Nordmark 
81ff550d0eSmasputra #define	ILL_HCKSUM_CAPABLE(ill)		\
82ff550d0eSmasputra 	(((ill)->ill_capabilities & ILL_CAPAB_HCKSUM) != 0)
83ff550d0eSmasputra 
84ff550d0eSmasputra /*
85ff550d0eSmasputra  * Macro to adjust a given checksum value depending on any prepended
86ff550d0eSmasputra  * or postpended data on the packet.  It expects the start offset to
87ff550d0eSmasputra  * begin at an even boundary and that the packet consists of at most
88ff550d0eSmasputra  * two mblks.
89ff550d0eSmasputra  */
90ff550d0eSmasputra #define	IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj) {		\
91ff550d0eSmasputra 	/*								\
92ff550d0eSmasputra 	 * Prepended extraneous data; adjust checksum.			\
93ff550d0eSmasputra 	 */								\
94ff550d0eSmasputra 	if ((len) > 0)							\
95ff550d0eSmasputra 		(adj) = IP_BCSUM_PARTIAL(cksum_start, len, 0);		\
96ff550d0eSmasputra 	else								\
97ff550d0eSmasputra 		(adj) = 0;						\
98ff550d0eSmasputra 	/*								\
99ff550d0eSmasputra 	 * len is now the total length of mblk(s)			\
100ff550d0eSmasputra 	 */								\
101ff550d0eSmasputra 	(len) = MBLKL(mp);						\
102ff550d0eSmasputra 	if ((mp1) == NULL)						\
103ff550d0eSmasputra 		(mp1) = (mp);						\
104ff550d0eSmasputra 	else								\
105ff550d0eSmasputra 		(len) += MBLKL(mp1);					\
106ff550d0eSmasputra 	/*								\
107ff550d0eSmasputra 	 * Postpended extraneous data; adjust checksum.			\
108ff550d0eSmasputra 	 */								\
109ff550d0eSmasputra 	if (((len) = (DB_CKSUMEND(mp) - len)) > 0) {			\
110ff550d0eSmasputra 		uint32_t _pad;						\
111ff550d0eSmasputra 									\
112ff550d0eSmasputra 		_pad = IP_BCSUM_PARTIAL((mp1)->b_wptr, len, 0);		\
113ff550d0eSmasputra 		/*							\
114ff550d0eSmasputra 		 * If the postpended extraneous data was odd		\
115ff550d0eSmasputra 		 * byte aligned, swap resulting checksum bytes.		\
116ff550d0eSmasputra 		 */							\
117ff550d0eSmasputra 		if ((uintptr_t)(mp1)->b_wptr & 1)			\
118ff550d0eSmasputra 			(adj) += ((_pad << 8) & 0xFFFF) | (_pad >> 8);	\
119ff550d0eSmasputra 		else							\
120ff550d0eSmasputra 			(adj) += _pad;					\
121ff550d0eSmasputra 		(adj) = ((adj) & 0xFFFF) + ((int)(adj) >> 16);		\
122ff550d0eSmasputra 	}								\
123ff550d0eSmasputra }
124ff550d0eSmasputra 
125bd670b35SErik Nordmark #define	IS_SIMPLE_IPH(ipha)						\
126bd670b35SErik Nordmark 	((ipha)->ipha_version_and_hdr_length == IP_SIMPLE_HDR_VERSION)
127ff550d0eSmasputra 
128ff550d0eSmasputra /*
129bd670b35SErik Nordmark  * Currently supported flags for LSO.
130ff550d0eSmasputra  */
131bd670b35SErik Nordmark #define	LSO_BASIC_TCP_IPV4	DLD_LSO_BASIC_TCP_IPV4
132bd670b35SErik Nordmark #define	LSO_BASIC_TCP_IPV6	DLD_LSO_BASIC_TCP_IPV6
133ff550d0eSmasputra 
134bd670b35SErik Nordmark #define	ILL_LSO_CAPABLE(ill)						\
135bd670b35SErik Nordmark 	(((ill)->ill_capabilities & ILL_CAPAB_LSO) != 0)
1368347601bSyl 
1378347601bSyl #define	ILL_LSO_USABLE(ill)						\
1388347601bSyl 	(ILL_LSO_CAPABLE(ill) &&					\
139bd670b35SErik Nordmark 	ill->ill_lso_capab != NULL)
1408347601bSyl 
141bd670b35SErik Nordmark #define	ILL_LSO_TCP_IPV4_USABLE(ill)					\
1428347601bSyl 	(ILL_LSO_USABLE(ill) &&						\
143bd670b35SErik Nordmark 	ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV4)
1448347601bSyl 
145bd670b35SErik Nordmark #define	ILL_LSO_TCP_IPV6_USABLE(ill)					\
146bd670b35SErik Nordmark 	(ILL_LSO_USABLE(ill) &&						\
147bd670b35SErik Nordmark 	ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV6)
148ff550d0eSmasputra 
149bd670b35SErik Nordmark #define	ILL_ZCOPY_CAPABLE(ill)						\
150bd670b35SErik Nordmark 	(((ill)->ill_capabilities & ILL_CAPAB_ZEROCOPY) != 0)
151ff550d0eSmasputra 
152bd670b35SErik Nordmark #define	ILL_ZCOPY_USABLE(ill)						\
153bd670b35SErik Nordmark 	(ILL_ZCOPY_CAPABLE(ill) && (ill->ill_zerocopy_capab != NULL) &&	\
154bd670b35SErik Nordmark 	(ill->ill_zerocopy_capab->ill_zerocopy_flags != 0))
155ff550d0eSmasputra 
156ff550d0eSmasputra 
157da14cebeSEric Cheng /* Macro that follows definitions of flags for mac_tx() (see mac_client.h) */
158da14cebeSEric Cheng #define	IP_DROP_ON_NO_DESC	0x01	/* Equivalent to MAC_DROP_ON_NO_DESC */
159da14cebeSEric Cheng 
160da14cebeSEric Cheng #define	ILL_DIRECT_CAPABLE(ill)						\
161da14cebeSEric Cheng 	(((ill)->ill_capabilities & ILL_CAPAB_DLD_DIRECT) != 0)
162da14cebeSEric Cheng 
163*c61a1653SRyan Zezeski /*
164*c61a1653SRyan Zezeski  * Determine if a mblk needs to take the "slow path", aka OTH
165*c61a1653SRyan Zezeski  * softring. There are multiple reasons why a mblk might take the slow
166*c61a1653SRyan Zezeski  * path.
167*c61a1653SRyan Zezeski  *
168*c61a1653SRyan Zezeski  * o The mblk is not a data message.
169*c61a1653SRyan Zezeski  *
170*c61a1653SRyan Zezeski  * o There is more than one outstanding reference to the mblk.
171*c61a1653SRyan Zezeski  *
172*c61a1653SRyan Zezeski  * o The IP header is not aligned (we assume alignment in the checksum
173*c61a1653SRyan Zezeski  *   routine).
174*c61a1653SRyan Zezeski  *
175*c61a1653SRyan Zezeski  * o The mblk doesn't contain enough data to populate a simple IP header.
176*c61a1653SRyan Zezeski  */
177da14cebeSEric Cheng #define	MBLK_RX_FANOUT_SLOWPATH(mp, ipha)				\
178*c61a1653SRyan Zezeski 	(DB_TYPE(mp) != M_DATA ||					\
179*c61a1653SRyan Zezeski 	(DB_REF(mp) != 1) ||						\
180*c61a1653SRyan Zezeski 	!OK_32PTR(ipha) ||						\
181da14cebeSEric Cheng 	(((uchar_t *)ipha + IP_SIMPLE_HDR_LENGTH) >= (mp)->b_wptr))
182da14cebeSEric Cheng 
183b127ac41SPhilip Kirk /*
184b127ac41SPhilip Kirk  * In non-global zone exclusive IP stacks, data structures such as IRE
185b127ac41SPhilip Kirk  * entries pretend that they're in the global zone.  The following
186b127ac41SPhilip Kirk  * macro evaluates to the real zoneid instead of a pretend
187b127ac41SPhilip Kirk  * GLOBAL_ZONEID.
188b127ac41SPhilip Kirk  */
189b127ac41SPhilip Kirk #define	IP_REAL_ZONEID(zoneid, ipst)					\
190b127ac41SPhilip Kirk 	(((zoneid) == GLOBAL_ZONEID) ?					\
191b127ac41SPhilip Kirk 	    netstackid_to_zoneid((ipst)->ips_netstack->netstack_stackid) : \
192b127ac41SPhilip Kirk 	    (zoneid))
193b127ac41SPhilip Kirk 
194da14cebeSEric Cheng extern void ill_flow_enable(void *, ip_mac_tx_cookie_t);
195bd670b35SErik Nordmark extern zoneid_t	ip_get_zoneid_v4(ipaddr_t, mblk_t *, ip_recv_attr_t *,
196bd670b35SErik Nordmark     zoneid_t);
197b127ac41SPhilip Kirk extern zoneid_t	ip_get_zoneid_v6(in6_addr_t *, mblk_t *, const ill_t *,
198bd670b35SErik Nordmark     ip_recv_attr_t *, zoneid_t);
1996e91bba0SGirish Moodalbail extern void conn_ire_revalidate(conn_t *, void *);
2006e91bba0SGirish Moodalbail extern void ip_ire_unbind_walker(ire_t *, void *);
2016e91bba0SGirish Moodalbail extern void ip_ire_rebind_walker(ire_t *, void *);
202ff550d0eSmasputra 
2030f1702c5SYu Xiangning /*
2040f1702c5SYu Xiangning  * flag passed in by IP based protocols to get a private ip stream with
2050f1702c5SYu Xiangning  * no conn_t. Note this flag has the same value as SO_FALLBACK
2060f1702c5SYu Xiangning  */
2070f1702c5SYu Xiangning #define	IP_HELPER_STR	SO_FALLBACK
2080f1702c5SYu Xiangning 
2090f1702c5SYu Xiangning #define	IP_MOD_MINPSZ	1
2100f1702c5SYu Xiangning #define	IP_MOD_MAXPSZ	INFPSZ
2110f1702c5SYu Xiangning #define	IP_MOD_HIWAT	65536
2120f1702c5SYu Xiangning #define	IP_MOD_LOWAT	1024
2130f1702c5SYu Xiangning 
2140f1702c5SYu Xiangning #define	DEV_IP	"/devices/pseudo/ip@0:ip"
2150f1702c5SYu Xiangning #define	DEV_IP6	"/devices/pseudo/ip6@0:ip6"
2160f1702c5SYu Xiangning 
217ff550d0eSmasputra #endif	/* _KERNEL */
218ff550d0eSmasputra 
219ff550d0eSmasputra #ifdef	__cplusplus
220ff550d0eSmasputra }
221ff550d0eSmasputra #endif
222ff550d0eSmasputra 
223ff550d0eSmasputra #endif	/* _INET_IP_IMPL_H */
224