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

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