Library Functions
Copyright 1996 Erik Lindsley
To maipulate the two structures, several library functions of different
catagories are provided:
INITIALIZATION
- void skb_queue_head_init(struct sk_buff_head *list)
- Initializes the sk_bufff_head structure. Normally, the sk_buff_head is
declared as a local variable, which is then initialized to an empty queue
by the this function
CREATION
-
- struct sk_buff *alloc_skb(unsigned int size, int priority)
- Allocates kernel memmory to store data of at least the specified size.
Note that kernel memory is allocate in powers of two, and so you might
get alot more space than you need. The priority indicates whether the memory
has to be available right now, or can be paged in. In most cases, it should
be GFP_ATOMIC, which means no paging.
- struct sk_buff *dev_alloc_skb(unsigned int size);
- struct sk_buff *skb_clone(struct sk_buff *skb, int priority)
- Make a fake copy of the the specified SKB.
The new skb is not owned by a socket, or locked, and will be freed on
deletion.
- struct sk_buff *skb_copy(struct sk_buff *skb, int priority)
- Make a real (independent) copy of the the specified SKB and the data it
points to.
SIMPLE MANIPULATION
- void skb_queue_head(struct sk_buff_head *list,struct sk_buff *buf)
- Adds the given SKB to the head of the queue. It will then be the next
SKB dequeue.
- void skb_queue_tail(struct sk_buff_head *list,struct sk_buff *buf)
- Adds the given SKB to the tail (end) of the queue. It will then be the
last SKB dequeued.
- struct sk_buff * skb_dequeue(struct sk_buff_head *list)
- Removes an SKB from the head of a given queue, if one is available.
If not, NULL is returned.
INFORMATIVE
- __u32 skb_queue_len(struct sk_buff_head *list);
- Determines the number of SKBs in a given queue.
-
struct sk_buff *skb_peek_copy(struct sk_buff_head *list);
- Takes a peek at the next SKB to be dequeued, BUT DOES NOT REMOVE IT
FROM THE LIST. This means that it is possible for another process to
run off with it while your back is turned.
-
int skb_headroom(struct sk_buff *skb)
-
Determines how many free bytes are available before the actual data
starts in the buffer. Often used to see if a header can simplely be
prepended to the valid data area, or if a copy into a new buffer
is necessary. Usually used as a check right before skb_push() is
called.
-
int skb_tailroom(struct sk_buff *skb)
-
Determines how many free bytes are available after the actual data
ends in the buffer. Often used to see if a trailer can simplely be
appended to the valid data area, or if a copy into a new buffer
is necessary. Ussually used as a check right before a call to skb_put().
- int skb_device_locked(struct sk_buff *skb)
Check to see if the given SKB is locked.
COMPLEX SKB MANIPULATION
- void skb_insert(struct sk_buff *old,struct sk_buff *newsk)
- Inserts the new SKB in front of the old SKB in the list.
- void skb_append(struct sk_buff *old,struct sk_buff *newsk)
- Inserts the new SKB in back of the old SKB in the list.
- void skb_unlink(struct sk_buff *buf)
- Removes the SKB from its list, no matter where it is in that list.
- void skb_device_lock(struct sk_buff *skb)
- Places a lock on the given SKB.
- void skb_device_unlock(struct sk_buff *skb)
- Removes a lock on a given SKB
DATA MANIPULATION
- unsigned char * skb_put(struct sk_buff *skb, int len)
- Adds len garbage characters to the end of the PDU, and then returns a
pointer to the start of the garbage characters so you can overwrite them.
Note that there
is no range checking to ensure that space actually exists, so be careful
of memory overruns.
- unsigned char * skb_push(struct sk_buff *skb, int len)
- "Pushes" len garbage bytes onto the front of the PDU, and
returns a pointer to the start of the garbage bytes. Note that there
is no range checking to ensure that space actually exists so be careful
of memory underruns.
- unsigned char * skb_pull(struct sk_buff *skb, int len)
- If there are len bytes available, then they are removed from the
buffer and a pointer to the start of the removed bytes is returned.
Otherwise, a NULL pointer is returned.
- void skb_reserve(struct sk_buff *skb, int len)
- Pre-allocates some space for a header that will be added by
later protocols. This can save some unnessary copies in lower protocol layers.
normally, these headers are then written with skb_push()
- void skb_trim(struct sk_buff *skb, int len)
- Shortens the stored data in the SKB to the desired length. Often
used to remove trailiers from PDUs
DESTRUCTION
- void kfree_skb(struct sk_buff *skb, int rw)
- Frees an SKB for either Reading, Writing, or both.
- void kfree_skbmem(struct sk_buff *skb)
- Frees the memory allocated to an SKB to store data.
Not used by newer code
- void dev_kfree_skb(struct sk_buff *skb, int mode)
- Frees the memory that the SKB structure occupies
/* Please note that I plan to add a 2-3 line description of what each function
does, and it's normal use. */