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

   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 #undef CONFIG_SKB_CHECK
  22 
  23 #define HAVE_ALLOC_SKB          /* For the drivers to know */
  24 
  25 
  26 #define FREE_READ       1
  27 #define FREE_WRITE      0
  28 
  29 
  30 struct sk_buff_head {
  31   struct sk_buff                * volatile next;
  32   struct sk_buff                * volatile prev;
  33 #if CONFIG_SKB_CHECK
  34   int                           magic_debug_cookie;
  35 #endif
  36 };
  37 
  38 
  39 struct sk_buff {
  40   struct sk_buff                * volatile next;        /* Next buffer in list */
  41   struct sk_buff                * volatile prev;        /* Previous buffer in list */
  42 #if CONFIG_SKB_CHECK
  43   int                           magic_debug_cookie;
  44 #endif
  45   struct sk_buff                * volatile link3;       /* Link for IP protocol level buffer chains     */
  46   struct sock                   *sk;                    /* Socket we are owned by                       */
  47   volatile unsigned long        when;                   /* used to compute rtt's                        */
  48   struct timeval                stamp;                  /* Time we arrived                              */
  49   struct device                 *dev;                   /* Device we arrived on/are leaving by          */
  50   struct sk_buff                *mem_addr;              /* Self reference (obsolete)                    */
  51   union {
  52         struct tcphdr   *th;
  53         struct ethhdr   *eth;
  54         struct iphdr    *iph;
  55         struct udphdr   *uh;
  56         unsigned char   *raw;
  57         unsigned long   seq;
  58   } h;
  59   struct iphdr                  *ip_hdr;                /* For IPPROTO_RAW                              */
  60   unsigned long                 mem_len;                /* Length of allocated memory                   */
  61   unsigned long                 len;                    /* Length of actual data                        */
  62   unsigned long                 fraglen;                /* Unused (yet)                                 */
  63   struct sk_buff                *fraglist;              /* Fragment list                                */
  64   unsigned long                 truesize;               /* True buffer size (obsolete)                  */
  65   unsigned long                 saddr;                  /* IP source address                            */
  66   unsigned long                 daddr;                  /* IP target address                            */
  67   unsigned long                 raddr;                  /* IP next hop address                          */
  68   volatile char                 acked,                  /* Are we acked ?                               */
  69                                 used,                   /* Are we in use ?                              */
  70                                 free,                   /* How to free this buffer                      */
  71                                 arp;                    /* Has IP/ARP resolution finished               */
  72   unsigned char                 tries,                  /* Times tried                                  */
  73                                 lock,                   /* Are we locked ?                              */
  74                                 localroute,             /* Local routing asserted for this frame        */
  75                                 pkt_type;               /* Packet class                                 */
  76 #define PACKET_HOST             0                       /* To us                                        */
  77 #define PACKET_BROADCAST        1                       /* To all                                       */
  78 #define PACKET_MULTICAST        2                       /* To group                                     */
  79 #define PACKET_OTHERHOST        3                       /* To someone else                              */
  80   unsigned short                users;                  /* User count - see datagram.c,tcp.c            */
  81   unsigned short                protocol;               /* Packet protocol from driver.                 */
  82 #ifdef CONFIG_SLAVE_BALANCING
  83   unsigned short                in_dev_queue;
  84 #endif  
  85   unsigned long                 padding[0];             /* Force long word alignment                    */
  86   unsigned char                 data[0];                /* Data follows                                 */
  87 };
  88 
  89 #define SK_WMEM_MAX     32767
  90 #define SK_RMEM_MAX     32767
  91 
  92 #ifdef CONFIG_SKB_CHECK
  93 #define SK_FREED_SKB    0x0DE2C0DE
  94 #define SK_GOOD_SKB     0xDEC0DED1
  95 #define SK_HEAD_SKB     0x12231298
  96 #endif
  97 
  98 #ifdef __KERNEL__
  99 /*
 100  *      Handling routines are only of interest to the kernel
 101  */
 102 
 103 #include <asm/system.h>
 104 
 105 #if 0
 106 extern void                     print_skb(struct sk_buff *);
 107 #endif
 108 extern void                     kfree_skb(struct sk_buff *skb, int rw);
 109 extern void                     skb_queue_head_init(struct sk_buff_head *list);
 110 extern void                     skb_queue_head(struct sk_buff_head *list,struct sk_buff *buf);
 111 extern void                     skb_queue_tail(struct sk_buff_head *list,struct sk_buff *buf);
 112 extern struct sk_buff *         skb_dequeue(struct sk_buff_head *list);
 113 extern void                     skb_insert(struct sk_buff *old,struct sk_buff *newsk);
 114 extern void                     skb_append(struct sk_buff *old,struct sk_buff *newsk);
 115 extern void                     skb_unlink(struct sk_buff *buf);
 116 extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
 117 extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
 118 extern void                     kfree_skbmem(struct sk_buff *skb, unsigned size);
 119 extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
 120 extern void                     skb_device_lock(struct sk_buff *skb);
 121 extern void                     skb_device_unlock(struct sk_buff *skb);
 122 extern void                     dev_kfree_skb(struct sk_buff *skb, int mode);
 123 extern int                      skb_device_locked(struct sk_buff *skb);
 124 /*
 125  *      Peek an sk_buff. Unlike most other operations you _MUST_
 126  *      be careful with this one. A peek leaves the buffer on the
 127  *      list and someone else may run off with it. For an interrupt
 128  *      type system cli() peek the buffer copy the data and sti();
 129  */
 130 static __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132         struct sk_buff *list = (struct sk_buff *)list_;
 133         return (list->next != list)? list->next : NULL;
 134 }
 135 
 136 #if CONFIG_SKB_CHECK
 137 extern int                      skb_check(struct sk_buff *skb,int,int, char *);
 138 #define IS_SKB(skb)             skb_check((skb), 0, __LINE__,__FILE__)
 139 #define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__,__FILE__)
 140 #else
 141 #define IS_SKB(skb)             
 142 #define IS_SKB_HEAD(skb)        
 143 
 144 extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146         list->prev = (struct sk_buff *)list;
 147         list->next = (struct sk_buff *)list;
 148 }
 149 
 150 /*
 151  *      Insert an sk_buff at the start of a list.
 152  */
 153 
 154 extern __inline__ void skb_queue_head(struct sk_buff_head *list_,struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156         unsigned long flags;
 157         struct sk_buff *list = (struct sk_buff *)list_;
 158 
 159         save_flags(flags);
 160         cli();
 161         newsk->next = list->next;
 162         newsk->prev = list;
 163         newsk->next->prev = newsk;
 164         newsk->prev->next = newsk;
 165         restore_flags(flags);
 166 }
 167 
 168 /*
 169  *      Insert an sk_buff at the end of a list.
 170  */
 171 
 172 extern __inline__ void skb_queue_tail(struct sk_buff_head *list_, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         unsigned long flags;
 175         struct sk_buff *list = (struct sk_buff *)list_;
 176 
 177         save_flags(flags);
 178         cli();
 179 
 180         newsk->next = list;
 181         newsk->prev = list->prev;
 182 
 183         newsk->next->prev = newsk;
 184         newsk->prev->next = newsk;
 185 
 186         restore_flags(flags);
 187 }
 188 
 189 /*
 190  *      Remove an sk_buff from a list. This routine is also interrupt safe
 191  *      so you can grab read and free buffers as another process adds them.
 192  *
 193  *      Note we now do the ful list 
 194  */
 195 
 196 extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list_)
     /* [previous][next][first][last][top][bottom][index][help] */
 197 {
 198         long flags;
 199         struct sk_buff *result;
 200         struct sk_buff *list = (struct sk_buff *)list_;
 201 
 202         save_flags(flags);
 203         cli();
 204 
 205         result = list->next;
 206         if (result == list) 
 207         {
 208                 restore_flags(flags);
 209                 return NULL;
 210         }
 211         else
 212         {
 213                 result->next->prev = list;
 214                 list->next = result->next;
 215 
 216                 result->next = NULL;
 217                 result->prev = NULL;
 218 
 219                 restore_flags(flags);
 220 
 221                 return result;
 222         }
 223 }
 224 
 225 /*
 226  *      Insert a packet before another one in a list.
 227  */
 228 
 229 extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 230 {
 231         unsigned long flags;
 232 
 233         save_flags(flags);
 234         cli();
 235         newsk->next = old;
 236         newsk->prev = old->prev;
 237         old->prev = newsk;
 238         newsk->prev->next = newsk;
 239 
 240         restore_flags(flags);
 241 }
 242 
 243 /*
 244  *      Place a packet after a given packet in a list.
 245  */
 246 
 247 extern __inline__ void skb_append(struct sk_buff *old, struct sk_buff *newsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 248 {
 249         unsigned long flags;
 250 
 251         save_flags(flags);
 252         cli();
 253 
 254         newsk->prev = old;
 255         newsk->next = old->next;
 256         newsk->next->prev = newsk;
 257         old->next = newsk;
 258 
 259         restore_flags(flags);
 260 }
 261 
 262 /*
 263  *      Remove an sk_buff from its list. Works even without knowing the list it
 264  *      is sitting on, which can be handy at times. It also means that THE LIST
 265  *      MUST EXIST when you unlink. Thus a list must have its contents unlinked
 266  *      _FIRST_.
 267  */
 268 
 269 extern __inline__ void skb_unlink(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 270 {
 271         unsigned long flags;
 272 
 273         save_flags(flags);
 274         cli();
 275 
 276         if(skb->prev && skb->next)
 277         {
 278                 skb->next->prev = skb->prev;
 279                 skb->prev->next = skb->next;
 280                 skb->next = NULL;
 281                 skb->prev = NULL;
 282         }
 283         restore_flags(flags);
 284 }
 285 
 286 #endif
 287 
 288 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
 289 extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
 290 extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
 291 extern void                     skb_free_datagram(struct sk_buff *skb);
 292 
 293 #endif  /* __KERNEL__ */
 294 #endif  /* _LINUX_SKBUFF_H */

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