aboutsummaryrefslogtreecommitdiff
path: root/sys/netpfil
diff options
context:
space:
mode:
authorAndrey V. Elsukov <ae@FreeBSD.org>2020-08-05 09:16:35 +0000
committerAndrey V. Elsukov <ae@FreeBSD.org>2020-08-05 09:16:35 +0000
commitaaef76e1fd8c94849324c557a204da2a84a305e3 (patch)
treef2b57e76d10e4326677c4d2b87b5b2e737c5a1fd /sys/netpfil
parent738fc84a7a946937fd3579fb94264973459cda52 (diff)
downloadsrc-aaef76e1fd8c94849324c557a204da2a84a305e3.tar.gz
src-aaef76e1fd8c94849324c557a204da2a84a305e3.zip
Handle delayed checksums if needed in NAT64.
Upper level protocols defer checksums calculation in hope we have checksums offloading in a network card. CSUM_DELAY_DATA flag is used to determine that checksum calculation was deferred. And IP output routine checks for this flag before pass mbuf to lower layer. Forwarded packets have not this flag. NAT64 uses checksums adjustment when it translates IP headers. In most cases NAT64 is used for forwarded packets, but in case when it handles locally originated packets we need to finish checksum calculation that was deferred to correctly adjust it. Add check for presence of CSUM_DELAY_DATA flag and finish checksum calculation before adjustment. Reported and tested by: Evgeniy Khramtsov <evgeniy at khramtsov org> MFC after: 1 week
Notes
Notes: svn path=/head/; revision=363888
Diffstat (limited to 'sys/netpfil')
-rw-r--r--sys/netpfil/ipfw/nat64/nat64_translate.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/netpfil/ipfw/nat64/nat64_translate.c b/sys/netpfil/ipfw/nat64/nat64_translate.c
index c7c83858b3cc..87cef07feefc 100644
--- a/sys/netpfil/ipfw/nat64/nat64_translate.c
+++ b/sys/netpfil/ipfw/nat64/nat64_translate.c
@@ -1294,6 +1294,12 @@ nat64_do_handle_ip4(struct mbuf *m, struct in6_addr *saddr,
ip6.ip6_hlim -= IPTTLDEC;
ip6.ip6_plen = htons(plen);
ip6.ip6_nxt = (proto == IPPROTO_ICMP) ? IPPROTO_ICMPV6: proto;
+
+ /* Handle delayed checksums if needed. */
+ if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
+ in_delayed_cksum(m);
+ m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
+ }
/* Convert checksums. */
switch (proto) {
case IPPROTO_TCP:
@@ -1665,6 +1671,12 @@ nat64_do_handle_ip6(struct mbuf *m, uint32_t aaddr, uint16_t aport,
return (NAT64RETURN);
}
nat64_init_ip4hdr(ip6, frag, plen, proto, &ip);
+
+ /* Handle delayed checksums if needed. */
+ if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6) {
+ in6_delayed_cksum(m, plen, hlen);
+ m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6;
+ }
/* Convert checksums. */
switch (proto) {
case IPPROTO_TCP: