ip_impl.h revision 91785ffff883655a89eb843ed89bcd24d717e320
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INET_IP_IMPL_H
#define _INET_IP_IMPL_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* IP implementation private declarations. These interfaces are
* used to build the IP module and are not meant to be accessed
* by any modules except IP itself. They are undocumented and are
* subject to change without notice.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _KERNEL
#define IP_MOD_ID 5701
#ifdef _BIG_ENDIAN
#define IP_HDR_CSUM_TTL_ADJUST 256
#define IP_TCP_CSUM_COMP IPPROTO_TCP
#define IP_UDP_CSUM_COMP IPPROTO_UDP
#else
#define IP_HDR_CSUM_TTL_ADJUST 1
#endif
#define TCP_CHECKSUM_OFFSET 16
#define TCP_CHECKSUM_SIZE 2
#define UDP_CHECKSUM_OFFSET 6
#define UDP_CHECKSUM_SIZE 2
#define ILL_HCKSUM_CAPABLE(ill) \
/*
* Macro that performs software checksum calculation on the IP header.
*/
((v_hlen_tos_len) >> 16) + \
((v_hlen_tos_len) & 0xFFFF) + \
}
/*
* This macro acts as a wrapper around IP_CKSUM_XMIT_FAST, and it performs
* several checks on the IRE and ILL (among other things) in order to see
* whether or not hardware checksum offload is allowed for the outgoing
* packet. It assumes that the caller has held a reference to the IRE.
*/
/* \
* We offload checksum calculation to hardware when IPsec isn't \
* present and if fragmentation isn't required. We also check \
* if M_DATA fastpath is safe to be used on the corresponding \
* IRE; this check is performed without grabbing ire_lock but \
* instead by holding a reference to it. This is sufficient \
* for IRE_CACHE; for IRE_BROADCAST on non-Ethernet links, the \
* DL_NOTE_FASTPATH_FLUSH indication could come up from the \
* driver and trigger the IRE (hence fp_mp) deletion. This is \
* why only IRE_CACHE type is eligible for offload. \
* \
* The presense of IP options also forces the network stack to \
* calculate the checksum in software. This is because: \
* \
* Wrap around: certain partial-checksum NICs (eri, ce) limit \
* the size of "start offset" width to 6-bit. This effectively \
* sets the largest value of the offset to 64-bytes, starting \
* from the MAC header. When the cumulative MAC and IP headers \
* exceed such limit, the offset will wrap around. This causes \
* the checksum to be calculated at the wrong place. \
* \
* IPv4 source routing: none of the full-checksum capable NICs \
* is capable of correctly handling the IPv4 source-routing \
* option for purposes of calculating the pseudo-header; the \
* actual destination is different from the destination in the \
* header which is that of the next-hop. (This case may not be \
* true for NICs which can parse IPv6 extension headers, but \
* we choose to simplify the implementation by not offloading \
* checksum when they are present.) \
* \
*/ \
(ipsec_len) == 0 && \
(start) == IP_SIMPLE_HDR_LENGTH && \
(start) == IPV6_HDR_LEN && \
dohwcksum) { \
} else { \
_hck_flags = 0; \
} \
}
/*
* Based on the device capabilities, this macro either marks an outgoing
* packet with hardware checksum offload information or calculate the
* checksum in software. If the latter is performed, the checksum field
* of the dblk is cleared; otherwise it will be non-zero and contain the
* necessary flag(s) for the driver.
*/
/* \
* Underlying interface supports hardware checksum offload for \
* the payload; leave the payload checksum for the hardware to \
* calculate. N.B: We only need to set up checksum info on the \
* first mblk. \
*/ \
DB_CKSUMFLAGS(mp) = 0; \
if (((ipver) == IPV4_VERSION && \
((hck_flags) & HCKSUM_INET_FULL_V4)) || \
((ipver) == IPV6_VERSION && \
((hck_flags) & HCKSUM_INET_FULL_V6))) { \
/* \
* Hardware calculates pseudo-header, header and the \
* payload checksums, so clear the checksum field in \
* the protocol header. \
*/ \
*(up) = 0; \
} else if ((hck_flags) & HCKSUM_INET_PARTIAL) { \
/* \
* Partial checksum offload has been enabled. Fill \
* the checksum field in the protocl header with the \
* pseudo-header checksum value. \
*/ \
/* \
* Offsets are relative to beginning of IP header. \
*/ \
(start) + UDP_CHECKSUM_OFFSET : \
(start) + TCP_CHECKSUM_OFFSET; \
} else { \
/* \
* Software checksumming. \
*/ \
} \
/* \
* Hardware supports IP header checksum offload; clear the \
* contents of IP header checksum field as expected by NIC. \
* Do this only if we offloaded either full or partial sum. \
*/ \
((hck_flags) & HCKSUM_IPHDRCKSUM)) { \
} \
}
/*
* Macro to inspect the checksum of a fully-reassembled incoming datagram.
*/
if ((hck_flags) & HCK_FULLCKSUM) { \
/* \
* The sum of all fragment checksums should \
* result in -0 (0xFFFF) or otherwise invalid. \
*/ \
if ((sum) != 0xFFFF) \
} else if ((hck_flags) & HCK_PARTIALCKSUM) { \
if (~(sum) & 0xFFFF) \
} \
}
/*
* This macro inspects an incoming packet to see if the checksum value
* contained in it is valid; if the hardware has provided the information,
* the value is verified, otherwise it performs software checksumming.
* The checksum value is returned to caller.
*/
\
if ((hck_flags) & HCK_FULLCKSUM) { \
/* \
* Full checksum has been computed by the hardware \
* and has been attached. If the driver wants us to \
* verify the correctness of the attached value, in \
* order to protect against faulty hardware, compare \
* it against -0 (0xFFFF) to see if it's valid. \
*/ \
} else if (((hck_flags) & HCK_PARTIALCKSUM) && \
/* \
* Partial checksum has been calculated by hardware \
* and attached to the packet; in addition, any \
* prepended extraneous data is even byte aligned, \
* and there are at most two mblks associated with \
* the packet. If any such data exists, we adjust \
* the checksum; also take care any postpended data. \
*/ \
/* \
* One's complement subtract extraneous checksum \
*/ \
else \
if (~(sum) & 0xFFFF) \
} \
}
/*
* Macro to adjust a given checksum value depending on any prepended
* or postpended data on the packet. It expects the start offset to
* begin at an even boundary and that the packet consists of at most
* two mblks.
*/
/* \
* Prepended extraneous data; adjust checksum. \
*/ \
if ((len) > 0) \
else \
(adj) = 0; \
/* \
* len is now the total length of mblk(s) \
*/ \
else \
/* \
* Postpended extraneous data; adjust checksum. \
*/ \
\
/* \
* If the postpended extraneous data was odd \
* byte aligned, swap resulting checksum bytes. \
*/ \
else \
} \
}
#define ILL_MDT_CAPABLE(ill) \
/*
* ioctl identifier and structure for Multidata Transmit update
* private M_CTL communication from IP to ULP.
*/
typedef struct ip_mdt_info_s {
/*
* Macro that determines whether or not a given ILL is allowed for MDT.
*/
#define ILL_MDT_USABLE(ill) \
(ILL_MDT_CAPABLE(ill) && \
#define ILL_LSO_CAPABLE(ill) \
/*
* ioctl identifier and structure for Large Segment Offload
* private M_CTL communication from IP to ULP.
*/
typedef struct ip_lso_info_s {
/*
* Macro that determines whether or not a given ILL is allowed for LSO.
*/
#define ILL_LSO_USABLE(ill) \
(ILL_LSO_CAPABLE(ill) && \
#define ILL_LSO_TCP_USABLE(ill) \
(ILL_LSO_USABLE(ill) && \
/*
* Macro that determines whether or not a given CONN may be considered
* for fast path prior to proceeding further with LSO or Multidata.
*/
#define CONN_IS_LSO_MD_FASTPATH(connp) \
/* Definitons for fragmenting IP packets using MDT. */
/*
* Smaller and private version of pdescinfo_t used specifically for IP,
* which allows for only a single payload span per packet.
*/
/*
* Macro version of ip_can_frag_mdt() which avoids the function call if we
* only examine a single message block.
*/
/*
* Macro that determines whether or not a given IPC requires
* outbound IPSEC processing.
*/
#define CONN_IPSEC_OUT_ENCAPSULATED(connp) \
((connp)->conn_out_enforce_policy || \
/*
* These are used by the synchronous streams code in tcp and udp.
* When we set the flags for a wakeup from a synchronous stream we
* always set RSLEEP in sd_wakeq, even if we have a read thread waiting
* to do the io. This is in case the read thread gets interrupted
* before completing the io. The RSLEEP flag in sd_wakeq is used to
* indicate that there is data available at the synchronous barrier.
* The assumption is that subsequent functions calls through rwnext()
* will reset sd_wakeq appropriately.
*/
#define STR_WAKEUP_CLEAR(stp) { \
}
#define STR_WAKEUP_SET(stp) { \
} \
}
#define STR_SENDSIG(stp) { \
int _events; \
} else { \
} \
}
#define CONN_UDP_SYNCSTR(connp) \
/*
* Macro that checks whether or not a particular UDP conn is
* flow-controlling on the read-side. If udp module is directly
* above ip, check to see if the drain queue is full; note here
* that we check this without any lock protection because this
* is a coarse granularity inbound flow-control. If the module
* above ip is not udp, then use canputnext to determine the
* flow-control.
*
* Note that these checks are done after the conn is found in
* the UDP fanout table. A UDP conn in that table may have its
* IPCL_UDP bit cleared from the conn_flags when the application
* pops the udp module without issuing an unbind; in this case
* IP will still receive packets for the conn and deliver it
* upstream via putnext. This is the reason why we have to test
* against IPCL_UDP.
*/
#define CONN_UDP_FLOWCTLD(connp) \
((CONN_UDP_SYNCSTR(connp) && \
/*
* Macro that delivers a given message upstream; if udp module
* is directly above ip, the message is passed directly into
* the stream-less entry point. Otherwise putnext is used.
*/
if (IPCL_IS_UDP(connp)) \
else \
}
#define ILL_DLS_CAPABLE(ill) \
(((ill)->ill_capabilities & \
(ILL_CAPAB_POLL|ILL_CAPAB_SOFT_RING)) != 0)
/*
* Macro that hands off one or more messages directly to DLD
* when the interface is marked with ILL_CAPAB_POLL.
*/
}
extern int ip_wput_frag_mdt_min;
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _INET_IP_IMPL_H */