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

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