Re: related to Skb Buffers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 1 Jan 2000, Lakshmi Shanmugam wrote:

> Skb structure in linux has three members 
> skb->len
> skb->datalen 
> skb->truesize
> 
> Can anyone explain me what is the difference between them

This is an enough asked question to be put into some sort of FAQ :)

truesize = end - head
len = tail - data

>From what i understood after going thru some code, it seems that
'data_len' is an artifact of the ability to have non-linear skbuffs.
Meaning, skbs can now be split up so that header and data areas dont have
to be in contiguous memory. From other sources i gathered that this is
required for 'zerocopy' to work.

Hence skb->len is the length of the data for that protocol, while 
skb->data_len is the length of the data for that protocol in THAT skb. 

So if you are not bothered about skb splits, then data_len = 0

--------------------------------------------------------------------
This part of code from tcp_output.c might help in understanding:

350 /* Split fragmented skb to two parts at length len. */
351 
352 static void skb_split(struct sk_buff *skb, struct sk_buff *skb1, u32 
len)
353 {
354 int i;
355 int pos = skb->len - skb->data_len;
356 
357 if (len < pos) {
358 /* Split line is inside header. */
359 memcpy(skb_put(skb1, pos-len), skb->data + len, pos-len);
360 
361 /* And move data appendix as is. */
362 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
363 skb_shinfo(skb1)->frags[i] = skb_shinfo(skb)->frags[i];
364 
365 skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
366 skb_shinfo(skb)->nr_frags = 0;
367 
368 skb1->data_len = skb->data_len;
369 skb1->len += skb1->data_len;
370 skb->data_len = 0;
371 skb->len = len;
372 skb->tail = skb->data+len;
373 } else {
374 int k = 0;
375 int nfrags = skb_shinfo(skb)->nr_frags;
376 
377 /* Second chunk has no header, nothing to copy. */
378 
379 skb_shinfo(skb)->nr_frags = 0;
380 skb1->len = skb1->data_len = skb->len - len;
381 skb->len = len;
382 skb->data_len = len - pos;
----------------------------------------------------------------

HTH.
ciao,
Amit

-- 
I'm an angel!!! Honest!
The horns are just there to hold the halo up straight.
^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
                  Amit Kucheria
          EECS Grad. Research Assistant
         University of Kansas @ Lawrence
   (R)+1-(785)-830 8521 ||| (O)+1-(785)-864 7774
____________________________________________________






--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux