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

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