Skip to content

Commit

Permalink
ip4: don't zero checksum on forwarding
Browse files Browse the repository at this point in the history
this fixes IP forwarding for systems that don't have hardware
checksumming on the output interface. The CHECKSUM_GEN_xxx checks
meant that lwip was unconditionally zeroing the checksums when
forwarding was enabled, the the checksums were not being re-calculated
before sending, resulting in zero checksum on the forwarded output
packets
  • Loading branch information
tridge committed Jan 10, 2024
1 parent a14232d commit b90fa15
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/ipv4/ip4.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
}

/* Take care of setting checksums to 0 for checksum offload netifs */
if (CHECKSUM_GEN_IP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP)) {
if (NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP)) {
IPH_CHKSUM_SET(iphdr, 0);
}
switch (IPH_PROTO(iphdr)) {
Expand All @@ -346,21 +346,21 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
case IP_PROTO_UDPLITE:
#endif
case IP_PROTO_UDP:
if (CHECKSUM_GEN_UDP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_UDP)) {
if (NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_UDP)) {
((struct udp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
}
break;
#endif
#if LWIP_TCP
case IP_PROTO_TCP:
if (CHECKSUM_GEN_TCP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_TCP)) {
if (NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_TCP)) {
((struct tcp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
}
break;
#endif
#if LWIP_ICMP
case IP_PROTO_ICMP:
if (CHECKSUM_GEN_ICMP || NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_ICMP)) {
if (NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_ICMP)) {
((struct icmp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)))->chksum = 0;
}
break;
Expand Down

0 comments on commit b90fa15

Please sign in to comment.