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

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