Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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;
}
share|improve this question
1  
I wouldn't call that "doing nothing to packets", but rather "nothing except changing theirs CRC" – poige Jul 10 '12 at 9:22

closed as off topic by Gilles, Michael Mrozek Jul 10 '12 at 22:31

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

IIRC, TCP CRC should include IPv4 header (12 octects sized "pseudo-header") as well. Do you?

share|improve this answer
Please, take a look at my edit. Checking the kernel source code and the internet, this function I am calling is supposed to do the job. or did I get something wrong? – Adel Qodmani Jul 10 '12 at 10:35
I'd suggest you try looking up tcp_v4_check() and code using it. – poige Jul 10 '12 at 14:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.