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

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