mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: cranium2003 <cranium2003@yahoo.com>
To: linux-kernel@vger.kernel.org
Subject: ip_fast_csum usage
Date: Sat, 1 Jan 2005 20:37:41 -0800 (PST)	[thread overview]
Message-ID: <20050102043741.9207.qmail@web41408.mail.yahoo.com> (raw)

Hello all,
          In linux kernel source code of IP layer i
found that calculation of IP header checksum requires
 ip_fast_csum function to be called with IP header as
unsigned char string parameter.
 I want to know what will happen if i replace that IP
header parameter with my own unsigned char *data
variable which is align to 4 octet boundry.

	iph->check = ip_fast_csum((unsigned char *) iph,
iph->ihl);

the ip_fast_csum defined in kernel source is as
static inline unsigned short ip_fast_csum(unsigned
char * iph,
					  unsigned int ihl)
{
	unsigned int sum;

	__asm__ __volatile__(
	    "movl (%1), %0	;\n"
	    "subl $4, %2	;\n"
	    "jbe 2f		;\n"
	    "addl 4(%1), %0	;\n"
	    "adcl 8(%1), %0	;\n"
	    "adcl 12(%1), %0	;\n"
"1:	    adcl 16(%1), %0	;\n"
	    "lea 4(%1), %1	;\n"
	    "decl %2		;\n"
	    "jne 1b		;\n"
	    "adcl $0, %0	;\n"
	    "movl %0, %2	;\n"
	    "shrl $16, %0	;\n"
	    "addw %w2, %w0	;\n"
	    "adcl $0, %0	;\n"
	    "notl %0		;\n"
"2:				;\n"
	/* Since the input registers which are loaded with
iph and ipl
	   are modified, we must also specify them as
outputs, or gcc
	   will assume they contain their original values. */
	: "=r" (sum), "=r" (iph), "=r" (ihl)
	: "1" (iph), "2" (ihl)
	: "memory");
	return(sum);
}

I am just experimenting with this function from kernel
module to check how it works?
Thanks in advance.
regards,
cranium.


		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

                 reply	other threads:[~2005-01-02  4:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050102043741.9207.qmail@web41408.mail.yahoo.com \
    --to=cranium2003@yahoo.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®