32 |
#include "iptunnel/tunnel.h" |
#include "iptunnel/tunnel.h" |
33 |
#include "iptunnel/vjcompress.h" |
#include "iptunnel/vjcompress.h" |
34 |
|
|
35 |
|
struct |
36 |
|
{ |
37 |
|
size_t len; |
38 |
|
size_t filled; |
39 |
|
char *data; |
40 |
|
} |
41 |
|
extra_ip; |
42 |
|
|
43 |
|
int need_extra = 0; |
44 |
|
|
45 |
void |
void |
46 |
get_ip_aol (token, data, data_size, out) |
get_ip_aol (token, data, data_size) |
47 |
token_t token; |
token_t token; |
48 |
char *data; |
char *data; |
49 |
size_t data_size; |
size_t data_size; |
|
buffer_t *out; |
|
50 |
{ |
{ |
51 |
struct short_ip *small = (struct short_ip *) data; |
struct short_ip *small = (struct short_ip *) data; |
52 |
struct long_ip *big = (struct long_ip *) data; |
struct long_ip *big = (struct long_ip *) data; |
53 |
char *ip_data; |
char *ip_data; |
54 |
|
|
55 |
|
if(need_extra) |
56 |
|
{ |
57 |
|
log(LOG_ERR, "IP tunnel - No extra packet received, cancelling the packet"); |
58 |
|
need_extra = 0; |
59 |
|
free(extra_ip.data); |
60 |
|
fdo_unregister ( TOKEN ("yd") ); |
61 |
|
} |
62 |
|
|
63 |
ipnum = small->ipnum; |
ipnum = small->ipnum; |
64 |
if (small->long_bit) |
if (small->long_bit) |
65 |
/* This packet is a long ip (>=128 bytes) */ |
/* This packet is a long ip (>=128 bytes) */ |
69 |
big->len=ntohs(big->len) & IP_LEN_MASK; |
big->len=ntohs(big->len) & IP_LEN_MASK; |
70 |
if (data_size - sizeof(*big) != big->len) |
if (data_size - sizeof(*big) != big->len) |
71 |
{ |
{ |
72 |
|
/* |
73 |
|
* The packet is incomplete, we should receive yd tokens to |
74 |
|
* complete him |
75 |
|
*/ |
76 |
log (LOG_INFO, "IP tunnel - big packet need extra packet(s)\n"); |
log (LOG_INFO, "IP tunnel - big packet need extra packet(s)\n"); |
77 |
|
need_extra = 1; |
78 |
|
extra_ip.len = big->len; |
79 |
|
extra_ip.data = malloc( big->len ); |
80 |
|
memcpy(extra_ip.data, ip_data, data_size - sizeof(*big)); |
81 |
|
extra_ip.filled = data_size - sizeof(*big); |
82 |
|
fdo_register ( TOKEN ("yd"), get_ip_extra); |
83 |
} |
} |
84 |
else |
else |
85 |
get_uncompressed_ip (ip_data, big->len); |
get_uncompressed_ip (ip_data, big->len); |
96 |
} |
} |
97 |
} |
} |
98 |
|
|
99 |
|
void |
100 |
|
get_ip_extra (token, data, data_size) |
101 |
|
token_t token; |
102 |
|
char *data; |
103 |
|
size_t data_size; |
104 |
|
{ |
105 |
|
if(data_size + extra_ip.filled > extra_ip.len) |
106 |
|
{ |
107 |
|
log(LOG_ERR, "IP tunnel - Packet overflow detected\n"); |
108 |
|
/* drop overflow data*/ |
109 |
|
data_size = extra_ip.len - extra_ip.filled; |
110 |
|
} |
111 |
|
memcpy(extra_ip.data + extra_ip.filled, data, data_size); |
112 |
|
extra_ip.filled += data_size; |
113 |
|
if( extra_ip.filled == extra_ip.len) |
114 |
|
{ |
115 |
|
get_uncompressed_ip (extra_ip.data, extra_ip.len); |
116 |
|
free(extra_ip.data); |
117 |
|
need_extra = 0; |
118 |
|
fdo_unregister ( TOKEN ("yd") ); |
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
void |
void |
123 |
get_uncompressed_ip (vjip, vjiplen) |
get_uncompressed_ip (vjip, vjiplen) |
145 |
{ |
{ |
146 |
/* copy header */ |
/* copy header */ |
147 |
memcpy (tmp, iphdr, iphdrlen); |
memcpy (tmp, iphdr, iphdrlen); |
148 |
/* copy data */ |
iphdr[0] &= ~TYPE_UNCOMPRESSED_TCP; |
149 |
|
iphdr[0] |= TYPE_IP; |
150 |
|
/* copy data */ |
151 |
memcpy (&tmp[iphdrlen], &vjip[vjhdrlen], vjiplen - vjhdrlen); |
memcpy (&tmp[iphdrlen], &vjip[vjhdrlen], vjiplen - vjhdrlen); |
152 |
iface->put (ifout, tmp, iplen); |
iface->put (ifout, tmp, iplen); |
153 |
free (tmp); |
free (tmp); |
162 |
{ |
{ |
163 |
debug (2, "IP tunnel - packet type: TYPE_UNCOMPRESSED_TCP\n"); |
debug (2, "IP tunnel - packet type: TYPE_UNCOMPRESSED_TCP\n"); |
164 |
/* an uncompressed TCP do *NOT* modify the size of the packet */ |
/* an uncompressed TCP do *NOT* modify the size of the packet */ |
165 |
if (vj_uncompress_uncomp (vjip, vjiplen, &vj_comp)) |
vj_uncompress_uncomp (vjip, vjiplen, &vj_comp); |
166 |
{ |
vjip[0] &= ~TYPE_UNCOMPRESSED_TCP; |
167 |
iface->put (ifout, vjip, vjiplen); |
vjip[0] |= TYPE_IP; |
168 |
} |
iface->put (ifout, vjip, vjiplen); |
|
else |
|
|
log (LOG_WARNING, "IP tunnel - Unable to uncompress the packet"); |
|
169 |
} |
} |
170 |
else if ((vjip[0] & TYPE_IP) == TYPE_IP) |
else if ((vjip[0] & TYPE_IP) == TYPE_IP) |
171 |
{ |
{ |