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_append
  15. __skb_unlink
  16. skb_unlink
  17. skb_put
  18. skb_push
  19. skb_pull
  20. skb_headroom
  21. skb_tailroom
  22. skb_reserve
  23. 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  * next;
  37         struct sk_buff  * 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  * next;                 /* Next buffer in list                          */
  49         struct sk_buff  * 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 file handles in a unix domain socket */
  67                 void *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 extern __inline__ int skb_queue_empty(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         return (list->next == (struct sk_buff *) list);
 167 }
 168 
 169 /*
 170  *      Peek an sk_buff. Unlike most other operations you _MUST_
 171  *      be careful with this one. A peek leaves the buffer on the
 172  *      list and someone else may run off with it. For an interrupt
 173  *      type system cli() peek the buffer copy the data and sti();
 174  */
 175 extern __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 176 {
 177         struct sk_buff *list = ((struct sk_buff *)list_)->next;
 178         if (list == (struct sk_buff *)list_)
 179                 list = NULL;
 180         return list;
 181 }
 182 
 183 /*
 184  *      Return the length of an sk_buff queue
 185  */
 186  
 187 extern __inline__ __u32 skb_queue_len(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 188 {
 189         return(list_->qlen);
 190 }
 191 
 192 #if CONFIG_SKB_CHECK
 193 extern int                      skb_check(struct sk_buff *skb,int,int, char *);
 194 #define IS_SKB(skb)             skb_check((skb), 0, __LINE__,__FILE__)
 195 #define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__,__FILE__)
 196 #else
 197 #define IS_SKB(skb)             
 198 #define IS_SKB_HEAD(skb)        
 199 
 200 extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 {
 202         list->prev = (struct sk_buff *)list;
 203         list->next = (struct sk_buff *)list;
 204         list->qlen = 0;
 205 }
 206 
 207 /*
 208  *      Insert an sk_buff at the start of a list.
 209  *
 210  *      The "__skb_xxxx()" functions are the non-atomic ones that
 211  *      can only be called with interrupts disabled.
 212  */
 213 
 214 extern __inline__ void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216         struct sk_buff *prev, *next;
 217 
 218         newsk->list = list;
 219         list->qlen++;
 220         prev = (struct sk_buff *)list;
 221         next = prev->next;
 222         newsk->next = next;
 223         newsk->prev = prev;
 224         next->prev = newsk;
 225         prev->next = newsk;
 226 }
 227 
 228 extern __inline__ void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         unsigned long flags;
 231 
 232         save_flags(flags);
 233         cli();
 234         __skb_queue_head(list, newsk);
 235         restore_flags(flags);
 236 }
 237 
 238 /*
 239  *      Insert an sk_buff at the end of a list.
 240  */
 241 
 242 extern __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 243 {
 244         struct sk_buff *prev, *next;
 245 
 246         newsk->list = list;
 247         list->qlen++;
 248         next = (struct sk_buff *)list;
 249         prev = next->prev;
 250         newsk->next = next;
 251         newsk->prev = prev;
 252         next->prev = newsk;
 253         prev->next = newsk;
 254 }
 255 
 256 extern __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258         unsigned long flags;
 259 
 260         save_flags(flags);
 261         cli();
 262         __skb_queue_tail(list, newsk);
 263         restore_flags(flags);
 264 }
 265 
 266 /*
 267  *      Remove an sk_buff from a list.
 268  */
 269 
 270 extern __inline__ struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 271 {
 272         struct sk_buff *next, *prev, *result;
 273 
 274         prev = (struct sk_buff *) list;
 275         next = prev->next;
 276         result = NULL;
 277         if (next != prev) {
 278                 result = next;
 279                 next = next->next;
 280                 list->qlen--;
 281                 next->prev = prev;
 282                 prev->next = next;
 283                 result->next = NULL;
 284                 result->prev = NULL;
 285                 result->list = NULL;
 286         }
 287         return result;
 288 }
 289 
 290 extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 291 {
 292         long flags;
 293         struct sk_buff *result;
 294 
 295         save_flags(flags);
 296         cli();
 297         result = __skb_dequeue(list);
 298         restore_flags(flags);
 299         return result;
 300 }
 301 
 302 /*
 303  *      Insert a packet before another one in a list.
 304  */
 305 
 306 extern __inline__ void __skb_insert(struct sk_buff *next, struct sk_buff *newsk,
     /* [previous][next][first][last][top][bottom][index][help] */
 307         struct sk_buff_head * list)
 308 {
 309         struct sk_buff * prev = next->prev;
 310 
 311         newsk->next = next;
 312         newsk->prev = prev;
 313         next->prev = newsk;
 314         prev->next = newsk;
 315         newsk->list = list;
 316         list->qlen++;
 317 }
 318 
 319 extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 320 {
 321         unsigned long flags;
 322 
 323         save_flags(flags);
 324         cli();
 325         __skb_insert(old, newsk, old->list);
 326         restore_flags(flags);
 327 }
 328 
 329 /*
 330  *      Place a packet after a given packet in a list.
 331  */
 332 
 333 extern __inline__ void __skb_append(struct sk_buff *prev, struct sk_buff *newsk,
     /* [previous][next][first][last][top][bottom][index][help] */
 334         struct sk_buff_head * list)
 335 {
 336         struct sk_buff * next = prev->next;
 337 
 338         newsk->next = next;
 339         newsk->prev = prev;
 340         next->prev = newsk;
 341         prev->next = newsk;
 342         newsk->list = list;
 343         list->qlen++;
 344 }
 345 
 346 extern __inline__ void skb_append(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 347 {
 348         unsigned long flags;
 349 
 350         save_flags(flags);
 351         cli();
 352         __skb_append(old, newsk, old->list);
 353         restore_flags(flags);
 354 }
 355 
 356 /*
 357  * remove sk_buff from list. _Must_ be called atomically, and with
 358  * the list known..
 359  */
 360 extern __inline__ void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 361 {
 362         struct sk_buff * next, * prev;
 363 
 364         list->qlen--;
 365         next = skb->next;
 366         prev = skb->prev;
 367         skb->next = NULL;
 368         skb->prev = NULL;
 369         skb->list = NULL;
 370         next->prev = prev;
 371         prev->next = next;
 372 }
 373 
 374 /*
 375  *      Remove an sk_buff from its list. Works even without knowing the list it
 376  *      is sitting on, which can be handy at times. It also means that THE LIST
 377  *      MUST EXIST when you unlink. Thus a list must have its contents unlinked
 378  *      _FIRST_.
 379  */
 380 
 381 extern __inline__ void skb_unlink(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 382 {
 383         unsigned long flags;
 384 
 385         save_flags(flags);
 386         cli();
 387         if(skb->list)
 388                 __skb_unlink(skb, skb->list);
 389         restore_flags(flags);
 390 }
 391 
 392 /*
 393  *      Add data to an sk_buff
 394  */
 395  
 396 extern __inline__ unsigned char *skb_put(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 397 {
 398         unsigned char *tmp=skb->tail;
 399         skb->tail+=len;
 400         skb->len+=len;
 401         if(skb->tail>skb->end)
 402                 panic("skput:over: %p:%d", __builtin_return_address(0),len);
 403         return tmp;
 404 }
 405 
 406 extern __inline__ unsigned char *skb_push(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 407 {
 408         skb->data-=len;
 409         skb->len+=len;
 410         if(skb->data<skb->head)
 411                 panic("skpush:under: %p:%d", __builtin_return_address(0),len);
 412         return skb->data;
 413 }
 414 
 415 extern __inline__ unsigned char * skb_pull(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417         if(len > skb->len)
 418                 return NULL;
 419         skb->data+=len;
 420         skb->len-=len;
 421         return skb->data;
 422 }
 423 
 424 extern __inline__ int skb_headroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 425 {
 426         return skb->data-skb->head;
 427 }
 428 
 429 extern __inline__ int skb_tailroom(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 430 {
 431         return skb->end-skb->tail;
 432 }
 433 
 434 extern __inline__ void skb_reserve(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 435 {
 436         skb->data+=len;
 437         skb->tail+=len;
 438 }
 439 
 440 extern __inline__ void skb_trim(struct sk_buff *skb, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 441 {
 442         if(skb->len>len)
 443         {
 444                 skb->len=len;
 445                 skb->tail=skb->data+len;
 446         }
 447 }
 448 
 449 #endif
 450 
 451 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
 452 extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
 453 extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
 454 extern void                     skb_copy_datagram_iovec(struct sk_buff *from, int offset, struct iovec *to,int size);
 455 extern void                     skb_free_datagram(struct sock * sk, struct sk_buff *skb);
 456 
 457 #endif  /* __KERNEL__ */
 458 #endif  /* _LINUX_SKBUFF_H */

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