20 |
* 02111-1307, USA. |
* 02111-1307, USA. |
21 |
* |
* |
22 |
*/ |
*/ |
23 |
|
#include "config.h" |
24 |
|
|
25 |
|
#include <stdlib.h> |
26 |
|
#include <sys/types.h> |
27 |
|
#include <netinet/in.h> |
28 |
|
#ifdef HAVE_NETINET_IN_SYSTM_H |
29 |
|
# include <netinet/in_systm.h> |
30 |
|
#endif |
31 |
|
#include <netinet/ip.h> |
32 |
|
#include <net/ppp_defs.h> |
33 |
|
|
34 |
#include <stdio.h> |
#include <stdio.h> |
35 |
#include <string.h> |
#include <string.h> |
37 |
#include "prot30.h" |
#include "prot30.h" |
38 |
#include "p30data.h" |
#include "p30data.h" |
39 |
#include "p30tcpip.h" |
#include "p30tcpip.h" |
40 |
|
#include "vjcompress.h" |
41 |
|
|
42 |
|
#include "log.h" |
43 |
#include "options.h" |
#include "options.h" |
44 |
#include "if.h" |
#include "if.h" |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
|
|
47 |
int ipnum = 0; |
int ipnum = 0; |
48 |
|
struct vjcompress vj_comp; |
49 |
|
#define MAX_VJHEADER 16 /* Maximum size of compressed header */ |
50 |
void |
void |
51 |
prot30_send_ip_config () |
prot30_send_ip_config () |
52 |
{ |
{ |
73 |
config = (struct ip_config_reply_t *) data; |
config = (struct ip_config_reply_t *) data; |
74 |
config->address = ntohl (config->address); |
config->address = ntohl (config->address); |
75 |
config->dns_address = ntohl (config->dns_address); |
config->dns_address = ntohl (config->dns_address); |
76 |
printf ("IP address: %d.%d.%d.%d\n", |
log (LOG_NOTICE, "P3/TCPIP - IP address: %d.%d.%d.%d\n", |
77 |
config->address >> 24 & 0xff, |
config->address >> 24 & 0xff, |
78 |
config->address >> 16 & 0xff, |
config->address >> 16 & 0xff, |
79 |
config->address >> 8 & 0xff, config->address & 0xff); |
config->address >> 8 & 0xff, config->address & 0xff); |
80 |
printf ("DNS address: %d.%d.%d.%d\n", |
log (LOG_NOTICE, "P3/TCPIP - DNS address: %d.%d.%d.%d\n", |
81 |
config->dns_address >> 24 & 0xff, |
config->dns_address >> 24 & 0xff, |
82 |
config->dns_address >> 16 & 0xff, |
config->dns_address >> 16 & 0xff, |
83 |
config->dns_address >> 8 & 0xff, config->dns_address & 0xff); |
config->dns_address >> 8 & 0xff, config->dns_address & 0xff); |
84 |
|
|
85 |
end = memchr (&config->hostname, 0x0c, data_size - sizeof (*config)); |
end = memchr (&config->hostname, 0x0c, data_size - sizeof (*config)); |
86 |
len = (int) end - (int) &config->hostname; |
len = (int) end - (int) &config->hostname; |
88 |
len = 255; |
len = 255; |
89 |
strncpy (hostname, &config->hostname, len); |
strncpy (hostname, &config->hostname, len); |
90 |
hostname[len] = '\0'; |
hostname[len] = '\0'; |
91 |
printf ("Hostname: %s\n", hostname); |
log (LOG_NOTICE, "P3/TCPIP - Hostname: %s\n", hostname); |
92 |
|
|
93 |
launch_ip_up (PARAM_INTERFACE_NAME, |
launch_ip_up (PARAM_INTERFACE_NAME, |
94 |
config->address, 0xffffffff, |
config->address, 0xffffffff, |
95 |
config->address & 0xffffff00, |
config->address & 0xffffff00, |
96 |
config->address | 0x000000ff, config->address); |
config->address | 0x000000ff, config->address); |
97 |
|
|
98 |
|
vj_compress_init (&vj_comp, -1); |
99 |
prot30_set_state (normal); |
prot30_set_state (normal); |
100 |
} |
} |
101 |
else |
else |
102 |
{ |
{ |
103 |
printf ("Received an ip_config while ever configured\n"); |
log (LOG_WARNING, |
104 |
|
"P3/TCPIP - Received an ip_config while ever configured\n"); |
105 |
} |
} |
106 |
} |
} |
107 |
|
|
117 |
if (small->len & LONG_IP_BIT) |
if (small->len & LONG_IP_BIT) |
118 |
/* This packet is a long ip (>128 bytes) */ |
/* This packet is a long ip (>128 bytes) */ |
119 |
{ |
{ |
120 |
big->len &= LONG_IP_MASK; |
debug (1, "P3/TCPIP - Received a big packet\n"); |
121 |
if_put (&if_out, big->ip_data, data_size - 3); |
prot30_get_uncompress_ip (big->ip_data, big->len & LONG_IP_MASK); |
122 |
} |
} |
123 |
else |
else |
124 |
{ |
{ |
125 |
if_put (&if_out, big->ip_data, data_size - 2); |
debug (1, "P3/TCPIP - Received a small packet\n"); |
126 |
|
prot30_get_uncompress_ip (small->ip_data, small->len); |
127 |
} |
} |
128 |
} |
} |
129 |
|
|
132 |
char *data; |
char *data; |
133 |
size_t data_size; |
size_t data_size; |
134 |
{ |
{ |
135 |
|
/* an extra packet is the continuation of a big 'big packet' |
136 |
|
so there is no IP header |
137 |
|
*/ |
138 |
if_put (&if_out, data, data_size); |
if_put (&if_out, data, data_size); |
139 |
} |
} |
140 |
|
|
141 |
void |
void |
142 |
prot30_send_ip () |
prot30_send_ip () |
143 |
{ |
{ |
144 |
char *data; |
char *ip; |
145 |
size_t data_size; |
size_t ip_size; |
146 |
int offset; |
int offset; |
147 |
struct short_ip_t small; |
aol_data_t data; |
148 |
struct long_ip_t big; |
struct short_ip_t *small; |
149 |
|
struct long_ip_t *big; |
150 |
|
|
151 |
while (if_get (&if_in, &data, &data_size)) |
debug (1, "P3/TCPIP - Sending IP...\n"); |
152 |
|
small = (struct short_ip_t *) data.raw; |
153 |
|
big = (struct long_ip_t *) data.raw; |
154 |
|
while (if_get (&if_in, &ip, &ip_size)) |
155 |
{ |
{ |
156 |
if (data_size > 0x7f) |
if (ip_size > 0x7f) |
157 |
{ |
{ |
158 |
|
debug (1, "P3/TCPIP - Sending a big packet\n"); |
159 |
offset = 0; |
offset = 0; |
160 |
while (data_size - offset > MAX_PACKET_SIZE - AOL_DATA_OFFSET - 3) |
big->ipnum = ipnum; |
161 |
big.ipnum = ipnum; |
big->len = ip_size | ~LONG_IP_MASK; |
162 |
big.len = data_size & LONG_IP_MASK; |
memcpy (big->ip_data, ip, ip_size); |
163 |
memcpy (big.ip_data, data, data_size); |
prot30_send_data (CODE_IP_NORMAL, &data, ip_size + 3); |
164 |
} |
} |
165 |
else |
else |
166 |
{ |
{ |
167 |
small.ipnum = ipnum; |
debug (1, "P3/TCPIP - Sending a small packet\n"); |
168 |
small.len = data_size; |
small->ipnum = ipnum; |
169 |
memcpy (small.ip_data, data, data_size); |
small->len = ip_size; |
170 |
|
memcpy (small->ip_data, ip, ip_size); |
171 |
|
prot30_send_data (CODE_IP_NORMAL, &data, ip_size + 2); |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
} |
} |
176 |
|
|
177 |
|
void |
178 |
|
prot30_get_uncompress_ip (vjip, vjiplen) |
179 |
|
char *vjip; |
180 |
|
size_t vjiplen; |
181 |
|
{ |
182 |
|
int vjhdrlen, iphdrlen, iplen; |
183 |
|
unsigned char *iphdr; |
184 |
|
char *tmp; |
185 |
|
|
186 |
|
if ((vjip[0] & TYPE_COMPRESSED_TCP) == TYPE_COMPRESSED_TCP) |
187 |
|
{ |
188 |
|
debug (2, "P3/TCPIP - packet type: TYPE_COMPRESSED_TCP\n"); |
189 |
|
vjhdrlen = vj_uncompress_tcp (vjip, vjiplen, vjiplen, |
190 |
|
&vj_comp, &iphdr, &iphdrlen); |
191 |
|
/* allocate a buffer to contruct the uncompressed packet */ |
192 |
|
iplen = iphdrlen + (vjiplen - vjhdrlen); |
193 |
|
tmp = malloc (iplen); |
194 |
|
if (tmp) |
195 |
|
{ |
196 |
|
/* copy header */ |
197 |
|
memcpy (tmp, iphdr, iphdrlen); |
198 |
|
/* copy data */ |
199 |
|
memcpy (&tmp[iphdrlen], &vjip[vjhdrlen], vjiplen - vjhdrlen); |
200 |
|
if_put (&if_out, tmp, iplen); |
201 |
|
free (tmp); |
202 |
|
} |
203 |
|
else |
204 |
|
{ |
205 |
|
log (LOG_CRIT, "P3/TCPIP - Unable to allocate memory\n"); |
206 |
|
exit (1); |
207 |
|
} |
208 |
|
} |
209 |
|
else if ((vjip[0] & TYPE_UNCOMPRESSED_TCP) == TYPE_UNCOMPRESSED_TCP) |
210 |
|
{ |
211 |
|
debug (2, "P3/TCPIP - packet type: TYPE_UNCOMPRESSED_TCP\n"); |
212 |
|
/* an uncompressed TCP do *NOT* modify the size of the packet */ |
213 |
|
if (vj_uncompress_uncomp (vjip, vjiplen, &vj_comp)) |
214 |
|
{ |
215 |
|
if_put (&if_out, vjip, vjiplen); |
216 |
|
} |
217 |
|
} |
218 |
|
else if ((vjip[0] & TYPE_IP) == TYPE_IP) |
219 |
|
{ |
220 |
|
debug (2, "P3/TCPIP - packet type: TYPE_IP\n"); |
221 |
|
/* So it's a raw IP packet */ |
222 |
|
if_put (&if_out, vjip, vjiplen); |
223 |
|
} |
224 |
|
else |
225 |
|
log (LOG_WARNING, "P3/TCPIP - received an unknown IP packet\n"); |
226 |
|
} |