svn commit: r364158 - stable/12/sys/netpfil/ipfw/nat64

Andrey V. Elsukov ae at FreeBSD.org
Wed Aug 12 11:48:20 UTC 2020


Author: ae
Date: Wed Aug 12 11:48:19 2020
New Revision: 364158
URL: https://svnweb.freebsd.org/changeset/base/364158

Log:
  MFC r363888:
    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.

Modified:
  stable/12/sys/netpfil/ipfw/nat64/nat64_translate.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/netpfil/ipfw/nat64/nat64_translate.c
==============================================================================
--- stable/12/sys/netpfil/ipfw/nat64/nat64_translate.c	Wed Aug 12 11:43:43 2020	(r364157)
+++ stable/12/sys/netpfil/ipfw/nat64/nat64_translate.c	Wed Aug 12 11:48:19 2020	(r364158)
@@ -1286,6 +1286,12 @@ nat64_do_handle_ip4(struct mbuf *m, struct in6_addr *s
 		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:
@@ -1656,6 +1662,12 @@ nat64_do_handle_ip6(struct mbuf *m, uint32_t aaddr, ui
 		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:


More information about the svn-src-all mailing list