4 * Copyright (c)2006 YAMAMOTO Takashi,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: in6_offload.c,v 1.3 2007/04/25 20:40:20 dyoung Exp $");
32 #include <sys/param.h>
37 #include <netinet/in.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/ip6.h>
40 #include <netinet/tcp.h>
41 #include <netinet6/in6_var.h>
42 #include <netinet6/nd6.h>
43 #include <netinet6/in6_offload.h>
45 struct ip6_tso_output_args
{
47 struct ifnet
*origifp
;
48 const struct sockaddr_in6
*dst
;
52 static int ip6_tso_output_callback(void *, struct mbuf
*);
55 ip6_tso_output_callback(void *vp
, struct mbuf
*m
)
57 struct ip6_tso_output_args
*args
= vp
;
59 return nd6_output(args
->ifp
, args
->origifp
, m
, args
->dst
, args
->rt
);
63 ip6_tso_output(struct ifnet
*ifp
, struct ifnet
*origifp
, struct mbuf
*m
,
64 const struct sockaddr_in6
*dst
, struct rtentry
*rt
)
66 struct ip6_tso_output_args args
;
69 args
.origifp
= origifp
;
73 return tcp6_segment(m
, ip6_tso_output_callback
, &args
);
77 * tcp6_segment: handle M_CSUM_TSOv6 by software.
79 * => always consume m.
80 * => call output_func with output_arg for each segments.
84 tcp6_segment(struct mbuf
*m
, int (*output_func
)(void *, struct mbuf
*),
95 struct mbuf
*hdr
= NULL
;
99 KASSERT((m
->m_flags
& M_PKTHDR
) != 0);
100 KASSERT((m
->m_pkthdr
.csum_flags
& M_CSUM_TSOv6
) != 0);
102 m
->m_pkthdr
.csum_flags
= 0;
104 len
= m
->m_pkthdr
.len
;
105 KASSERT(len
>= sizeof(*iph
) + sizeof(*th
));
107 if (m
->m_len
< sizeof(*iph
)) {
108 m
= m_pullup(m
, sizeof(*iph
));
114 iph
= mtod(m
, struct ip6_hdr
*);
115 iphlen
= sizeof(*iph
);
116 KASSERT((iph
->ip6_vfc
& IPV6_VERSION_MASK
) == IPV6_VERSION
);
117 KASSERT(iph
->ip6_nxt
== IPPROTO_TCP
);
119 hlen
= iphlen
+ sizeof(*th
);
120 if (m
->m_len
< hlen
) {
121 m
= m_pullup(m
, hlen
);
127 th
= (void *)(mtod(m
, char *) + iphlen
);
128 tcpseq
= ntohl(th
->th_seq
);
129 thlen
= th
->th_off
* 4;
130 hlen
= iphlen
+ thlen
;
132 mss
= m
->m_pkthdr
.segsz
;
136 t
= m_split(m
, hlen
, M_NOWAIT
);
144 KASSERT(len
% mss
== 0);
148 n
= m_dup(hdr
, 0, hlen
, M_NOWAIT
);
153 KASSERT(n
->m_len
== hlen
); /* XXX */
155 t
= m_split(m
, mss
, M_NOWAIT
);
164 KASSERT(n
->m_len
>= hlen
); /* XXX */
166 n
->m_pkthdr
.len
= hlen
+ mss
;
167 iph
= mtod(n
, struct ip6_hdr
*);
168 KASSERT((iph
->ip6_vfc
& IPV6_VERSION_MASK
) == IPV6_VERSION
);
169 iph
->ip6_plen
= htons(thlen
+ mss
);
170 th
= (void *)(mtod(n
, char *) + iphlen
);
171 th
->th_seq
= htonl(tcpseq
);
173 th
->th_sum
= in6_cksum(n
, IPPROTO_TCP
, iphlen
, thlen
+ mss
);
175 error
= (*output_func
)(output_arg
, n
);