~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/skbuff.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *      Definitions for the 'struct sk_buff' memory handlers.
  3  *
  4  *      Authors:
  5  *              Alan Cox, <gw4pts@gw4pts.ampr.org>
  6  *              Florian La Roche, <rzsfl@rz.uni-sb.de>
  7  *
  8  *      This program is free software; you can redistribute it and/or
  9  *      modify it under the terms of the GNU General Public License
 10  *      as published by the Free Software Foundation; either version
 11  *      2 of the License, or (at your option) any later version.
 12  */
 13  
 14 #ifndef _LINUX_SKBUFF_H
 15 #define _LINUX_SKBUFF_H
 16 
 17 #include <linux/config.h>
 18 #include <linux/kernel.h>
 19 #include <linux/sched.h>
 20 #include <linux/time.h>
 21 
 22 #include <asm/atomic.h>
 23 #include <asm/types.h>
 24 #include <linux/spinlock.h>
 25 
 26 #define HAVE_ALLOC_SKB          /* For the drivers to know */
 27 #define HAVE_ALIGNABLE_SKB      /* Ditto 8)                */
 28 #define SLAB_SKB                /* Slabified skbuffs       */
 29 
 30 #define CHECKSUM_NONE 0
 31 #define CHECKSUM_HW 1
 32 #define CHECKSUM_UNNECESSARY 2
 33 
 34 #ifdef __i386__
 35 #define NET_CALLER(arg) (*(((void**)&arg)-1))
 36 #else
 37 #define NET_CALLER(arg) __builtin_return_address(0)
 38 #endif
 39 
 40 #ifdef CONFIG_NETFILTER
 41 struct nf_conntrack {
 42         atomic_t use;
 43         void (*destroy)(struct nf_conntrack *);
 44 };
 45 
 46 struct nf_ct_info {
 47         struct nf_conntrack *master;
 48 };
 49 #endif
 50 
 51 struct sk_buff_head {
 52         /* These two members must be first. */
 53         struct sk_buff  * next;
 54         struct sk_buff  * prev;
 55 
 56         __u32           qlen;
 57         spinlock_t      lock;
 58 };
 59 
 60 struct sk_buff {
 61         /* These two members must be first. */
 62         struct sk_buff  * next;                 /* Next buffer in list                          */
 63         struct sk_buff  * prev;                 /* Previous buffer in list                      */
 64 
 65         struct sk_buff_head * list;             /* List we are on                               */
 66         struct sock     *sk;                    /* Socket we are owned by                       */
 67         struct timeval  stamp;                  /* Time we arrived                              */
 68         struct net_device       *dev;           /* Device we arrived on/are leaving by          */
 69 
 70         /* Transport layer header */
 71         union
 72         {
 73                 struct tcphdr   *th;
 74                 struct udphdr   *uh;
 75                 struct icmphdr  *icmph;
 76                 struct igmphdr  *igmph;
 77                 struct iphdr    *ipiph;
 78                 struct spxhdr   *spxh;
 79                 unsigned char   *raw;
 80         } h;
 81 
 82         /* Network layer header */
 83         union
 84         {
 85                 struct iphdr    *iph;
 86                 struct ipv6hdr  *ipv6h;
 87                 struct arphdr   *arph;
 88                 struct ipxhdr   *ipxh;
 89                 unsigned char   *raw;
 90         } nh;
 91   
 92         /* Link layer header */
 93         union 
 94         {       
 95                 struct ethhdr   *ethernet;
 96                 unsigned char   *raw;
 97         } mac;
 98 
 99         struct  dst_entry *dst;
100 
101         /* 
102          * This is the control buffer. It is free to use for every
103          * layer. Please put your private variables there. If you
104          * want to keep them across layers you have to do a skb_clone()
105          * first. This is owned by whoever has the skb queued ATM.
106          */ 
107         char            cb[48];  
108 
109         unsigned int    len;                    /* Length of actual data                        */
110         unsigned int    csum;                   /* Checksum                                     */
111         volatile char   used;                   /* Data moved to user and not MSG_PEEK          */
112         unsigned char   cloned,                 /* head may be cloned (check refcnt to be sure). */
113                         pkt_type,               /* Packet class                                 */
114                         ip_summed;              /* Driver fed us an IP checksum                 */
115         __u32           priority;               /* Packet queueing priority                     */
116         atomic_t        users;                  /* User count - see datagram.c,tcp.c            */
117         unsigned short  protocol;               /* Packet protocol from driver.                 */
118         unsigned short  security;               /* Security level of packet                     */
119         unsigned int    truesize;               /* Buffer size                                  */
120 
121         unsigned char   *head;                  /* Head of buffer                               */
122         unsigned char   *data;                  /* Data head pointer                            */
123         unsigned char   *tail;                  /* Tail pointer                                 */
124         unsigned char   *end;                   /* End pointer                                  */
125         void            (*destructor)(struct sk_buff *);        /* Destruct function            */
126 #ifdef CONFIG_NETFILTER
127         /* Can be used for communication between hooks. */
128         unsigned long   nfmark;
129         /* Cache info */
130         __u32           nfcache;
131         /* Associated connection, if any */
132         struct nf_ct_info *nfct;
133 #ifdef CONFIG_NETFILTER_DEBUG
134         unsigned int nf_debug;
135 #endif
136 #endif /*CONFIG_NETFILTER*/
137 
138 #if defined(CONFIG_HIPPI)
139         union{
140                 __u32   ifield;
141         } private;
142 #endif
143 
144 #ifdef CONFIG_NET_SCHED
145        __u32           tc_index;               /* traffic control index */
146 #endif
147 };
148 
149 #define SK_WMEM_MAX     65535
150 #define SK_RMEM_MAX     65535
151 
152 #ifdef __KERNEL__
153 /*
154  *      Handling routines are only of interest to the kernel
155  */
156 #include <linux/malloc.h>
157 
158 #include <asm/system.h>
159 
160 extern void                     __kfree_skb(struct sk_buff *skb);
161 extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
162 extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
163 extern void                     kfree_skbmem(struct sk_buff *skb);
164 extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
165 extern struct sk_buff *         skb_copy(const struct sk_buff *skb, int priority);
166 extern struct sk_buff *         skb_copy_expand(const struct sk_buff *skb, 
167                                                 int newheadroom,
168                                                 int newtailroom,
169                                                 int priority);
170 #define dev_kfree_skb(a)        kfree_skb(a)
171 extern void     skb_over_panic(struct sk_buff *skb, int len, void *here);
172 extern void     skb_under_panic(struct sk_buff *skb, int len, void *here);
173 
174 /* Backwards compatibility */
175 #define skb_realloc_headroom(skb, nhr) skb_copy_expand(skb, nhr, skb_tailroom(skb), GFP_ATOMIC)
176 
177 /* Internal */
178 static inline atomic_t *skb_datarefp(struct sk_buff *skb)
179 {
180         return (atomic_t *)(skb->end);
181 }
182 
183 /**
184  *      skb_queue_empty - check if a queue is empty
185  *      @list: queue head
186  *
187  *      Returns true if the queue is empty, false otherwise.
188  */
189  
190 static inline int skb_queue_empty(struct sk_buff_head *list)
191 {
192         return (list->next == (struct sk_buff *) list);
193 }
194 
195 /**
196  *      skb_get - reference buffer
197  *      @skb: buffer to reference
198  *
199  *      Makes another reference to a socket buffer and returns a pointer
200  *      to the buffer.
201  */
202  
203 static inline struct sk_buff *skb_get(struct sk_buff *skb)
204 {
205         atomic_inc(&skb->users);
206         return skb;
207 }
208 
209 /*
210  * If users==1, we are the only owner and are can avoid redundant
211  * atomic change.
212  */
213  
214 /**
215  *      kfree_skb - free an sk_buff
216  *      @skb: buffer to free
217  *
218  *      Drop a reference to the buffer and free it if the usage count has
219  *      hit zero.
220  */
221  
222 static inline void kfree_skb(struct sk_buff *skb)
223 {
224         if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
225                 __kfree_skb(skb);
226 }
227 
228 /* Use this if you didn't touch the skb state [for fast switching] */
229 static inline void kfree_skb_fast(struct sk_buff *skb)
230 {
231         if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
232                 kfree_skbmem(skb);      
233 }
234 
235 /**
236  *      skb_cloned - is the buffer a clone
237  *      @skb: buffer to check
238  *
239  *      Returns true if the buffer was generated with skb_clone() and is
240  *      one of multiple shared copies of the buffer. Cloned buffers are
241  *      shared data so must not be written to under normal circumstances.
242  */
243 
244 static inline int skb_cloned(struct sk_buff *skb)
245 {
246         return skb->cloned && atomic_read(skb_datarefp(skb)) != 1;
247 }
248 
249 /**
250  *      skb_shared - is the buffer shared
251  *      @skb: buffer to check
252  *
253  *      Returns true if more than one person has a reference to this
254  *      buffer.
255  */
256  
257 static inline int skb_shared(struct sk_buff *skb)
258 {
259         return (atomic_read(&skb->users) != 1);
260 }
261 
262 /** 
263  *      skb_share_check - check if buffer is shared and if so clone it
264  *      @skb: buffer to check
265  *      @pri: priority for memory allocation
266  *      
267  *      If the buffer is shared the buffer is cloned and the old copy
268  *      drops a reference. A new clone with a single reference is returned.
269  *      If the buffer is not shared the original buffer is returned. When
270  *      being called from interrupt status or with spinlocks held pri must
271  *      be GFP_ATOMIC.
272  *
273  *      NULL is returned on a memory allocation failure.
274  */
275  
276 static inline struct sk_buff *skb_share_check(struct sk_buff *skb, int pri)
277 {
278         if (skb_shared(skb)) {
279                 struct sk_buff *nskb;
280                 nskb = skb_clone(skb, pri);
281                 kfree_skb(skb);
282                 return nskb;
283         }
284         return skb;
285 }
286 
287 
288 /*
289  *      Copy shared buffers into a new sk_buff. We effectively do COW on
290  *      packets to handle cases where we have a local reader and forward
291  *      and a couple of other messy ones. The normal one is tcpdumping
292  *      a packet thats being forwarded.
293  */
294  
295 /**
296  *      skb_unshare - make a copy of a shared buffer
297  *      @skb: buffer to check
298  *      @pri: priority for memory allocation
299  *
300  *      If the socket buffer is a clone then this function creates a new
301  *      copy of the data, drops a reference count on the old copy and returns
302  *      the new copy with the reference count at 1. If the buffer is not a clone
303  *      the original buffer is returned. When called with a spinlock held or
304  *      from interrupt state @pri must be %GFP_ATOMIC
305  *
306  *      %NULL is returned on a memory allocation failure.
307  */
308  
309 static inline struct sk_buff *skb_unshare(struct sk_buff *skb, int pri)
310 {
311         struct sk_buff *nskb;
312         if(!skb_cloned(skb))
313                 return skb;
314         nskb=skb_copy(skb, pri);
315         kfree_skb(skb);         /* Free our shared copy */
316         return nskb;
317 }
318 
319 /**
320  *      skb_peek
321  *      @list_: list to peek at
322  *
323  *      Peek an &sk_buff. Unlike most other operations you _MUST_
324  *      be careful with this one. A peek leaves the buffer on the
325  *      list and someone else may run off with it. You must hold
326  *      the appropriate locks or have a private queue to do this.
327  *
328  *      Returns %NULL for an empty list or a pointer to the head element.
329  *      The reference count is not incremented and the reference is therefore
330  *      volatile. Use with caution.
331  */
332  
333 static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
334 {
335         struct sk_buff *list = ((struct sk_buff *)list_)->next;
336         if (list == (struct sk_buff *)list_)
337                 list = NULL;
338         return list;
339 }
340 
341 /**
342  *      skb_peek_tail
343  *      @list_: list to peek at
344  *
345  *      Peek an &sk_buff. Unlike most other operations you _MUST_
346  *      be careful with this one. A peek leaves the buffer on the
347  *      list and someone else may run off with it. You must hold
348  *      the appropriate locks or have a private queue to do this.
349  *
350  *      Returns %NULL for an empty list or a pointer to the tail element.
351  *      The reference count is not incremented and the reference is therefore
352  *      volatile. Use with caution.
353  */
354 
355 static inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
356 {
357         struct sk_buff *list = ((struct sk_buff *)list_)->prev;
358         if (list == (struct sk_buff *)list_)
359                 list = NULL;
360         return list;
361 }
362 
363 /**
364  *      skb_queue_len   - get queue length
365  *      @list_: list to measure
366  *
367  *      Return the length of an &sk_buff queue. 
368  */
369  
370 static inline __u32 skb_queue_len(struct sk_buff_head *list_)
371 {
372         return(list_->qlen);
373 }
374 
375 static inline void skb_queue_head_init(struct sk_buff_head *list)
376 {
377         spin_lock_init(&list->lock);
378         list->prev = (struct sk_buff *)list;
379         list->next = (struct sk_buff *)list;
380         list->qlen = 0;
381 }
382 
383 /*
384  *      Insert an sk_buff at the start of a list.
385  *
386  *      The "__skb_xxxx()" functions are the non-atomic ones that
387  *      can only be called with interrupts disabled.
388  */
389 
390 /**
391  *      __skb_queue_head - queue a buffer at the list head
392  *      @list: list to use
393  *      @newsk: buffer to queue
394  *
395  *      Queue a buffer at the start of a list. This function takes no locks
396  *      and you must therefore hold required locks before calling it.
397  *
398  *      A buffer cannot be placed on two lists at the same time.
399  */     
400  
401 static inline void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
402 {
403         struct sk_buff *prev, *next;
404 
405         newsk->list = list;
406         list->qlen++;
407         prev = (struct sk_buff *)list;
408         next = prev->next;
409         newsk->next = next;
410         newsk->prev = prev;
411         next->prev = newsk;
412         prev->next = newsk;
413 }
414 
415 
416 /**
417  *      skb_queue_head - queue a buffer at the list head
418  *      @list: list to use
419  *      @newsk: buffer to queue
420  *
421  *      Queue a buffer at the start of the list. This function takes the
422  *      list lock and can be used safely with other locking &sk_buff functions
423  *      safely.
424  *
425  *      A buffer cannot be placed on two lists at the same time.
426  */     
427 
428 static inline void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
429 {
430         unsigned long flags;
431 
432         spin_lock_irqsave(&list->lock, flags);
433         __skb_queue_head(list, newsk);
434         spin_unlock_irqrestore(&list->lock, flags);
435 }
436 
437 /**
438  *      __skb_queue_tail - queue a buffer at the list tail
439  *      @list: list to use
440  *      @newsk: buffer to queue
441  *
442  *      Queue a buffer at the end of a list. This function takes no locks
443  *      and you must therefore hold required locks before calling it.
444  *
445  *      A buffer cannot be placed on two lists at the same time.
446  */     
447  
448 
449 static inline void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
450 {
451         struct sk_buff *prev, *next;
452 
453         newsk->list = list;
454         list->qlen++;
455         next = (struct sk_buff *)list;
456         prev = next->prev;
457         newsk->next = next;
458         newsk->prev = prev;
459         next->prev = newsk;
460         prev->next = newsk;
461 }
462 
463 /**
464  *      skb_queue_tail - queue a buffer at the list tail
465  *      @list: list to use
466  *      @newsk: buffer to queue
467  *
468  *      Queue a buffer at the tail of the list. This function takes the
469  *      list lock and can be used safely with other locking &sk_buff functions
470  *      safely.
471  *
472  *      A buffer cannot be placed on two lists at the same time.
473  */     
474 
475 static inline void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
476 {
477         unsigned long flags;
478 
479         spin_lock_irqsave(&list->lock, flags);
480         __skb_queue_tail(list, newsk);
481         spin_unlock_irqrestore(&list->lock, flags);
482 }
483 
484 /**
485  *      __skb_dequeue - remove from the head of the queue
486  *      @list: list to dequeue from
487  *
488  *      Remove the head of the list. This function does not take any locks
489  *      so must be used with appropriate locks held only. The head item is
490  *      returned or %NULL if the list is empty.
491  */
492 
493 static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
494 {
495         struct sk_buff *next, *prev, *result;
496 
497         prev = (struct sk_buff *) list;
498         next = prev->next;
499         result = NULL;
500         if (next != prev) {
501                 result = next;
502                 next = next->next;
503                 list->qlen--;
504                 next->prev = prev;
505                 prev->next = next;
506                 result->next = NULL;
507                 result->prev = NULL;
508                 result->list = NULL;
509         }
510         return result;
511 }
512 
513 /**
514  *      skb_dequeue - remove from the head of the queue
515  *      @list: list to dequeue from
516  *
517  *      Remove the head of the list. The list lock is taken so the function
518  *      may be used safely with other locking list functions. The head item is
519  *      returned or %NULL if the list is empty.
520  */
521 
522 static inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
523 {
524         long flags;
525         struct sk_buff *result;
526 
527         spin_lock_irqsave(&list->lock, flags);
528         result = __skb_dequeue(list);
529         spin_unlock_irqrestore(&list->lock, flags);
530         return result;
531 }
532 
533 /*
534  *      Insert a packet on a list.
535  */
536 
537 static inline void __skb_insert(struct sk_buff *newsk,
538         struct sk_buff * prev, struct sk_buff *next,
539         struct sk_buff_head * list)
540 {
541         newsk->next = next;
542         newsk->prev = prev;
543         next->prev = newsk;
544         prev->next = newsk;
545         newsk->list = list;
546         list->qlen++;
547 }
548 
549 /**
550  *      skb_insert      -       insert a buffer
551  *      @old: buffer to insert before
552  *      @newsk: buffer to insert
553  *
554  *      Place a packet before a given packet in a list. The list locks are taken
555  *      and this function is atomic with respect to other list locked calls
556  *      A buffer cannot be placed on two lists at the same time.
557  */
558 
559 static inline void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
560 {
561         unsigned long flags;
562 
563         spin_lock_irqsave(&old->list->lock, flags);
564         __skb_insert(newsk, old->prev, old, old->list);
565         spin_unlock_irqrestore(&old->list->lock, flags);
566 }
567 
568 /*
569  *      Place a packet after a given packet in a list.
570  */
571 
572 static inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk)
573 {
574         __skb_insert(newsk, old, old->next, old->list);
575 }
576 
577 /**
578  *      skb_append      -       append a buffer
579  *      @old: buffer to insert after
580  *      @newsk: buffer to insert
581  *
582  *      Place a packet after a given packet in a list. The list locks are taken
583  *      and this function is atomic with respect to other list locked calls.
584  *      A buffer cannot be placed on two lists at the same time.
585  */
586 
587 
588 static inline void skb_append(struct sk_buff *old, struct sk_buff *newsk)
589 {
590         unsigned long flags;
591 
592         spin_lock_irqsave(&old->list->lock, flags);
593         __skb_append(old, newsk);
594         spin_unlock_irqrestore(&old->list->lock, flags);
595 }
596 
597 /*
598  * remove sk_buff from list. _Must_ be called atomically, and with
599  * the list known..
600  */
601  
602 static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
603 {
604         struct sk_buff * next, * prev;
605 
606         list->qlen--;
607         next = skb->next;
608         prev = skb->prev;
609         skb->next = NULL;
610         skb->prev = NULL;
611         skb->list = NULL;
612         next->prev = prev;
613         prev->next = next;
614 }
615 
616 /**
617  *      skb_unlink      -       remove a buffer from a list
618  *      @skb: buffer to remove
619  *
620  *      Place a packet after a given packet in a list. The list locks are taken
621  *      and this function is atomic with respect to other list locked calls
622  *      
623  *      Works even without knowing the list it is sitting on, which can be 
624  *      handy at times. It also means that THE LIST MUST EXIST when you 
625  *      unlink. Thus a list must have its contents unlinked before it is
626  *      destroyed.
627  */
628 
629 static inline void skb_unlink(struct sk_buff *skb)
630 {
631         struct sk_buff_head *list = skb->list;
632 
633         if(list) {
634                 unsigned long flags;
635 
636                 spin_lock_irqsave(&list->lock, flags);
637                 if(skb->list == list)
638                         __skb_unlink(skb, skb->list);
639                 spin_unlock_irqrestore(&list->lock, flags);
640         }
641 }
642 
643 /* XXX: more streamlined implementation */
644 
645 /**
646  *      __skb_dequeue_tail - remove from the tail of the queue
647  *      @list: list to dequeue from
648  *
649  *      Remove the tail of the list. This function does not take any locks
650  *      so must be used with appropriate locks held only. The tail item is
651  *      returned or %NULL if the list is empty.
652  */
653 
654 static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
655 {
656         struct sk_buff *skb = skb_peek_tail(list); 
657         if (skb)
658                 __skb_unlink(skb, list);
659         return skb;
660 }
661 
662 /**
663  *      skb_dequeue - remove from the head of the queue
664  *      @list: list to dequeue from
665  *
666  *      Remove the head of the list. The list lock is taken so the function
667  *      may be used safely with other locking list functions. The tail item is
668  *      returned or %NULL if the list is empty.
669  */
670 
671 static inline struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
672 {
673         long flags;
674         struct sk_buff *result;
675 
676         spin_lock_irqsave(&list->lock, flags);
677         result = __skb_dequeue_tail(list);
678         spin_unlock_irqrestore(&list->lock, flags);
679         return result;
680 }
681 
682 /*
683  *      Add data to an sk_buff
684  */
685  
686 static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
687 {
688         unsigned char *tmp=skb->tail;
689         skb->tail+=len;
690         skb->len+=len;
691         return tmp;
692 }
693 
694 /**
695  *      skb_put - add data to a buffer
696  *      @skb: buffer to use 
697  *      @len: amount of data to add
698  *
699  *      This function extends the used data area of the buffer. If this would
700  *      exceed the total buffer size the kernel will panic. A pointer to the
701  *      first byte of the extra data is returned.
702  */
703  
704 static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
705 {
706         unsigned char *tmp=skb->tail;
707         skb->tail+=len;
708         skb->len+=len;
709         if(skb->tail>skb->end) {
710                 skb_over_panic(skb, len, current_text_addr());
711         }
712         return tmp;
713 }
714 
715 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
716 {
717         skb->data-=len;
718         skb->len+=len;
719         return skb->data;
720 }
721 
722 /**
723  *      skb_push - add data to the start of a buffer
724  *      @skb: buffer to use 
725  *      @len: amount of data to add
726  *
727  *      This function extends the used data area of the buffer at the buffer
728  *      start. If this would exceed the total buffer headroom the kernel will
729  *      panic. A pointer to the first byte of the extra data is returned.
730  */
731 
732 static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
733 {
734         skb->data-=len;
735         skb->len+=len;
736         if(skb->data<skb->head) {
737                 skb_under_panic(skb, len, current_text_addr());
738         }
739         return skb->data;
740 }
741 
742 static inline char *__skb_pull(struct sk_buff *skb, unsigned int len)
743 {
744         skb->len-=len;
745         return  skb->data+=len;
746 }
747 
748 /**
749  *      skb_pull - remove data from the start of a buffer
750  *      @skb: buffer to use 
751  *      @len: amount of data to remove
752  *
753  *      This function removes data from the start of a buffer, returning
754  *      the memory to the headroom. A pointer to the next data in the buffer
755  *      is returned. Once the data has been pulled future pushes will overwrite
756  *      the old data.
757  */
758 
759 static inline unsigned char * skb_pull(struct sk_buff *skb, unsigned int len)
760 {       
761         if (len > skb->len)
762                 return NULL;
763         return __skb_pull(skb,len);
764 }
765 
766 /**
767  *      skb_headroom - bytes at buffer head
768  *      @skb: buffer to check
769  *
770  *      Return the number of bytes of free space at the head of an &sk_buff.
771  */
772  
773 static inline int skb_headroom(const struct sk_buff *skb)
774 {
775         return skb->data-skb->head;
776 }
777 
778 /**
779  *      skb_tailroom - bytes at buffer end
780  *      @skb: buffer to check
781  *
782  *      Return the number of bytes of free space at the tail of an sk_buff
783  */
784 
785 static inline int skb_tailroom(const struct sk_buff *skb)
786 {
787         return skb->end-skb->tail;
788 }
789 
790 /**
791  *      skb_reserve - adjust headroom
792  *      @skb: buffer to alter
793  *      @len: bytes to move
794  *
795  *      Increase the headroom of an empty &sk_buff by reducing the tail
796  *      room. This is only allowed for an empty buffer.
797  */
798 
799 static inline void skb_reserve(struct sk_buff *skb, unsigned int len)
800 {
801         skb->data+=len;
802         skb->tail+=len;
803 }
804 
805 
806 static inline void __skb_trim(struct sk_buff *skb, unsigned int len)
807 {
808         skb->len = len;
809         skb->tail = skb->data+len;
810 }
811 
812 /**
813  *      skb_trim - remove end from a buffer
814  *      @skb: buffer to alter
815  *      @len: new length
816  *
817  *      Cut the length of a buffer down by removing data from the tail. If
818  *      the buffer is already under the length specified it is not modified.
819  */
820 
821 static inline void skb_trim(struct sk_buff *skb, unsigned int len)
822 {
823         if (skb->len > len) {
824                 __skb_trim(skb, len);
825         }
826 }
827 
828 /**
829  *      skb_orphan - orphan a buffer
830  *      @skb: buffer to orphan
831  *
832  *      If a buffer currently has an owner then we call the owner's
833  *      destructor function and make the @skb unowned. The buffer continues
834  *      to exist but is no longer charged to its former owner.
835  */
836 
837 
838 static inline void skb_orphan(struct sk_buff *skb)
839 {
840         if (skb->destructor)
841                 skb->destructor(skb);
842         skb->destructor = NULL;
843         skb->sk = NULL;
844 }
845 
846 /**
847  *      skb_purge - empty a list
848  *      @list: list to empty
849  *
850  *      Delete all buffers on an &sk_buff list. Each buffer is removed from
851  *      the list and one reference dropped. This function takes the list
852  *      lock and is atomic with respect to other list locking functions.
853  */
854 
855 
856 static inline void skb_queue_purge(struct sk_buff_head *list)
857 {
858         struct sk_buff *skb;
859         while ((skb=skb_dequeue(list))!=NULL)
860                 kfree_skb(skb);
861 }
862 
863 /**
864  *      __skb_purge - empty a list
865  *      @list: list to empty
866  *
867  *      Delete all buffers on an &sk_buff list. Each buffer is removed from
868  *      the list and one reference dropped. This function does not take the
869  *      list lock and the caller must hold the relevant locks to use it.
870  */
871 
872 
873 static inline void __skb_queue_purge(struct sk_buff_head *list)
874 {
875         struct sk_buff *skb;
876         while ((skb=__skb_dequeue(list))!=NULL)
877                 kfree_skb(skb);
878 }
879 
880 /**
881  *      dev_alloc_skb - allocate an skbuff for sending
882  *      @length: length to allocate
883  *
884  *      Allocate a new &sk_buff and assign it a usage count of one. The
885  *      buffer has unspecified headroom built in. Users should allocate
886  *      the headroom they think they need without accounting for the
887  *      built in space. The built in space is used for optimisations.
888  *
889  *      %NULL is returned in there is no free memory. Although this function
890  *      allocates memory it can be called from an interrupt.
891  */
892  
893 static inline struct sk_buff *dev_alloc_skb(unsigned int length)
894 {
895         struct sk_buff *skb;
896 
897         skb = alloc_skb(length+16, GFP_ATOMIC);
898         if (skb)
899                 skb_reserve(skb,16);
900         return skb;
901 }
902 
903 /**
904  *      skb_cow - copy a buffer if need be
905  *      @skb: buffer to copy
906  *      @headroom: needed headroom
907  *
908  *      If the buffer passed lacks sufficient headroom or is a clone then
909  *      it is copied and the additional headroom made available. If there
910  *      is no free memory %NULL is returned. The new buffer is returned if
911  *      a copy was made (and the old one dropped a reference). The existing
912  *      buffer is returned otherwise.
913  *
914  *      This function primarily exists to avoid making two copies when making
915  *      a writable copy of a buffer and then growing the headroom.
916  */
917  
918 
919 static inline struct sk_buff *
920 skb_cow(struct sk_buff *skb, unsigned int headroom)
921 {
922         headroom = (headroom+15)&~15;
923 
924         if ((unsigned)skb_headroom(skb) < headroom || skb_cloned(skb)) {
925                 struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
926                 kfree_skb(skb);
927                 skb = skb2;
928         }
929         return skb;
930 }
931 
932 #define skb_queue_walk(queue, skb) \
933                 for (skb = (queue)->next;                       \
934                      (skb != (struct sk_buff *)(queue));        \
935                      skb=skb->next)
936 
937 
938 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
939 extern unsigned int             datagram_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait);
940 extern int                      skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
941 extern int                      skb_copy_datagram_iovec(struct sk_buff *from, int offset, struct iovec *to,int size);
942 extern void                     skb_free_datagram(struct sock * sk, struct sk_buff *skb);
943 
944 extern void skb_init(void);
945 extern void skb_add_mtu(int mtu);
946 
947 #ifdef CONFIG_NETFILTER
948 static inline void
949 nf_conntrack_put(struct nf_ct_info *nfct)
950 {
951         if (nfct && atomic_dec_and_test(&nfct->master->use))
952                 nfct->master->destroy(nfct->master);
953 }
954 static inline void
955 nf_conntrack_get(struct nf_ct_info *nfct)
956 {
957         if (nfct)
958                 atomic_inc(&nfct->master->use);
959 }
960 #endif
961 
962 #endif  /* __KERNEL__ */
963 #endif  /* _LINUX_SKBUFF_H */
964 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.