Index: ip_divert.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_divert.c,v retrieving revision 1.64 diff -u -p -r1.64 ip_divert.c --- ip_divert.c 16 Nov 2020 06:38:20 -0000 1.64 +++ ip_divert.c 5 Apr 2021 08:57:54 -0000 @@ -213,6 +213,42 @@ divert_packet(struct mbuf *m, int dir, u break; } if_put(ifp); + } else { + struct ip *ip; + int min_hdrlen, off; + int flags = 0; + + ip = mtod(m, struct ip *); + off = ip->ip_hl << 2; + + switch (ip->ip_p) { + case IPPROTO_TCP: + min_hdrlen = sizeof(struct tcphdr); + flags = M_TCP_CSUM_OUT; + break; + case IPPROTO_UDP: + min_hdrlen = sizeof(struct udphdr); + flags = M_UDP_CSUM_OUT; + break; + case IPPROTO_ICMP: + min_hdrlen = ICMP_MINLEN; + flags = M_ICMP_CSUM_OUT; + break; + default: + min_hdrlen = 0; + break; + } + if (off + min_hdrlen >= m->m_pkthdr.len) + m->m_pkthdr.csum_flags |= flags; + + /* + * Calculate IP and protocol checksums for the outbound packet + * since the kernel may be expecting the NIC to calculate it, + * or pf has modified the packet. + */ + ip->ip_sum = 0; + ip->ip_sum = in_cksum(m, off); + in_proto_cksum_out(m, NULL); } if (inp) {