- /*
- * If the packet is originated from an ALG on the NAT gateway
- * (source address is loopback or local), in which case the
- * TCP/UDP checksum field contains the pseudo header checksum
- * that's not yet complemented. A packet generated locally
- * will have UDP/TCP CSUM flag set (gets set in protocol
- * output).
- */
- if (dir == PF_OUT && m != NULL &&
- (m->m_flags & M_PKTHDR) &&
- (m->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))) {
- /* Pseudo-header checksum does not include ports */
+ /*
+ * If the packet is originated from an ALG on the NAT gateway
+ * (source address is loopback or local), in which case the
+ * TCP/UDP checksum field contains the pseudo header checksum
+ * that's not yet complemented.
+ * In that case we do not need to fixup the checksum for port
+ * translation as the pseudo header checksum doesn't include ports.
+ *
+ * A packet generated locally will have UDP/TCP CSUM flag
+ * set (gets set in protocol output).
+ *
+ * It should be noted that the fixup doesn't do anything if the
+ * checksum is 0.
+ */
+ if (dir == PF_OUT && pbuf != NULL &&
+ (*pbuf->pb_csum_flags & (CSUM_TCP | CSUM_UDP))) {
+ /* Pseudo-header checksum does not include ports */