I am using netfilter hook POST_ROUTING in a kernel module to capture packets.
I am doing NOTHING to the packets, not a single change. I simply check if it's a TCP and then re-calculate the checksum(later on, I need to change some fields so I want to get the checksum calculation right).
I re-calc the checksum and once I load the module, all TCP connection simply won't work. w3m for example gets stuck at Opening Socket.
I am calculating the TCP checksum using this:
tcph->check = tcp_v4_check(skb->len - ip_hdrlen(skb), iph->saddr, iph->daddr, csum_partial((char *)tcph, skb->len - ip_hdrlen(skb), 0));
Please, what's wrong with what I am doing?
Oh, and the kernel I am using is 2.6.35-22
EDIT: I'll include my hook function:
static unsigned int post_icmp_check(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct iphdr *iph;
struct tcphdr *tcph;
iph = ip_hdr(skb);
if(iph->saddr == in_aton("127.0.0.1") || iph->daddr == in_aton("127.0.0.1"))
return NF_ACCEPT;
if(iph->protocol == IPPROTO_TCP){
tcph = tcp_hdr(skb);
tcph->check = 0;
tcph->check = tcp_v4_check(skb->len - ip_hdrlen(skb), iph->saddr, iph->daddr, csum_partial((char *)tcph, skb->len - ip_hdrlen(skb), 0));
}
return NF_ACCEPT;
}