OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [linux/] [skbuff.h] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
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
 
17
#include <linux/config.h>
18
#include <linux/time.h>
19
 
20
#include <asm/atomic.h>
21
#include <asm/types.h>
22
 
23
#define CONFIG_SKB_CHECK 0
24
 
25
#define HAVE_ALLOC_SKB          /* For the drivers to know */
26
#define HAVE_ALIGNABLE_SKB      /* Ditto 8)                */
27
 
28
 
29
#define FREE_READ       1
30
#define FREE_WRITE      0
31
 
32
#define CHECKSUM_NONE 0
33
#define CHECKSUM_HW 1
34
#define CHECKSUM_UNNECESSARY 2
35
 
36
struct sk_buff_head
37
{
38
        struct sk_buff  * next;
39
        struct sk_buff  * prev;
40
        __u32           qlen;           /* Must be same length as a pointer
41
                                           for using debugging */
42
#if CONFIG_SKB_CHECK
43
        int             magic_debug_cookie;
44
#endif
45
};
46
 
47
 
48
struct sk_buff
49
{
50
        struct sk_buff  * next;                 /* Next buffer in list                          */
51
        struct sk_buff  * prev;                 /* Previous buffer in list                      */
52
        struct sk_buff_head * list;             /* List we are on                               */
53
#if CONFIG_SKB_CHECK
54
        int             magic_debug_cookie;
55
#endif
56
        struct sk_buff  *link3;                 /* Link for IP protocol level buffer chains     */
57
        struct sock     *sk;                    /* Socket we are owned by                       */
58
        unsigned long   when;                   /* used to compute rtt's                        */
59
        struct timeval  stamp;                  /* Time we arrived                              */
60
        struct device   *dev;                   /* Device we arrived on/are leaving by          */
61
        union
62
        {
63
                struct tcphdr   *th;
64
                struct ethhdr   *eth;
65
                struct iphdr    *iph;
66
                struct udphdr   *uh;
67
                unsigned char   *raw;
68
                /* for passing file handles in a unix domain socket */
69
                void *filp;
70
        } h;
71
 
72
        union
73
        {
74
                /* As yet incomplete physical layer views */
75
                unsigned char   *raw;
76
                struct ethhdr   *ethernet;
77
        } mac;
78
 
79
        struct iphdr    *ip_hdr;                /* For IPPROTO_RAW                              */
80
        unsigned long   len;                    /* Length of actual data                        */
81
        unsigned long   csum;                   /* Checksum                                     */
82
        __u32           saddr;                  /* IP source address                            */
83
        __u32           daddr;                  /* IP target address                            */
84
        __u32           raddr;                  /* IP next hop address                          */
85
        __u32           seq;                    /* TCP sequence number                          */
86
        __u32           end_seq;                /* seq [+ fin] [+ syn] + datalen                */
87
        __u32           ack_seq;                /* TCP ack sequence number                      */
88
        unsigned char   proto_priv[16];         /* Protocol private data                        */
89
        volatile char   acked,                  /* Are we acked ?                               */
90
                        used,                   /* Are we in use ?                              */
91
                        free,                   /* How to free this buffer                      */
92
                        arp;                    /* Has IP/ARP resolution finished               */
93
        unsigned char   tries,                  /* Times tried                                  */
94
                        lock,                   /* Are we locked ?                              */
95
                        localroute,             /* Local routing asserted for this frame        */
96
                        pkt_type,               /* Packet class                                 */
97
                        pkt_bridged,            /* Tracker for bridging                         */
98
                        ip_summed;              /* Driver fed us an IP checksum                 */
99
#define PACKET_HOST             0                /* To us                                        */
100
#define PACKET_BROADCAST        1               /* To all                                       */
101
#define PACKET_MULTICAST        2               /* To group                                     */
102
#define PACKET_OTHERHOST        3               /* To someone else                              */
103
        unsigned short  users;                  /* User count - see datagram.c,tcp.c            */
104
        unsigned short  protocol;               /* Packet protocol from driver.                 */
105
        unsigned int    truesize;               /* Buffer size                                  */
106
 
107
        atomic_t        count;                  /* reference count                              */
108
        struct sk_buff  *data_skb;              /* Link to the actual data skb                  */
109
        unsigned char   *head;                  /* Head of buffer                               */
110
        unsigned char   *data;                  /* Data head pointer                            */
111
        unsigned char   *tail;                  /* Tail pointer                                 */
112
        unsigned char   *end;                   /* End pointer                                  */
113
        void            (*destructor)(struct sk_buff *);        /* Destruct function            */
114
        __u16           redirport;              /* Redirect port                                */
115
 
116
        /*
117
         *      Keep this at the end then we wont break stuff.
118
         */
119
#if defined(CONFIG_SHAPER) || defined(CONFIG_SHAPER_MODULE)
120
        __u32           shapelatency;           /* Latency on frame */
121
        __u32           shapeclock;             /* Time it should go out */
122
        __u32           shapelen;               /* Frame length in clocks */
123
        __u32           shapestamp;             /* Stamp for shaper    */
124
        __u16           shapepend;              /* Pending */
125
#endif
126
};
127
 
128
#ifdef CONFIG_SKB_LARGE
129
#define SK_WMEM_MAX     65535
130
#define SK_RMEM_MAX     65535
131
#else
132
#define SK_WMEM_MAX     32767
133
#define SK_RMEM_MAX     32767
134
#endif
135
 
136
#if CONFIG_SKB_CHECK
137
#define SK_FREED_SKB    0x0DE2C0DE
138
#define SK_GOOD_SKB     0xDEC0DED1
139
#define SK_HEAD_SKB     0x12231298
140
#endif
141
 
142
#ifdef __KERNEL__
143
/*
144
 *      Handling routines are only of interest to the kernel
145
 */
146
#include <linux/malloc.h>
147
 
148
#include <asm/system.h>
149
 
150
#if 0
151
extern void                     print_skb(struct sk_buff *);
152
#endif
153
extern void                     kfree_skb(struct sk_buff *skb, int rw);
154
extern void                     skb_queue_head_init(struct sk_buff_head *list);
155
extern void                     skb_queue_head(struct sk_buff_head *list,struct sk_buff *buf);
156
extern void                     skb_queue_tail(struct sk_buff_head *list,struct sk_buff *buf);
157
extern struct sk_buff *         skb_dequeue(struct sk_buff_head *list);
158
extern void                     skb_insert(struct sk_buff *old,struct sk_buff *newsk);
159
extern void                     skb_append(struct sk_buff *old,struct sk_buff *newsk);
160
extern void                     skb_unlink(struct sk_buff *buf);
161
extern __u32                    skb_queue_len(struct sk_buff_head *list);
162
extern struct sk_buff *         skb_peek_copy(struct sk_buff_head *list);
163
extern struct sk_buff *         alloc_skb(unsigned int size, int priority);
164
extern struct sk_buff *         dev_alloc_skb(unsigned int size);
165
extern void                     kfree_skbmem(struct sk_buff *skb);
166
extern struct sk_buff *         skb_clone(struct sk_buff *skb, int priority);
167
extern struct sk_buff *         skb_copy(struct sk_buff *skb, int priority);
168
extern void                     skb_device_lock(struct sk_buff *skb);
169
extern void                     skb_device_unlock(struct sk_buff *skb);
170
extern void                     dev_kfree_skb(struct sk_buff *skb, int mode);
171
extern int                      skb_device_locked(struct sk_buff *skb);
172
extern unsigned char *          skb_put(struct sk_buff *skb, int len);
173
extern unsigned char *          skb_push(struct sk_buff *skb, int len);
174
extern unsigned char *          skb_pull(struct sk_buff *skb, int len);
175
extern int                      skb_headroom(struct sk_buff *skb);
176
extern int                      skb_tailroom(struct sk_buff *skb);
177
extern void                     skb_reserve(struct sk_buff *skb, int len);
178
extern void                     skb_trim(struct sk_buff *skb, int len);
179
 
180
extern __inline__ int skb_queue_empty(struct sk_buff_head *list)
181
{
182
        return (list->next == (struct sk_buff *) list);
183
}
184
 
185
/*
186
 *      Peek an sk_buff. Unlike most other operations you _MUST_
187
 *      be careful with this one. A peek leaves the buffer on the
188
 *      list and someone else may run off with it. For an interrupt
189
 *      type system cli() peek the buffer copy the data and sti();
190
 */
191
extern __inline__ struct sk_buff *skb_peek(struct sk_buff_head *list_)
192
{
193
        struct sk_buff *list = ((struct sk_buff *)list_)->next;
194
        if (list == (struct sk_buff *)list_)
195
                list = NULL;
196
        return list;
197
}
198
 
199
/*
200
 *      Return the length of an sk_buff queue
201
 */
202
 
203
extern __inline__ __u32 skb_queue_len(struct sk_buff_head *list_)
204
{
205
        return(list_->qlen);
206
}
207
 
208
#if CONFIG_SKB_CHECK
209
extern int                      skb_check(struct sk_buff *skb,int,int, char *);
210
#define IS_SKB(skb)             skb_check((skb), 0, __LINE__,__FILE__)
211
#define IS_SKB_HEAD(skb)        skb_check((skb), 1, __LINE__,__FILE__)
212
#else
213
#define IS_SKB(skb)             
214
#define IS_SKB_HEAD(skb)        
215
 
216
extern __inline__ void skb_queue_head_init(struct sk_buff_head *list)
217
{
218
        list->prev = (struct sk_buff *)list;
219
        list->next = (struct sk_buff *)list;
220
        list->qlen = 0;
221
}
222
 
223
/*
224
 *      Insert an sk_buff at the start of a list.
225
 *
226
 *      The "__skb_xxxx()" functions are the non-atomic ones that
227
 *      can only be called with interrupts disabled.
228
 */
229
 
230
extern __inline__ void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
231
{
232
        struct sk_buff *prev, *next;
233
 
234
        newsk->list = list;
235
        list->qlen++;
236
        prev = (struct sk_buff *)list;
237
        next = prev->next;
238
        newsk->next = next;
239
        newsk->prev = prev;
240
        next->prev = newsk;
241
        prev->next = newsk;
242
}
243
 
244
extern __inline__ void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
245
{
246
        unsigned long flags;
247
 
248
        save_flags(flags);
249
        cli();
250
        __skb_queue_head(list, newsk);
251
        restore_flags(flags);
252
}
253
 
254
/*
255
 *      Insert an sk_buff at the end of a list.
256
 */
257
 
258
extern __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
259
{
260
        struct sk_buff *prev, *next;
261
 
262
        newsk->list = list;
263
        list->qlen++;
264
        next = (struct sk_buff *)list;
265
        prev = next->prev;
266
        newsk->next = next;
267
        newsk->prev = prev;
268
        next->prev = newsk;
269
        prev->next = newsk;
270
}
271
 
272
extern __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
273
{
274
        unsigned long flags;
275
 
276
        save_flags(flags);
277
        cli();
278
        __skb_queue_tail(list, newsk);
279
        restore_flags(flags);
280
}
281
 
282
/*
283
 *      Remove an sk_buff from a list.
284
 */
285
 
286
extern __inline__ struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
287
{
288
        struct sk_buff *next, *prev, *result;
289
 
290
        prev = (struct sk_buff *) list;
291
        next = prev->next;
292
        result = NULL;
293
        if (next != prev) {
294
                result = next;
295
                next = next->next;
296
                list->qlen--;
297
                next->prev = prev;
298
                prev->next = next;
299
                result->next = NULL;
300
                result->prev = NULL;
301
                result->list = NULL;
302
        }
303
        return result;
304
}
305
 
306
extern __inline__ struct sk_buff *skb_dequeue(struct sk_buff_head *list)
307
{
308
        long flags;
309
        struct sk_buff *result;
310
 
311
        save_flags(flags);
312
        cli();
313
        result = __skb_dequeue(list);
314
        restore_flags(flags);
315
        return result;
316
}
317
 
318
/*
319
 *      Insert a packet on a list.
320
 */
321
 
322
extern __inline__ void __skb_insert(struct sk_buff *newsk,
323
        struct sk_buff * prev, struct sk_buff *next,
324
        struct sk_buff_head * list)
325
{
326
        newsk->next = next;
327
        newsk->prev = prev;
328
        next->prev = newsk;
329
        prev->next = newsk;
330
        newsk->list = list;
331
        list->qlen++;
332
}
333
 
334
/*
335
 *      Place a packet before a given packet in a list
336
 */
337
extern __inline__ void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
338
{
339
        unsigned long flags;
340
 
341
        save_flags(flags);
342
        cli();
343
        __skb_insert(newsk, old->prev, old, old->list);
344
        restore_flags(flags);
345
}
346
 
347
/*
348
 *      Place a packet after a given packet in a list.
349
 */
350
 
351
extern __inline__ void skb_append(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, old->next, old->list);
358
        restore_flags(flags);
359
}
360
 
361
/*
362
 * remove sk_buff from list. _Must_ be called atomically, and with
363
 * the list known..
364
 */
365
extern __inline__ void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
366
{
367
        struct sk_buff * next, * prev;
368
 
369
        list->qlen--;
370
        next = skb->next;
371
        prev = skb->prev;
372
        skb->next = NULL;
373
        skb->prev = NULL;
374
        skb->list = NULL;
375
        next->prev = prev;
376
        prev->next = next;
377
}
378
 
379
/*
380
 *      Remove an sk_buff from its list. Works even without knowing the list it
381
 *      is sitting on, which can be handy at times. It also means that THE LIST
382
 *      MUST EXIST when you unlink. Thus a list must have its contents unlinked
383
 *      _FIRST_.
384
 */
385
 
386
extern __inline__ void skb_unlink(struct sk_buff *skb)
387
{
388
        unsigned long flags;
389
 
390
        save_flags(flags);
391
        cli();
392
        if(skb->list)
393
                __skb_unlink(skb, skb->list);
394
        restore_flags(flags);
395
}
396
 
397
/*
398
 *      Add data to an sk_buff
399
 */
400
 
401
extern __inline__ unsigned char *skb_put(struct sk_buff *skb, int len)
402
{
403
        unsigned char *tmp=skb->tail;
404
        skb->tail+=len;
405
        skb->len+=len;
406
        if(skb->tail>skb->end)
407
        {
408
                __label__ here;
409
                panic("skput:over: %p:%d", &&here,len);
410
here:
411
        }
412
        return tmp;
413
}
414
 
415
extern __inline__ unsigned char *skb_push(struct sk_buff *skb, int len)
416
{
417
        skb->data-=len;
418
        skb->len+=len;
419
        if(skb->data<skb->head)
420
        {
421
                __label__ here;
422
                panic("skpush:under: %p:%d", &&here,len);
423
here:
424
        }
425
        return skb->data;
426
}
427
 
428
extern __inline__ unsigned char * skb_pull(struct sk_buff *skb, int len)
429
{
430
        if(len > skb->len)
431
                return NULL;
432
        skb->data+=len;
433
        skb->len-=len;
434
        return skb->data;
435
}
436
 
437
extern __inline__ int skb_headroom(struct sk_buff *skb)
438
{
439
        return skb->data-skb->head;
440
}
441
 
442
extern __inline__ int skb_tailroom(struct sk_buff *skb)
443
{
444
        return skb->end-skb->tail;
445
}
446
 
447
extern __inline__ void skb_reserve(struct sk_buff *skb, int len)
448
{
449
        skb->data+=len;
450
        skb->tail+=len;
451
}
452
 
453
extern __inline__ void skb_trim(struct sk_buff *skb, int len)
454
{
455
        if(skb->len>len)
456
        {
457
                skb->len=len;
458
                skb->tail=skb->data+len;
459
        }
460
}
461
 
462
#endif
463
 
464
extern struct sk_buff *         skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
465
extern int                      datagram_select(struct sock *sk, int sel_type, select_table *wait);
466
extern void                     skb_copy_datagram(struct sk_buff *from, int offset, char *to,int size);
467
extern void                     skb_copy_datagram_iovec(struct sk_buff *from, int offset, struct iovec *to,int size);
468
extern void                     skb_free_datagram(struct sock * sk, struct sk_buff *skb);
469
 
470
#endif  /* __KERNEL__ */
471
#endif  /* _LINUX_SKBUFF_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.