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

RE: About the alternation of skbuff



Hi Marco
the skb has many fields, and you do need to change some of them when you
change the size of one.

i will list the relevant parameters, and try to explain what each of them
means.
HEAD - a pointer to the beginning of the data section. this is a static
pointer, and is used by kfree() later - so you must not change this field
unless you allocated a new chunk of SKB data.
DATA - a pointer used by the linux kernel to point to the relevant data.
what i mean - when you allocate a new SKB, data will usually point to the
third bytes of allocated data (->head+2), since it is assumed it will be
used for receiving an IP packet, and will have an Ethernet header, which is
14 bytes so the idea behind those 2 bytes is to achieve IP header alignment.
after the NIC driver receives the packet he will move the data pointer by 14
bytes to point to the next level header - IP and so on and so forth. in
general - "data" points to the beginning of the relevant data inside the
packet.
TAIL - a pointer to the last byte of data inside the packet. if you change
the size of the packet you need to modify this field. but make sure you are
not running over the end of the actual buffer.
END - a pointer to the last byte of allocated data. this is also a static
pointer - do not change, and do not run "tail" after this boundary.
LEN - is actually (TAIL-DATA) it is changed by the various skb_pull/push etc
routines and reflects the size at a certain point of execution
TRUESIZE - is STATIC and can tell you the real size, it is actually
(sizeof(struct sk_buff) + (END - HEAD))

there are many routines that help you move those pointer and change "LEN"
accordingly - you can simply use them and not worry any more (check out
skb_pull, skb_push, skb_trim, and the rest of the functions there)
those are the basic guidelines, if you want to try being more "creative" and
you must push the packet size limit without reallocating the data segment,
you can make an assumption that although a packet was allocated as 1514
bytes - it actually got 2048 bytes of memory, since it was allocated using
kmalloc which allocates the data from a preallocated pools in sizes which
are all powers of 2. so if you run down the END pointer but not by more than
~500 bytes, you are probably safe - but BEWARE...

Hilik


-----Original Message-----
From: owner-kernelnewbies@nl.linux.org
[mailto:owner-kernelnewbies@nl.linux.org]On Behalf Of lam wai wm
Sent: Wednesday, August 08, 2001 4:29 AM
To: kernelnewbies@nl.linux.org
Subject: About the alternation of skbuff


Hi all,

I'm going to alter the data content in the skbuff (payload).
The reason behind that because I'm going to encrypt the payload
only, but if the cipher-text is bigger than the original data
content (payload)  what do I have to concern?  And if the
cipher-text is smaller (probably not) than the original data,
do I have to shrink some of the pointers variable in skbuff.
If it does, would you please tell me which one do I have to
alter?

Thanks so much.

your sincerely,
  marco.


-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/

-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/