root/include/linux/skbuff.h

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

INCLUDED FROM


DEFINITIONS

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

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