laforge@gnumonks.org
At the time I wanted to know more about the Linux network stack, I = always=20 wanted a document like this to exist. But unfortunately I never found = one. After=20 I gained some basic knowledge about the Linux network stack internals, I = wrote=20 one.=20
I'm happy if this document is of any use for other people trying to = learn=20 about the Linux kernel.=20
Please let me know of any bugs in this document. It should resemble = kernel=20 revision 2.4.0-test4=20
skbuffs are the buffers in which the linux kernel handles network = packets.=20 The packet is received by the network card, put into a skbuff and then = passed to=20 the network stack, which uses the skbuff all the time.=20
The struct sk_buff is defined in <linux/skbuff.h> as follows:=20
next buffer in list
previous buffer in list
list we are on
socket we belong to
timeval we arrived at
device we are leaving by
device we arrived at
transport layer header (tcp,udp,icmp,igmp,spx,raw)
network layer header (ip,ipv6,arp,ipx,raw)
link layer header
FIXME:
control buffer, used internally
length of actual data
checksum
FIXME: data moved to user and not MSG_PEEK
we are a clone
head may be cloned
packet class
driver fed us ip checksum
packet queuing priority
user count
packet protocol from driver
security level of packet
real size of the buffer
pointer to head of buffer
data head pointer
tail pointer
end pointer
destructor function=20
netfilter mark
netfilter internal caching info
associated connection, if any=20
traffic control index
There are a bunch of skb support functions provided by the sk_buff = layer. I=20 briefly describe the most important ones in this section.=20
This function allocates a new skb. This is provided by the skb = layer to=20 initialize some privat data and do memory statistics. The returned = buffer has=20 no headroom and a tailroom of /size/ bytes.=20
Decrement the skb's usage count by one and free the skb if no = references=20 left.=20
Increments the skb's usage count by one and returns a pointer to = it.=20
This function clones a skb. Both copies share the packet data but = have=20 their own struct sk_buff. The new copy is not owned by any socket, = reference=20 count is 1.=20
Makes a real copy of the skb, including packet data. This is = needed, if You=20 wish to modify the packet data. Reference count of the new skb is 1.=20
Make a copy of the skb, including packet data. Additionally the new = skb has=20 a haedroom of /new_headroom/ bytes size and a tailroom of = /new_tailroom/=20 bytes.=20
Is the skb a clone?=20
Is this skb shared? (is the reference count > 1)?=20
peek a skb from front of the list; does not remove skb from the = list=20
peek a skb from tail of the list; does not remove sk from the list=20
return the length of the given skb list=20
enqueue a skb at the head of a given list=20
enqueue a skb at the end of a given list.=20
struct sk_buff *skb_dequeue(struct sk_buff_head *list_)=20
dequeue a skb from the head of the given list.=20
struct sk_buff *sbk_dequeue_tail(struct sk_buff_head *list_)=20
dequeue a skb from the tail of the given list
extends the data area of the skb. if the total size exceeds the = size of the=20 skb, the kernel will panic. A pointer to the first byte of new data is = returned.=20
extends the data area of the skb. if the total size exceeds the = size of the=20 skb, the kernel will panic. A pointer to the first byte of new data is = returned.=20
remove data from the start of a buffer, returning the bytes to = headroom. A=20 pointr to the next data in the buffer is returned.=20
return the amount of bytes of free space at the head of skb=20
return the amount of bytes of free space at the end of skb=20
if the buffer passed lacks sufficient headroom or is a clone it is = copied=20 and additional headroom made available.=20
![]() ![]() |