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

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