Version:  2.0.40 2.2.26 2.4.37 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10

Linux/include/linux/skbuff.h

  1 /*
  2  *      Definitions for the 'struct sk_buff' memory handlers.
  3  *
  4  *      Authors:
  5  *              Alan Cox, <alan@lxorguk.ukuu.org.uk>
  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 
 17 #include <linux/config.h>
 18 #include <linux/time.h>
 19 
 20 #include <asm/atomic.h>
 21 #include <asm/types.h>
 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  *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 acke ? */
 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                         pkt_bridged,            /* Tracker for bridging */
 96                         ip_summed;              /* Driver fed us an IP checksum */
 97 #define PACKET_HOST             0               /* To us */
 98 #define PACKET_BROADCAST        1               /* To all */
 99 #define PACKET_MULTICAST        2               /* To group */
100 #define PACKET_OTHERHOST        3               /* To someone else */
101         unsigned short  users;                  /* User count - see datagram.c,tcp.c */
102         unsigned short  protocol;               /* Packet protocol from driver. */
103         unsigned int    truesize;               /* Buffer size */
104 
105         atomic_t        count;                  /* reference count */
106         struct sk_buff  *data_skb;              /* Link to the actual data skb */
107         unsigned char   *head;                  /* Head of buffer */
108         unsigned char   *data;                  /* Data head pointer */
109         unsigned char   *tail;                  /* Tail pointer */
110         unsigned char   *end;                   /* End pointer */
111         void            (*destructor)(struct sk_buff *);        /* Destruct function */
112         __u16           redirport;              /* Redirect port */
113 
114         /*
115          *      Keep this at the end then we wont break stuff.
116          */
117 #if defined(CONFIG_SHAPER) || defined(CONFIG_SHAPER_MODULE)
118         __u32           shapelatency;           /* Latency on frame */
119         __u32           shapeclock;             /* Time it should go out */
120         __u32           shapelen;               /* Frame length in clocks */
121         __u32           shapestamp;             /* Stamp for shaper    */
122         __u16           shapepend;              /* Pending */
123 #endif
124 };
125 
126 #ifdef CONFIG_SKB_LARGE
127 #define SK_WMEM_MAX     65535
128 #define SK_RMEM_MAX     65535
129 #else
130 #define SK_WMEM_MAX     32767
131 #define SK_RMEM_MAX     32767
132 #endif
133 
134 #if CONFIG_SKB_CHECK
135 #define SK_FREED_SKB    0x0DE2C0DE
136 #define SK_GOOD_SKB     0xDEC0DED1
137 #define SK_HEAD_SKB     0x12231298
138 #endif
139 
140 #ifdef __KERNEL__
141 /*
142  *      Handling routines are only of interest to the kernel
143  */
144 #include <linux/malloc.h>
145 
146 #include <asm/system.h>
147 
148 #if 0
149 extern void                     print_skb(struct sk_buff *);
150 #endif
151 extern void                     kfree_skb(struct sk_buff *skb, int rw);
152 extern void                     skb_queue_head_init(struct sk_buff_head *list);
153 extern void                     skb_queue_head(struct sk_buff_head *list, struct sk_buff *buf);
154 extern void                     skb_queue_tail(struct sk_buff_head *list, struct sk_buff *buf);
155 extern struct sk_buff *         skb_dequeue(struct sk_buff_head *list);
156 extern void                     skb_insert(struct sk_buff *old, struct sk_buff *newsk);
157 extern void                     skb_append(struct sk_buff *old, struct sk_buff *newsk);
158 extern void                     skb_unlink(struct sk_buff *buf);
159 extern __u32                    skb_queue_len(struct sk_buff_head *list);
160 extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
161 extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
162 extern struct sk_buff *         dev_alloc_skb(unsigned int size);
163 extern void                     kfree_skbmem(struct sk_buff *skb);
164 extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
165 extern struct sk_buff *         skb_copy(struct sk_buff *skb, int priority);
166 extern struct sk_buff *         skb_pad(struct sk_buff *skb, int pad);
167 extern void                     skb_device_lock(struct sk_buff *skb);
168 extern void                     skb_device_unlock(struct sk_buff *skb);
169 extern void                     dev_kfree_skb(struct sk_buff *skb, int mode);
170 extern int                      skb_device_locked(struct sk_buff *skb);
171 extern unsigned char *          skb_put(struct sk_buff *skb, int len);
172 extern unsigned char *          skb_push(struct sk_buff *skb, int len);
173 extern unsigned char *          skb_pull(struct sk_buff *skb, int len);
174 extern int                      skb_headroom(struct sk_buff *skb);
175 extern int                      skb_tailroom(struct sk_buff *skb);
176 extern void                     skb_reserve(struct sk_buff *skb, int len);
177 extern void                     skb_trim(struct sk_buff *skb, int len);
178 
179 extern __inline__ int skb_queue_empty(struct sk_buff_head *list)
180 {
181         return (list->next == (struct sk_buff *) list);
182 }
183 
184 /*
185  *      Peek an sk_buff. Unlike most other operations you _MUST_
186  *      be careful with this one. A peek leaves the buffer on the
187  *      list and someone else may run off with it. For an interrupt
188  *      type system cli() peek the buffer copy the data and sti();
189  */
190 extern __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
191 {
192         struct sk_buff *list = ((struct sk_buff *)list_)->next;
193         if (list == (struct sk_buff *)list_)
194                 list = NULL;
195         return list;
196 }
197 
198 /*
199  *      Return the length of an sk_buff queue
200  */
201 
202 extern __inline__ __u32 skb_queue_len(struct sk_buff_head *list_)
203 {
204         return(list_->qlen);
205 }
206 
207 #if CONFIG_SKB_CHECK
208 extern int skb_check(struct sk_buff *skb, int, int, char *);
209 #define IS_SKB(skb)             skb_check((skb), 0, __LINE__, __FILE__)
210 #define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__, __FILE__)
211 #define IS_SKB_LINKED(skb)      skb_check((skb), 2, __LINE__, __FILE__)
212 #define IS_SKB_UNLINKED(skb)    skb_check((skb), 3, __LINE__, __FILE__)
213 /* Note: IS_SKB_LINKED will accept skb_heads in addition to linked-in
214  * data skbs */
215 
216 extern void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk);
217 extern void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk);
218 extern struct sk_buff *__skb_dequeue(struct sk_buff_head *list);
219 extern void __skb_insert(struct sk_buff *newsk,
220         struct sk_buff * prev, struct sk_buff *next,
221         struct sk_buff_head * list);
222 extern void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list);
223 
224 #else
225 #define IS_SKB(skb)
226 #define IS_SKB_HEAD(skb)
227 #define IS_SKB_LINKED(skb)
228 #define IS_SKB_UNLINKED(skb)
229 
230 extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
231 {
232         list->prev = (struct sk_buff *)list;
233         list->next = (struct sk_buff *)list;
234         list->qlen = 0;
235 }
236 
237 /*
238  *      Insert an sk_buff at the start of a list.
239  *
240  *      The "__skb_xxxx()" functions are the non-atomic ones that
241  *      can only be called with interrupts disabled.
242  */
243 
244 extern __inline__ void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
245 {
246         struct sk_buff *prev, *next;
247 
248         newsk->list = list;
249         list->qlen++;
250         prev = (struct sk_buff *)list;
251         next = prev->next;
252         newsk->next = next;
253         newsk->prev = prev;
254         next->prev = newsk;
255         prev->next = newsk;
256 }
257 
258 extern __inline__ void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
259 {
260         unsigned long flags;
261 
262         save_flags(flags);
263         cli();
264         __skb_queue_head(list, newsk);
265         restore_flags(flags);
266 }
267 
268 /*
269  *      Insert an sk_buff at the end of a list.
270  */
271 
272 extern __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
273 {
274         struct sk_buff *prev, *next;
275 
276         newsk->list = list;
277         list->qlen++;
278         next = (struct sk_buff *)list;
279         prev = next->prev;
280         newsk->next = next;
281         newsk->prev = prev;
282         next->prev = newsk;
283         prev->next = newsk;
284 }
285 
286 extern __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
287 {
288         unsigned long flags;
289 
290         save_flags(flags);
291         cli();
292         __skb_queue_tail(list, newsk);
293         restore_flags(flags);
294 }
295 
296 /*
297  *      Remove an sk_buff from a list.
298  */
299 
300 extern __inline__ struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
301 {
302         struct sk_buff *next, *prev, *result;
303 
304         prev = (struct sk_buff *) list;
305         next = prev->next;
306         result = NULL;
307         if (next != prev) {
308                 result = next;
309                 next = next->next;
310                 list->qlen--;
311                 next->prev = prev;
312                 prev->next = next;
313                 result->next = NULL;
314                 result->prev = NULL;
315                 result->list = NULL;
316         }
317         return result;
318 }
319 
320 extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list)
321 {
322         long flags;
323         struct sk_buff *result;
324 
325         save_flags(flags);
326         cli();
327         result = __skb_dequeue(list);
328         restore_flags(flags);
329         return result;
330 }
331 
332 /*
333  *      Insert a packet on a list.
334  */
335 
336 extern __inline__ void __skb_insert(struct sk_buff *newsk,
337         struct sk_buff * prev, struct sk_buff *next,
338         struct sk_buff_head * list)
339 {
340         newsk->next = next;
341         newsk->prev = prev;
342         next->prev = newsk;
343         prev->next = newsk;
344         newsk->list = list;
345         list->qlen++;
346 }
347 
348 /*
349  *      Place a packet before a given packet in a list
350  */
351 extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
352 {
353         unsigned long flags;
354 
355         save_flags(flags);
356         cli();
357         __skb_insert(newsk, old->prev, old, old->list);
358         restore_flags(flags);
359 }
360 
361 /*
362  *      Place a packet after a given packet in a list.
363  */
364 
365 extern __inline__ void skb_append(struct sk_buff *old, struct sk_buff *newsk)
366 {
367         unsigned long flags;
368 
369         save_flags(flags);
370         cli();
371         __skb_insert(newsk, old, old->next, old->list);
372         restore_flags(flags);
373 }
374 
375 /*
376  * remove sk_buff from list. _Must_ be called atomically, and with
377  * the list known..
378  */
379 extern __inline__ void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
380 {
381         struct sk_buff * next, * prev;
382 
383         list->qlen--;
384         next = skb->next;
385         prev = skb->prev;
386         skb->next = NULL;
387         skb->prev = NULL;
388         skb->list = NULL;
389         next->prev = prev;
390         prev->next = next;
391 }
392 
393 /*
394  *      Remove an sk_buff from its list. Works even without knowing the list it
395  *      is sitting on, which can be handy at times. It also means that THE LIST
396  *      MUST EXIST when you unlink. Thus a list must have its contents unlinked
397  *      _FIRST_.
398  */
399 
400 extern __inline__ void skb_unlink(struct sk_buff *skb)
401 {
402         unsigned long flags;
403 
404         save_flags(flags);
405         cli();
406         if(skb->list)
407                 __skb_unlink(skb, skb->list);
408         restore_flags(flags);
409 }
410 
411 /*
412  *      Add data to an sk_buff
413  */
414 
415 extern __inline__ unsigned char *skb_put(struct sk_buff *skb, int len)
416 {
417         unsigned char *tmp=skb->tail;
418         skb->tail+=len;
419         skb->len+=len;
420         if(skb->tail>skb->end)
421         {
422                 __label__ here;
423                 panic("skput:over: %p:%d", &&here, len);
424 here:;
425         }
426         return tmp;
427 }
428 
429 extern __inline__ unsigned char *skb_push(struct sk_buff *skb, int len)
430 {
431         skb->data-=len;
432         skb->len+=len;
433         if(skb->data<skb->head)
434         {
435                 __label__ here;
436                 panic("skpush:under: %p:%d", &&here, len);
437 here:;
438         }
439         return skb->data;
440 }
441 
442 extern __inline__ unsigned char * skb_pull(struct sk_buff *skb, int len)
443 {
444         if(len > skb->len)
445                 return NULL;
446         skb->data+=len;
447         skb->len-=len;
448         return skb->data;
449 }
450 
451 extern __inline__ int skb_headroom(struct sk_buff *skb)
452 {
453         return skb->data-skb->head;
454 }
455 
456 extern __inline__ int skb_tailroom(struct sk_buff *skb)
457 {
458         return skb->end-skb->tail;
459 }
460 
461 extern __inline__ void skb_reserve(struct sk_buff *skb, int len)
462 {
463         skb->data+=len;
464         skb->tail+=len;
465 }
466 
467 extern __inline__ void skb_trim(struct sk_buff *skb, int len)
468 {
469         if(skb->len>len)
470         {
471                 skb->len=len;
472                 skb->tail=skb->data+len;
473         }
474 }
475 
476 #endif
477 
478 static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len)
479 {
480         unsigned int size = skb->len;
481         if (size >= len)
482                 return skb;
483         return skb_pad(skb, len-size);
484 }
485 
486 extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
487 extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
488 extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
489 extern void                     skb_copy_datagram_iovec(struct sk_buff *from, int offset, struct iovec *to,int size);
490 extern void                     skb_free_datagram(struct sock * sk, struct sk_buff *skb);
491 
492 #endif  /* __KERNEL__ */
493 #endif  /* _LINUX_SKBUFF_H */
494 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us