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

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