Rev 629 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
629 | giacomo | 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; |
||
37 | skb->truesize = len; |
||
38 | |||
39 | return skb; |
||
40 | } |
||
41 | |||
42 | void skb_reserve(struct sk_buff *skb, int len) |
||
43 | { |
||
44 | /* changed by PJ ... before it did nothing... */ |
||
45 | skb->data+=len; |
||
46 | skb->tail+=len; |
||
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 | } |
||
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 | /* Allocate the copy buffer */ |
||
73 | |||
74 | n = alloc_skb(skb->truesize + newheadroom-headroom, GFP_ATOMIC); |
||
75 | if (n == NULL) |
||
76 | return NULL; |
||
77 | |||
78 | skb_reserve(n, newheadroom); |
||
79 | |||
80 | /* |
||
81 | * Shift between the two data areas in bytes |
||
82 | */ |
||
83 | |||
84 | offset = n->data - skb->data; |
||
85 | |||
86 | /* Set the tail pointer and length */ |
||
87 | skb_put(n, skb->len); |
||
88 | |||
89 | /* Copy the bytes */ |
||
90 | memcpy(n->data, skb->data, skb->len); |
||
91 | n->list = NULL; |
||
92 | // n->sk = NULL; |
||
93 | // n->priority = skb->priority; |
||
94 | n->protocol = skb->protocol; |
||
95 | n->dev = skb->dev; |
||
96 | // n->dst = dst_clone(skb->dst); |
||
97 | // n->h.raw = skb->h.raw+offset; |
||
98 | // n->nh.raw = skb->nh.raw+offset; |
||
99 | // n->mac.raw = skb->mac.raw+offset; |
||
100 | memcpy(n->cb, skb->cb, sizeof(skb->cb)); |
||
101 | n->used = skb->used; |
||
102 | // n->is_clone = 0; |
||
103 | // atomic_set(&n->users, 1); |
||
104 | // n->pkt_type = skb->pkt_type; |
||
105 | // n->stamp = skb->stamp; |
||
106 | // n->destructor = NULL; |
||
107 | // n->security = skb->security; |
||
108 | #ifdef CONFIG_IP_FIREWALL |
||
109 | n->fwmark = skb->fwmark; |
||
110 | #endif |
||
111 | |||
112 | return n; |
||
113 | } |