From owner-freebsd-net@FreeBSD.ORG Mon Oct 24 05:27:02 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 41A4E16A41F for ; Mon, 24 Oct 2005 05:27:02 +0000 (GMT) (envelope-from kamal_ckk@yahoo.com) Received: from web35705.mail.mud.yahoo.com (web35705.mail.mud.yahoo.com [66.163.179.159]) by mx1.FreeBSD.org (Postfix) with SMTP id 9BCEE43D46 for ; Mon, 24 Oct 2005 05:27:01 +0000 (GMT) (envelope-from kamal_ckk@yahoo.com) Received: (qmail 63217 invoked by uid 60001); 24 Oct 2005 05:27:00 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=N79z5gnjr6mNXJoLZb81I5twdTYK5SGYObEvqRSJsvupfSO5HIm3hphLWqrC57eUUU+8tJq0wpPhu23wL1g//2v7MbYiSiPTFfu9lJ46SYFKEO2S4LbWvF1RFZv/r5rrgNqxH5/Z0RT73Y8EMn8b3wuQDVLnoYn6//Wp5cc++G8= ; Message-ID: <20051024052700.63215.qmail@web35705.mail.mud.yahoo.com> Received: from [202.79.62.15] by web35705.mail.mud.yahoo.com via HTTP; Sun, 23 Oct 2005 22:27:00 PDT Date: Sun, 23 Oct 2005 22:27:00 -0700 (PDT) From: kamal kc To: Giorgos Keramidas In-Reply-To: <20051023120442.GB29924@flame.pc> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: freebsd , freebsd Subject: Re: in_cksum() for ip packets with multiple mbufs X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Oct 2005 05:27:02 -0000 > > void copy_the_memorybuffer(struct mbuf **m) > > { > > struct mbuf *mbuf_pointer=*m; > > struct mbuf **next_packet; > > > > next_packet=&mbuf_pointer; > > > > struct ip *my_ip_hdr; > > my_ip_hdr=mtod((*next_packet),struct ip *); > > my_ip_hdr->ip_tos=64; > > my_ip_hdr->ip_sum=0; > > > > my_ip_hdr->ip_sum= > > > in_cksum((*next_packet),(my_ip_hdr->ip_hl<<2)); > > ....... > > } > > Why all this pointer fun? How do you know that it's > safe to dereference > `m' when you do: > > struct mbuf *mbuf_pointer=*m; > > Why are you dereferencing `m' once to obtain > mbuf_pointer and then > taking the address of that to obtain next_packet, > when you could > just do: > > next_packet = m; > > There are also several other problems with > copy_the_memorybuffer() as > it's written above: > > - It's considered bad style to mix declarations > and code the way you > have done above > > - It is probably better to return the copy of > the mbuf you're > fiddling with, instead of modifying in place a > parameter of the > function. one thing i would like to ask? does it make any difference if i free the mbuf 'm' passed to if_output() and pass my own mbuf to if_output. is the original mbuf referenced by any other pointers or global variables ?? i couldn't figure out much from the sources. > - If you are not *REALLY* copying the data of > the mbuf, then > the name of copy_the_memorybuffer() is very > confusing. i didn't showed in the above code snippet but actually i am copying the data contained in the mbufs in a character array. my purpose is to compress the data contained in the ip packet > - What is the magic constant 64 that is assigned > to ip_tos? that was just to see that i could actually modify the ip header. > What you probably want to do is something like: > > void > ip_set_type_of_service(struct mbuf *m) > { > struct ip *iph; > > assert(m != NULL); > > iph = mtod(m, struct ip *); > iph->ip_tos = IPTOS_PREC_IMMEDIATE; > iph->ip_sum = 0; > iph->ip_sum = in_cksum((uint16_t *)iph, > iph->ip_hl << 2); > } thanks i will try this code and try to make the code simpler next time. > but that's not copying anything. > > > but still it doesn't seem to work. and the problem > > is still there. > > You have obviously made a lot of changes that we > haven't seen yet. > Instead of posting snippets here and there, save a > copy of the original > sources somewhere, then a copy of the new sources, > and run diff(1) on > the two directories to extract *ALL* the changes. > > $ cd /usr/src > $ diff -ruN src.old/ src/ > /tmp/patchfile > > and put the patchfile somewhere online where we can > have a look at all > the changes. i am new to kernel sources and kernel programming and thank you for informing me on the diff(1). thanks to you that the problem was solved (i don't know if it is completely ok). i found that - i had made mistake in computing checksum. earlier checksum was computed over the whole dat I may soon put up patchfiles on web. thanks. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com