Subversion Repositories shark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Emulates Linux sk buffers using hartik net buffers... */
2
 
3
#include <kernel/kern.h>
4
#include <semaphore.h>
5
 
6
#include "../net/netbuff.h"
7
#include "../net/eth_priv.h"
8
 
9
#include"linux/skbuff.h"
10
 
11
#define LOWLEV_TX_BUFFERS 50
12
#define LOWLEV_RX_BUFFERS 50
13
struct netbuff rxbuff;
14
struct netbuff lowlevel_txbuff;
15
 
16
void skb_init(void)
17
{
18
        netbuff_init(&lowlevel_txbuff, LOWLEV_TX_BUFFERS, ETH_MAX_LEN);
19
        netbuff_init(&rxbuff, LOWLEV_RX_BUFFERS, ETH_MAX_LEN);
20
}
21
 
22
struct sk_buff *dev_alloc_skb(unsigned int len)
23
{
24
        struct sk_buff *skb;
25
 
26
        kern_cli();
27
        skb = kern_alloc(sizeof(struct sk_buff));
28
        kern_sti();
29
 
30
        skb->data = netbuff_get(&rxbuff, NON_BLOCK);
31
        if (skb->data == NULL) {
32
                        return NULL;
33
        }
34
        skb->head = skb->data;
35
        skb->tail = skb->data;
36
        skb->len = 0;
203 pj 37
        skb->truesize = len;
2 pj 38
 
39
        return skb;
40
}
41
 
42
void skb_reserve(struct sk_buff *skb, int len)
43
{
203 pj 44
        /* changed by PJ ... before it did nothing... */
45
        skb->data+=len;
46
        skb->tail+=len;
2 pj 47
}
48
 
49
unsigned char *skb_put(struct sk_buff *skb, int len)
50
{
51
        unsigned char *tmp=skb->tail;
52
 
53
        skb->tail+=len;
54
        skb->len+=len;
55
 
56
        return tmp;
57
}
58
 
59
void skb_queue_head_init(struct sk_buff_head *list)
60
{    
61
        list->prev = (struct sk_buff *)list;
62
        list->next = (struct sk_buff *)list;
63
        list->qlen = 0;
64
}
203 pj 65
 
66
struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, int newheadroom)
67
{
68
        struct sk_buff *n;
69
        unsigned long offset;
70
        int headroom = skb_headroom(skb);
71
 
72
        /*
73
         *      Allocate the copy buffer
74
         */
75
 
76
        n=alloc_skb(skb->truesize+newheadroom-headroom, GFP_ATOMIC);
77
        if(n==NULL)
78
                return NULL;
79
 
80
        skb_reserve(n,newheadroom);
81
 
82
        /*
83
         *      Shift between the two data areas in bytes
84
         */
85
 
86
        offset=n->data-skb->data;
87
 
88
        /* Set the tail pointer and length */
89
        skb_put(n,skb->len);
90
        /* Copy the bytes */
91
        memcpy(n->data,skb->data,skb->len);
92
        n->list=NULL;
93
        //        n->sk=NULL;
94
        //        n->priority=skb->priority;
95
        n->protocol=skb->protocol;
96
        n->dev=skb->dev;
97
        //        n->dst=dst_clone(skb->dst);
98
        //        n->h.raw=skb->h.raw+offset;
99
        //        n->nh.raw=skb->nh.raw+offset;
100
        //        n->mac.raw=skb->mac.raw+offset;
101
        memcpy(n->cb, skb->cb, sizeof(skb->cb));
102
        n->used=skb->used;
103
        //        n->is_clone=0;
104
        //        atomic_set(&n->users, 1);
105
        //        n->pkt_type=skb->pkt_type;
106
        //        n->stamp=skb->stamp;
107
        //        n->destructor = NULL;
108
        //        n->security=skb->security;
109
#ifdef CONFIG_IP_FIREWALL
110
        n->fwmark = skb->fwmark;
111
#endif
112
 
113
        return n;
114
}