root/include/linux/skbuff.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. skb_peek
  2. skb_queue_head_init
  3. skb_queue_head
  4. skb_queue_tail
  5. skb_dequeue
  6. skb_insert
  7. skb_append
  8. skb_unlink
  9. skb_put
  10. skb_push
  11. skb_pull
  12. skb_headroom
  13. skb_tailroom
  14. skb_reserve
  15. skb_trim

   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 #include <linux/malloc.h>
  17 #include <linux/wait.h>
  18 #include <linux/time.h>
  19 #include <linux/config.h>
  20 
  21 #define CONFIG_SKB_CHECK 0
  22 
  23 #define HAVE_ALLOC_SKB          /* For the drivers to know */
  24 #define HAVE_ALIGNABLE_SKB      /* Ditto 8)                */
  25 
  26 
  27 #define FREE_READ       1
  28 #define FREE_WRITE      0
  29 
  30 
  31 struct sk_buff_head {
  32   struct sk_buff                * volatile next;
  33   struct sk_buff                * volatile prev;
  34 #if CONFIG_SKB_CHECK
  35   int                           magic_debug_cookie;
  36 #endif
  37 };
  38 
  39 
  40 struct sk_buff {
  41   struct sk_buff                * volatile next;        /* Next buffer in list */
  42   struct sk_buff                * volatile prev;        /* Previous buffer in list */
  43 #if CONFIG_SKB_CHECK
  44   int                           magic_debug_cookie;
  45 #endif
  46   struct sk_buff                * volatile link3;       /* Link for IP protocol level buffer chains     */
  47   struct sock                   *sk;                    /* Socket we are owned by                       */
  48   volatile unsigned long        when;                   /* used to compute rtt's                        */
  49   struct timeval                stamp;                  /* Time we arrived                              */
  50   struct device                 *dev;                   /* Device we arrived on/are leaving by          */
  51   union {
  52         struct tcphdr   *th;
  53         struct ethhdr   *eth;
  54         struct iphdr    *iph;
  55         struct udphdr   *uh;
  56         unsigned char   *raw;
  57         unsigned long   seq;
  58   } h;
  59   
  60   union {                                               /* As yet incomplete physical layer views       */
  61         unsigned char           *raw;
  62         struct ethhdr           *ethernet;
  63   } mac;
  64   
  65   struct iphdr                  *ip_hdr;                /* For IPPROTO_RAW                              */
  66   unsigned long                 len;                    /* Length of actual data                        */
  67   unsigned long                 saddr;                  /* IP source address                            */
  68   unsigned long                 daddr;                  /* IP target address                            */
  69   unsigned long                 raddr;                  /* IP next hop address                          */
  70   unsigned long                 csum;                   /* Checksum                                     */
  71   volatile char                 acked,                  /* Are we acked ?                               */
  72                                 used,                   /* Are we in use ?                              */
  73                                 free,                   /* How to free this buffer                      */
  74                                 arp;                    /* Has IP/ARP resolution finished               */
  75   unsigned char                 tries,                  /* Times tried                                  */
  76                                 lock,                   /* Are we locked ?                              */
  77                                 localroute,             /* Local routing asserted for this frame        */
  78                                 pkt_type,               /* Packet class                                 */
  79                                 ip_summed;              /* Driver fed us an IP checksum                 */
  80 #define PACKET_HOST             0                       /* To us                                        */
  81 #define PACKET_BROADCAST        1                       /* To all                                       */
  82 #define PACKET_MULTICAST        2                       /* To group                                     */
  83 #define PACKET_OTHERHOST        3                       /* To someone else                              */
  84   unsigned short                users;                  /* User count - see datagram.c,tcp.c            */
  85   unsigned short                protocol;               /* Packet protocol from driver.                 */
  86   unsigned short                truesize;               /* Buffer size                                  */
  87   unsigned char                 *head;                  /* Head of buffer                               */
  88   unsigned char                 *data;                  /* Data head pointer                            */
  89   unsigned char                 *tail;                  /* Tail pointer                                 */
  90   unsigned char                 *end;                   /* End pointer                                  */
  91 };
  92 
  93 #define SK_WMEM_MAX     32767
  94 #define SK_RMEM_MAX     32767
  95 
  96 #if CONFIG_SKB_CHECK
  97 #define SK_FREED_SKB    0x0DE2C0DE
  98 #define SK_GOOD_SKB     0xDEC0DED1
  99 #define SK_HEAD_SKB     0x12231298
 100 #endif
 101 
 102 #ifdef __KERNEL__
 103 /*
 104  *      Handling routines are only of interest to the kernel
 105  */
 106 
 107 #include <asm/system.h>
 108 
 109 #if 0
 110 extern void                     print_skb(struct sk_buff *);
 111 #endif
 112 extern void                     kfree_skb(struct sk_buff *skb, int rw);
 113 extern void                     skb_queue_head_init(struct sk_buff_head *list);
 114 extern void                     skb_queue_head(struct sk_buff_head *list,struct sk_buff *buf);
 115 extern void                     skb_queue_tail(struct sk_buff_head *list,struct sk_buff *buf);
 116 extern struct sk_buff *         skb_dequeue(struct sk_buff_head *list);
 117 extern void                     skb_insert(struct sk_buff *old,struct sk_buff *newsk);
 118 extern void                     skb_append(struct sk_buff *old,struct sk_buff *newsk);
 119 extern void                     skb_unlink(struct sk_buff *buf);
 120 extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
 121 extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
 122 extern struct sk_buff *         dev_alloc_skb(unsigned int size);
 123 extern void                     kfree_skbmem(struct sk_buff *skb);
 124 extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
 125 extern void                     skb_device_lock(struct sk_buff *skb);
 126 extern void                     skb_device_unlock(struct sk_buff *skb);
 127 extern void                     dev_kfree_skb(struct sk_buff *skb, int mode);
 128 extern int                      skb_device_locked(struct sk_buff *skb);
 129 extern unsigned char *          skb_put(struct sk_buff *skb, int len);
 130 extern unsigned char *          skb_push(struct sk_buff *skb, int len);
 131 extern int                      skb_pull(struct sk_buff *skb, int len);
 132 extern int                      skb_headroom(struct sk_buff *skb);
 133 extern int                      skb_tailroom(struct sk_buff *skb);
 134 extern void                     skb_reserve(struct sk_buff *skb, int len);
 135 extern void                     skb_trim(struct sk_buff *skb, int len);
 136 
 137 /*
 138  *      Peek an sk_buff. Unlike most other operations you _MUST_
 139  *      be careful with this one. A peek leaves the buffer on the
 140  *      list and someone else may run off with it. For an interrupt
 141  *      type system cli() peek the buffer copy the data and sti();
 142  */
 143 static __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 144 {
 145         struct sk_buff *list = (struct sk_buff *)list_;
 146         return (list->next != list)? list->next : NULL;
 147 }
 148 
 149 #if CONFIG_SKB_CHECK
 150 extern int                      skb_check(struct sk_buff *skb,int,int, char *);
 151 #define IS_SKB(skb)             skb_check((skb), 0, __LINE__,__FILE__)
 152 #define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__,__FILE__)
 153 #else
 154 #define IS_SKB(skb)             
 155 #define IS_SKB_HEAD(skb)        
 156 
 157 extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159         list->prev = (struct sk_buff *)list;
 160         list->next = (struct sk_buff *)list;
 161 }
 162 
 163 /*
 164  *      Insert an sk_buff at the start of a list.
 165  */
 166 
 167 extern __inline__ void skb_queue_head(struct sk_buff_head *list_,struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 168 {
 169         unsigned long flags;
 170         struct sk_buff *list = (struct sk_buff *)list_;
 171 
 172         save_flags(flags);
 173         cli();
 174         newsk->next = list->next;
 175         newsk->prev = list;
 176         newsk->next->prev = newsk;
 177         newsk->prev->next = newsk;
 178         restore_flags(flags);
 179 }
 180 
 181 /*
 182  *      Insert an sk_buff at the end of a list.
 183  */
 184 
 185 extern __inline__ void skb_queue_tail(struct sk_buff_head *list_, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 186 {
 187         unsigned long flags;
 188         struct sk_buff *list = (struct sk_buff *)list_;
 189 
 190         save_flags(flags);
 191         cli();
 192 
 193         newsk->next = list;
 194         newsk->prev = list->prev;
 195 
 196         newsk->next->prev = newsk;
 197         newsk->prev->next = newsk;
 198 
 199         restore_flags(flags);
 200 }
 201 
 202 /*
 203  *      Remove an sk_buff from a list. This routine is also interrupt safe
 204  *      so you can grab read and free buffers as another process adds them.
 205  *
 206  *      Note we now do the ful list 
 207  */
 208 
 209 extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 {
 211         long flags;
 212         struct sk_buff *result;
 213         struct sk_buff *list = (struct sk_buff *)list_;
 214 
 215         save_flags(flags);
 216         cli();
 217 
 218         result = list->next;
 219         if (result == list) 
 220         {
 221                 restore_flags(flags);
 222                 return NULL;
 223         }
 224         else
 225         {
 226                 result->next->prev = list;
 227                 list->next = result->next;
 228 
 229                 result->next = NULL;
 230                 result->prev = NULL;
 231 
 232                 restore_flags(flags);
 233 
 234                 return result;
 235         }
 236 }
 237 
 238 /*
 239  *      Insert a packet before another one in a list.
 240  */
 241 
 242 extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 243 {
 244         unsigned long flags;
 245 
 246         save_flags(flags);
 247         cli();
 248         newsk->next = old;
 249         newsk->prev = old->prev;
 250         old->prev = newsk;
 251         newsk->prev->next = newsk;
 252 
 253         restore_flags(flags);
 254 }
 255 
 256 /*
 257  *      Place a packet after a given packet in a list.
 258  */
 259 
 260 extern __inline__ void skb_append(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 {
 262         unsigned long flags;
 263 
 264         save_flags(flags);
 265         cli();
 266 
 267         newsk->prev = old;
 268         newsk->next = old->next;
 269         newsk->next->prev = newsk;
 270         old->next = newsk;
 271 
 272         restore_flags(flags);
 273 }
 274 
 275 /*
 276  *      Remove an sk_buff from its list. Works even without knowing the list it
 277  *      is sitting on, which can be handy at times. It also means that THE LIST
 278  *      MUST EXIST when you unlink. Thus a list must have its contents unlinked
 279  *      _FIRST_.
 280  */
 281 
 282 extern __inline__ void skb_unlink(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 283 {
 284         unsigned long flags;
 285 
 286         save_flags(flags);
 287         cli();
 288 
 289         if(skb->prev && skb->next)
 290         {
 291                 skb->next->prev = skb->prev;
 292                 skb->prev->next = skb->next;
 293                 skb->next = NULL;
 294                 skb->prev = NULL;
 295         }
 296         restore_flags(flags);
 297 }
 298 
 299 /*
 300  *      Add data to an sk_buff
 301  */
 302  
 303 extern __inline__ unsigned char *skb_put(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 304 {
 305         unsigned char *tmp=skb->tail;
 306         skb->tail+=len;
 307         skb->len+=len;
 308         if(skb->tail>skb->end)
 309                 panic("skput:over: %p:%d", __builtin_return_address(0),len);
 310         return tmp;
 311 }
 312 
 313 extern __inline__ unsigned char *skb_push(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 314 {
 315         skb->data-=len;
 316         skb->len+=len;
 317         if(skb->data<skb->head)
 318                 panic("skpush:under: %p:%d", __builtin_return_address(0),len);
 319         return skb->data;
 320 }
 321 
 322 extern __inline__ int skb_pull(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 323 {
 324         if(len>skb->len)
 325                 len=skb->len;
 326         skb->data+=len;
 327         skb->len-=len;
 328         return len;
 329 }
 330 
 331 extern __inline__ int skb_headroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 332 {
 333         return skb->data-skb->head;
 334 }
 335 
 336 extern __inline__ int skb_tailroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 337 {
 338         return skb->end-skb->tail;
 339 }
 340 
 341 extern __inline__ void skb_reserve(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 342 {
 343         skb->data+=len;
 344         skb->tail+=len;
 345 }
 346 
 347 extern __inline__ void skb_trim(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 348 {
 349         if(skb->len>len)
 350         {
 351                 skb->len=len;
 352                 skb->tail=skb->data+len;
 353         }
 354 }
 355 
 356 #endif
 357 
 358 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
 359 extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
 360 extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
 361 extern void                     skb_free_datagram(struct sk_buff *skb);
 362 
 363 #endif  /* __KERNEL__ */
 364 #endif  /* _LINUX_SKBUFF_H */

/* [previous][next][first][last][top][bottom][index][help] */