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