LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2014, 09:06 PM   #1
android2009
LQ Newbie
 
Registered: Aug 2010
Posts: 16

Rep: Reputation: 0
Does csum_tcpudp_magic() calculate UDP checksum same way as kernel does ?


Hi everyone,

I am trying a netfilter module in kernel 3.8.0.34 to filter NF_IP_LOCAL_OUT packets like below. The packets have not been touched but UDP checksum was recalculated using csum_tcpudp_magic(), However the returned checksum value is always different from original ip_header->check.

Am I missing something or the original checksum was calculated with different method ?

Output:
Code:
[252565.092326] recalculating udp checksum 38161
[252565.092327] recalculated udp checksum 27332
Code:
unsigned int out_hook(unsigned int hooknum,  

                  struct sk_buff *skb,

                  const struct net_device *in,

                  const struct net_device *out,

                  int (*okfn)(struct sk_buff*))

{

     

        printk(KERN_INFO "Out_hook: entering function\n");

	 struct sk_buff *sock_buff;

	 struct iphdr *ip_header;

        struct udphdr *udp_header;

        struct tcphdr *tcp_header;

	 unsigned int udp_len;

	 unsigned int tcp_len;

	 

	 

	 if(!skb) 

         {

            printk(KERN_INFO "skb is NULL\n");

	    return NF_ACCEPT;

         }


         if(!(skb->network_header))

         {

             printk(KERN_INFO "Error in nh\n");

             return NF_ACCEPT;

         }



         sock_buff = skb;

        printk(KERN_INFO "Getting ip_header\n");

	 /* Get ip header */

	 ip_header = ip_hdr(sock_buff);



	 /* Handle udp protocol */



	 if(ip_header->protocol == IPPROTO_UDP)

	 {

            printk(KERN_INFO "Handling udp packet\n");

	    udp_header = udp_hdr(sock_buff);

		

		/* udp length = sock_buff->len - ip_header length (should be 20 bytes) */

		udp_len = sock_buff->len - (ip_header->ihl << 2);


		/* If UDP checksum is enabled, need to re-calculate */

		if(udp_header->check)

		{

  

                    printk(KERN_INFO "recalculating udp checksum %u\n", udp_header->check);

		    

	            udp_header->check = csum_tcpudp_magic(ip_header->saddr, ip_header->daddr, udp_len, IPPROTO_UDP,  csum_partial(udp_header, udp_len ,0));

                   

                    printk(KERN_INFO "recalculated udp checksum %u\n", udp_header->check);

            

		}

       return NF_ACCEPT;
}

Last edited by android2009; 04-07-2014 at 09:12 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I calculate the right TCP checksum? moby@root Programming 2 11-11-2010 01:26 PM
[SOLVED] Calculate new tcp checksum yaplej Programming 1 09-25-2009 12:27 PM
Enable UDP checksum rafismx Linux - Newbie 0 02-29-2008 07:44 PM
UDP checksum icortazar3 Linux - Networking 1 12-19-2007 03:13 AM
UDP: Short Packets: and UDP bad checksum: entries in dmesg minutes2memories Linux - Networking 2 02-26-2006 08:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration