ff550d0e264b51131fb34e9e83163b348d916640masputra/*
ff550d0e264b51131fb34e9e83163b348d916640masputra * CDDL HEADER START
ff550d0e264b51131fb34e9e83163b348d916640masputra *
ff550d0e264b51131fb34e9e83163b348d916640masputra * The contents of this file are subject to the terms of the
592d29ab7326015d0a5b56899a233e7f15dd4dffja * Common Development and Distribution License (the "License").
592d29ab7326015d0a5b56899a233e7f15dd4dffja * You may not use this file except in compliance with the License.
ff550d0e264b51131fb34e9e83163b348d916640masputra *
ff550d0e264b51131fb34e9e83163b348d916640masputra * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ff550d0e264b51131fb34e9e83163b348d916640masputra * or http://www.opensolaris.org/os/licensing.
ff550d0e264b51131fb34e9e83163b348d916640masputra * See the License for the specific language governing permissions
ff550d0e264b51131fb34e9e83163b348d916640masputra * and limitations under the License.
ff550d0e264b51131fb34e9e83163b348d916640masputra *
ff550d0e264b51131fb34e9e83163b348d916640masputra * When distributing Covered Code, include this CDDL HEADER in each
ff550d0e264b51131fb34e9e83163b348d916640masputra * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ff550d0e264b51131fb34e9e83163b348d916640masputra * If applicable, add the following below this CDDL HEADER, with the
ff550d0e264b51131fb34e9e83163b348d916640masputra * fields enclosed by brackets "[]" replaced with your own identifying
ff550d0e264b51131fb34e9e83163b348d916640masputra * information: Portions Copyright [yyyy] [name of copyright owner]
ff550d0e264b51131fb34e9e83163b348d916640masputra *
ff550d0e264b51131fb34e9e83163b348d916640masputra * CDDL HEADER END
ff550d0e264b51131fb34e9e83163b348d916640masputra */
ff550d0e264b51131fb34e9e83163b348d916640masputra/*
6e91bba0d6c6bdabbba62cefae583715a4a58e2aGirish Moodalbail * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
ff550d0e264b51131fb34e9e83163b348d916640masputra * Use is subject to license terms.
ff550d0e264b51131fb34e9e83163b348d916640masputra */
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#ifndef _INET_IP_IMPL_H
ff550d0e264b51131fb34e9e83163b348d916640masputra#define _INET_IP_IMPL_H
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra/*
ff550d0e264b51131fb34e9e83163b348d916640masputra * IP implementation private declarations. These interfaces are
ff550d0e264b51131fb34e9e83163b348d916640masputra * used to build the IP module and are not meant to be accessed
ff550d0e264b51131fb34e9e83163b348d916640masputra * by any modules except IP itself. They are undocumented and are
ff550d0e264b51131fb34e9e83163b348d916640masputra * subject to change without notice.
ff550d0e264b51131fb34e9e83163b348d916640masputra */
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#ifdef __cplusplus
ff550d0e264b51131fb34e9e83163b348d916640masputraextern "C" {
ff550d0e264b51131fb34e9e83163b348d916640masputra#endif
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#ifdef _KERNEL
ff550d0e264b51131fb34e9e83163b348d916640masputra
381a2a9a387f449fab7d0c7e97c4184c26963abfdr#include <sys/sdt.h>
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#include <sys/dld.h>
6e91bba0d6c6bdabbba62cefae583715a4a58e2aGirish Moodalbail#include <inet/tunables.h>
381a2a9a387f449fab7d0c7e97c4184c26963abfdr
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_MOD_ID 5701
ff550d0e264b51131fb34e9e83163b348d916640masputra
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define INET_NAME "ip"
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
ff550d0e264b51131fb34e9e83163b348d916640masputra#ifdef _BIG_ENDIAN
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_HDR_CSUM_TTL_ADJUST 256
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_TCP_CSUM_COMP IPPROTO_TCP
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_UDP_CSUM_COMP IPPROTO_UDP
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define IP_ICMPV6_CSUM_COMP IPPROTO_ICMPV6
ff550d0e264b51131fb34e9e83163b348d916640masputra#else
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_HDR_CSUM_TTL_ADJUST 1
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_TCP_CSUM_COMP (IPPROTO_TCP << 8)
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_UDP_CSUM_COMP (IPPROTO_UDP << 8)
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define IP_ICMPV6_CSUM_COMP (IPPROTO_ICMPV6 << 8)
ff550d0e264b51131fb34e9e83163b348d916640masputra#endif
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#define TCP_CHECKSUM_OFFSET 16
ff550d0e264b51131fb34e9e83163b348d916640masputra#define TCP_CHECKSUM_SIZE 2
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#define UDP_CHECKSUM_OFFSET 6
ff550d0e264b51131fb34e9e83163b348d916640masputra#define UDP_CHECKSUM_SIZE 2
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ICMPV6_CHECKSUM_OFFSET 2
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ICMPV6_CHECKSUM_SIZE 2
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IPH_TCPH_CHECKSUMP(ipha, hlen) \
ff550d0e264b51131fb34e9e83163b348d916640masputra ((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + TCP_CHECKSUM_OFFSET)))
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IPH_UDPH_CHECKSUMP(ipha, hlen) \
ff550d0e264b51131fb34e9e83163b348d916640masputra ((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + UDP_CHECKSUM_OFFSET)))
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define IPH_ICMPV6_CHECKSUMP(ipha, hlen) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ((uint16_t *)(((uchar_t *)(ipha)) + ((hlen) + ICMPV6_CHECKSUM_OFFSET)))
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark
ff550d0e264b51131fb34e9e83163b348d916640masputra#define ILL_HCKSUM_CAPABLE(ill) \
ff550d0e264b51131fb34e9e83163b348d916640masputra (((ill)->ill_capabilities & ILL_CAPAB_HCKSUM) != 0)
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra/*
ff550d0e264b51131fb34e9e83163b348d916640masputra * Macro to adjust a given checksum value depending on any prepended
ff550d0e264b51131fb34e9e83163b348d916640masputra * or postpended data on the packet. It expects the start offset to
ff550d0e264b51131fb34e9e83163b348d916640masputra * begin at an even boundary and that the packet consists of at most
ff550d0e264b51131fb34e9e83163b348d916640masputra * two mblks.
ff550d0e264b51131fb34e9e83163b348d916640masputra */
ff550d0e264b51131fb34e9e83163b348d916640masputra#define IP_ADJCKSUM_PARTIAL(cksum_start, mp, mp1, len, adj) { \
ff550d0e264b51131fb34e9e83163b348d916640masputra /* \
ff550d0e264b51131fb34e9e83163b348d916640masputra * Prepended extraneous data; adjust checksum. \
ff550d0e264b51131fb34e9e83163b348d916640masputra */ \
ff550d0e264b51131fb34e9e83163b348d916640masputra if ((len) > 0) \
ff550d0e264b51131fb34e9e83163b348d916640masputra (adj) = IP_BCSUM_PARTIAL(cksum_start, len, 0); \
ff550d0e264b51131fb34e9e83163b348d916640masputra else \
ff550d0e264b51131fb34e9e83163b348d916640masputra (adj) = 0; \
ff550d0e264b51131fb34e9e83163b348d916640masputra /* \
ff550d0e264b51131fb34e9e83163b348d916640masputra * len is now the total length of mblk(s) \
ff550d0e264b51131fb34e9e83163b348d916640masputra */ \
ff550d0e264b51131fb34e9e83163b348d916640masputra (len) = MBLKL(mp); \
ff550d0e264b51131fb34e9e83163b348d916640masputra if ((mp1) == NULL) \
ff550d0e264b51131fb34e9e83163b348d916640masputra (mp1) = (mp); \
ff550d0e264b51131fb34e9e83163b348d916640masputra else \
ff550d0e264b51131fb34e9e83163b348d916640masputra (len) += MBLKL(mp1); \
ff550d0e264b51131fb34e9e83163b348d916640masputra /* \
ff550d0e264b51131fb34e9e83163b348d916640masputra * Postpended extraneous data; adjust checksum. \
ff550d0e264b51131fb34e9e83163b348d916640masputra */ \
ff550d0e264b51131fb34e9e83163b348d916640masputra if (((len) = (DB_CKSUMEND(mp) - len)) > 0) { \
ff550d0e264b51131fb34e9e83163b348d916640masputra uint32_t _pad; \
ff550d0e264b51131fb34e9e83163b348d916640masputra \
ff550d0e264b51131fb34e9e83163b348d916640masputra _pad = IP_BCSUM_PARTIAL((mp1)->b_wptr, len, 0); \
ff550d0e264b51131fb34e9e83163b348d916640masputra /* \
ff550d0e264b51131fb34e9e83163b348d916640masputra * If the postpended extraneous data was odd \
ff550d0e264b51131fb34e9e83163b348d916640masputra * byte aligned, swap resulting checksum bytes. \
ff550d0e264b51131fb34e9e83163b348d916640masputra */ \
ff550d0e264b51131fb34e9e83163b348d916640masputra if ((uintptr_t)(mp1)->b_wptr & 1) \
ff550d0e264b51131fb34e9e83163b348d916640masputra (adj) += ((_pad << 8) & 0xFFFF) | (_pad >> 8); \
ff550d0e264b51131fb34e9e83163b348d916640masputra else \
ff550d0e264b51131fb34e9e83163b348d916640masputra (adj) += _pad; \
ff550d0e264b51131fb34e9e83163b348d916640masputra (adj) = ((adj) & 0xFFFF) + ((int)(adj) >> 16); \
ff550d0e264b51131fb34e9e83163b348d916640masputra } \
ff550d0e264b51131fb34e9e83163b348d916640masputra}
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define IS_SIMPLE_IPH(ipha) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ((ipha)->ipha_version_and_hdr_length == IP_SIMPLE_HDR_VERSION)
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra/*
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark * Currently supported flags for LSO.
ff550d0e264b51131fb34e9e83163b348d916640masputra */
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define LSO_BASIC_TCP_IPV4 DLD_LSO_BASIC_TCP_IPV4
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define LSO_BASIC_TCP_IPV6 DLD_LSO_BASIC_TCP_IPV6
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ILL_LSO_CAPABLE(ill) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark (((ill)->ill_capabilities & ILL_CAPAB_LSO) != 0)
8347601bcb0a439f6e50fc36b4039a73d08700e1yl
8347601bcb0a439f6e50fc36b4039a73d08700e1yl#define ILL_LSO_USABLE(ill) \
8347601bcb0a439f6e50fc36b4039a73d08700e1yl (ILL_LSO_CAPABLE(ill) && \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ill->ill_lso_capab != NULL)
8347601bcb0a439f6e50fc36b4039a73d08700e1yl
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ILL_LSO_TCP_IPV4_USABLE(ill) \
8347601bcb0a439f6e50fc36b4039a73d08700e1yl (ILL_LSO_USABLE(ill) && \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV4)
8347601bcb0a439f6e50fc36b4039a73d08700e1yl
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ILL_LSO_TCP_IPV6_USABLE(ill) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark (ILL_LSO_USABLE(ill) && \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ill->ill_lso_capab->ill_lso_flags & LSO_BASIC_TCP_IPV6)
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ILL_ZCOPY_CAPABLE(ill) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark (((ill)->ill_capabilities & ILL_CAPAB_ZEROCOPY) != 0)
ff550d0e264b51131fb34e9e83163b348d916640masputra
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark#define ILL_ZCOPY_USABLE(ill) \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark (ILL_ZCOPY_CAPABLE(ill) && (ill->ill_zerocopy_capab != NULL) && \
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark (ill->ill_zerocopy_capab->ill_zerocopy_flags != 0))
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/* Macro that follows definitions of flags for mac_tx() (see mac_client.h) */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#define IP_DROP_ON_NO_DESC 0x01 /* Equivalent to MAC_DROP_ON_NO_DESC */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#define ILL_DIRECT_CAPABLE(ill) \
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (((ill)->ill_capabilities & ILL_CAPAB_DLD_DIRECT) != 0)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark/* This macro is used by the mac layer */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#define MBLK_RX_FANOUT_SLOWPATH(mp, ipha) \
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (DB_TYPE(mp) != M_DATA || DB_REF(mp) != 1 || !OK_32PTR(ipha) || \
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (((uchar_t *)ipha + IP_SIMPLE_HDR_LENGTH) >= (mp)->b_wptr))
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk/*
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk * In non-global zone exclusive IP stacks, data structures such as IRE
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk * entries pretend that they're in the global zone. The following
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk * macro evaluates to the real zoneid instead of a pretend
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk * GLOBAL_ZONEID.
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk */
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk#define IP_REAL_ZONEID(zoneid, ipst) \
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk (((zoneid) == GLOBAL_ZONEID) ? \
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk netstackid_to_zoneid((ipst)->ips_netstack->netstack_stackid) : \
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk (zoneid))
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirk
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void ill_flow_enable(void *, ip_mac_tx_cookie_t);
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmarkextern zoneid_t ip_get_zoneid_v4(ipaddr_t, mblk_t *, ip_recv_attr_t *,
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark zoneid_t);
b127ac411761a3d8d642d9342d9cac2785e1faaaPhilip Kirkextern zoneid_t ip_get_zoneid_v6(in6_addr_t *, mblk_t *, const ill_t *,
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark ip_recv_attr_t *, zoneid_t);
6e91bba0d6c6bdabbba62cefae583715a4a58e2aGirish Moodalbailextern void conn_ire_revalidate(conn_t *, void *);
6e91bba0d6c6bdabbba62cefae583715a4a58e2aGirish Moodalbailextern void ip_ire_unbind_walker(ire_t *, void *);
6e91bba0d6c6bdabbba62cefae583715a4a58e2aGirish Moodalbailextern void ip_ire_rebind_walker(ire_t *, void *);
ff550d0e264b51131fb34e9e83163b348d916640masputra
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * flag passed in by IP based protocols to get a private ip stream with
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * no conn_t. Note this flag has the same value as SO_FALLBACK
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define IP_HELPER_STR SO_FALLBACK
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define IP_MOD_MINPSZ 1
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define IP_MOD_MAXPSZ INFPSZ
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define IP_MOD_HIWAT 65536
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define IP_MOD_LOWAT 1024
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define DEV_IP "/devices/pseudo/ip@0:ip"
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#define DEV_IP6 "/devices/pseudo/ip6@0:ip6"
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
ff550d0e264b51131fb34e9e83163b348d916640masputra#endif /* _KERNEL */
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#ifdef __cplusplus
ff550d0e264b51131fb34e9e83163b348d916640masputra}
ff550d0e264b51131fb34e9e83163b348d916640masputra#endif
ff550d0e264b51131fb34e9e83163b348d916640masputra
ff550d0e264b51131fb34e9e83163b348d916640masputra#endif /* _INET_IP_IMPL_H */