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

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