I want to implement a traffic forwarder through netfilter to forward 0.0.0.0:8080 to the intranet 127.0.0.1:80. The problem is that when the checksum is calculated after modifying the TCP and IP data in the NF_INET_PRE_ROUTING stage, some of the calculated checksum values are correct and some are incorrect.
if (iph->daddr == in_aton("192.168.31.211") && (iph->saddr = in_aton("127.0.0.1")) && ntohs(tcph->source) == 22) {
// Restore the original source IP address
iph->saddr = in_aton("192.168.31.126");
tcph->source = htons(8080);
// Recalculate the IP checksum
iph->check = 0;
iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
// Recalculate the TCP checksum
tcph->check = 0;
tcplen = (skb->len - (iph->ihl << 2));
tcph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, tcplen, IPPROTO_TCP, csum_partial(tcph, tcplen, 0));
skb->ip_summed = CHECKSUM_NONE;
}
1
2
Able to calculate the checksum correctly
New contributor
kk4l is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.