/* $NetBSD: in_offload.c,v 1.15 2024/07/05 04:31:54 rin Exp $ */
/*
* Copyright (c)2005, 2006 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
m = tcp4_segment(m, 0);
if (m == NULL)
return ENOMEM;
do {
n = m->m_nextpkt;
if (error == 0)
error = ip_if_output(ifp, m, sa, rt);
else
m_freem(m);
m = n;
} while (m != NULL);
return error;
}
/*
* Compute now in software the IP and TCP/UDP checksums. Cancel the
* hardware offloading.
*/
void
in_undefer_cksum(struct mbuf *mh, size_t hdrlen, int csum_flags)
{
const size_t iphdrlen = M_CSUM_DATA_IPv4_IPHL(mh->m_pkthdr.csum_data);
uint16_t csum;
uint16_t ip_len;
uint16_t *csump;
struct mbuf *m = mh;
/*
* Deal with prepended frame header as done by e.g. ether_output().
* If first mbuf in chain has just the header, use second mbuf
* for the actual checksum. in4_csum() expects the passed mbuf
* to have the whole (struct ip) area contiguous.
*/
if (m->m_len <= hdrlen) {
hdrlen -= m->m_len;
m = m->m_next;
KASSERT(m != NULL);
}
if (__predict_true(hdrlen + sizeof(struct ip) <= m->m_len)) {
struct ip *ip = (struct ip *)(mtod(m, uint8_t *) + hdrlen);