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 
  17 #include <linux/config.h>
  18 #include <linux/time.h>
  19 
  20 #include <asm/atomic.h>
  21 #include <asm/types.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 #include <linux/malloc.h>
 135 
 136 #include <asm/system.h>
 137 
 138 #if 0
 139 extern void                     print_skb(struct sk_buff *);
 140 #endif
 141 extern void                     kfree_skb(struct sk_buff *skb, int rw);
 142 extern void                     skb_queue_head_init(struct sk_buff_head *list);
 143 extern void                     skb_queue_head(struct sk_buff_head *list,struct sk_buff *buf);
 144 extern void                     skb_queue_tail(struct sk_buff_head *list,struct sk_buff *buf);
 145 extern struct sk_buff *         skb_dequeue(struct sk_buff_head *list);
 146 extern void                     skb_insert(struct sk_buff *old,struct sk_buff *newsk);
 147 extern void                     skb_append(struct sk_buff *old,struct sk_buff *newsk);
 148 extern void                     skb_unlink(struct sk_buff *buf);
 149 extern __u32                    skb_queue_len(struct sk_buff_head *list);
 150 extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
 151 extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
 152 extern struct sk_buff *         dev_alloc_skb(unsigned int size);
 153 extern void                     kfree_skbmem(struct sk_buff *skb);
 154 extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
 155 extern struct sk_buff *         skb_copy(struct sk_buff *skb, int priority);
 156 extern void                     skb_device_lock(struct sk_buff *skb);
 157 extern void                     skb_device_unlock(struct sk_buff *skb);
 158 extern void                     dev_kfree_skb(struct sk_buff *skb, int mode);
 159 extern int                      skb_device_locked(struct sk_buff *skb);
 160 extern unsigned char *          skb_put(struct sk_buff *skb, int len);
 161 extern unsigned char *          skb_push(struct sk_buff *skb, int len);
 162 extern unsigned char *          skb_pull(struct sk_buff *skb, int len);
 163 extern int                      skb_headroom(struct sk_buff *skb);
 164 extern int                      skb_tailroom(struct sk_buff *skb);
 165 extern void                     skb_reserve(struct sk_buff *skb, int len);
 166 extern void                     skb_trim(struct sk_buff *skb, int len);
 167 
 168 extern __inline__ int skb_queue_empty(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170         return (list->next == (struct sk_buff *) list);
 171 }
 172 
 173 /*
 174  *      Peek an sk_buff. Unlike most other operations you _MUST_
 175  *      be careful with this one. A peek leaves the buffer on the
 176  *      list and someone else may run off with it. For an interrupt
 177  *      type system cli() peek the buffer copy the data and sti();
 178  */
 179 extern __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 180 {
 181         struct sk_buff *list = ((struct sk_buff *)list_)->next;
 182         if (list == (struct sk_buff *)list_)
 183                 list = NULL;
 184         return list;
 185 }
 186 
 187 /*
 188  *      Return the length of an sk_buff queue
 189  */
 190  
 191 extern __inline__ __u32 skb_queue_len(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 192 {
 193         return(list_->qlen);
 194 }
 195 
 196 #if CONFIG_SKB_CHECK
 197 extern int                      skb_check(struct sk_buff *skb,int,int, char *);
 198 #define IS_SKB(skb)             skb_check((skb), 0, __LINE__,__FILE__)
 199 #define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__,__FILE__)
 200 #else
 201 #define IS_SKB(skb)             
 202 #define IS_SKB_HEAD(skb)        
 203 
 204 extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 205 {
 206         list->prev = (struct sk_buff *)list;
 207         list->next = (struct sk_buff *)list;
 208         list->qlen = 0;
 209 }
 210 
 211 /*
 212  *      Insert an sk_buff at the start of a list.
 213  *
 214  *      The "__skb_xxxx()" functions are the non-atomic ones that
 215  *      can only be called with interrupts disabled.
 216  */
 217 
 218 extern __inline__ void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 219 {
 220         struct sk_buff *prev, *next;
 221 
 222         newsk->list = list;
 223         list->qlen++;
 224         prev = (struct sk_buff *)list;
 225         next = prev->next;
 226         newsk->next = next;
 227         newsk->prev = prev;
 228         next->prev = newsk;
 229         prev->next = newsk;
 230 }
 231 
 232 extern __inline__ void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 233 {
 234         unsigned long flags;
 235 
 236         save_flags(flags);
 237         cli();
 238         __skb_queue_head(list, newsk);
 239         restore_flags(flags);
 240 }
 241 
 242 /*
 243  *      Insert an sk_buff at the end of a list.
 244  */
 245 
 246 extern __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 247 {
 248         struct sk_buff *prev, *next;
 249 
 250         newsk->list = list;
 251         list->qlen++;
 252         next = (struct sk_buff *)list;
 253         prev = next->prev;
 254         newsk->next = next;
 255         newsk->prev = prev;
 256         next->prev = newsk;
 257         prev->next = newsk;
 258 }
 259 
 260 extern __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 {
 262         unsigned long flags;
 263 
 264         save_flags(flags);
 265         cli();
 266         __skb_queue_tail(list, newsk);
 267         restore_flags(flags);
 268 }
 269 
 270 /*
 271  *      Remove an sk_buff from a list.
 272  */
 273 
 274 extern __inline__ struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 275 {
 276         struct sk_buff *next, *prev, *result;
 277 
 278         prev = (struct sk_buff *) list;
 279         next = prev->next;
 280         result = NULL;
 281         if (next != prev) {
 282                 result = next;
 283                 next = next->next;
 284                 list->qlen--;
 285                 next->prev = prev;
 286                 prev->next = next;
 287                 result->next = NULL;
 288                 result->prev = NULL;
 289                 result->list = NULL;
 290         }
 291         return result;
 292 }
 293 
 294 extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 295 {
 296         long flags;
 297         struct sk_buff *result;
 298 
 299         save_flags(flags);
 300         cli();
 301         result = __skb_dequeue(list);
 302         restore_flags(flags);
 303         return result;
 304 }
 305 
 306 /*
 307  *      Insert a packet on a list.
 308  */
 309 
 310 extern __inline__ void __skb_insert(struct sk_buff *newsk,
     /* [previous][next][first][last][top][bottom][index][help] */
 311         struct sk_buff * prev, struct sk_buff *next,
 312         struct sk_buff_head * list)
 313 {
 314         newsk->next = next;
 315         newsk->prev = prev;
 316         next->prev = newsk;
 317         prev->next = newsk;
 318         newsk->list = list;
 319         list->qlen++;
 320 }
 321 
 322 /*
 323  *      Place a packet before a given packet in a list
 324  */
 325 extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 326 {
 327         unsigned long flags;
 328 
 329         save_flags(flags);
 330         cli();
 331         __skb_insert(newsk, old->prev, old, old->list);
 332         restore_flags(flags);
 333 }
 334 
 335 /*
 336  *      Place a packet after a given packet in a list.
 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_insert(newsk, old, old->next, old->list);
 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         {
 396                 __label__ here;
 397                 panic("skput:over: %p:%d", &&here,len);
 398 here:
 399         }
 400         return tmp;
 401 }
 402 
 403 extern __inline__ unsigned char *skb_push(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 404 {
 405         skb->data-=len;
 406         skb->len+=len;
 407         if(skb->data<skb->head)
 408         {
 409                 __label__ here;
 410                 panic("skpush:under: %p:%d", &&here,len);
 411 here:
 412         }
 413         return skb->data;
 414 }
 415 
 416 extern __inline__ unsigned char * skb_pull(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418         if(len > skb->len)
 419                 return NULL;
 420         skb->data+=len;
 421         skb->len-=len;
 422         return skb->data;
 423 }
 424 
 425 extern __inline__ int skb_headroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 426 {
 427         return skb->data-skb->head;
 428 }
 429 
 430 extern __inline__ int skb_tailroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 431 {
 432         return skb->end-skb->tail;
 433 }
 434 
 435 extern __inline__ void skb_reserve(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 436 {
 437         skb->data+=len;
 438         skb->tail+=len;
 439 }
 440 
 441 extern __inline__ void skb_trim(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 442 {
 443         if(skb->len>len)
 444         {
 445                 skb->len=len;
 446                 skb->tail=skb->data+len;
 447         }
 448 }
 449 
 450 #endif
 451 
 452 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
 453 extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
 454 extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
 455 extern void                     skb_copy_datagram_iovec(struct sk_buff *from, int offset, struct iovec *to,int size);
 456 extern void                     skb_free_datagram(struct sock * sk, struct sk_buff *skb);
 457 
 458 #endif  /* __KERNEL__ */
 459 #endif  /* _LINUX_SKBUFF_H */

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