6c374174c47e08d940e18784b00c415a1963f41a
[openwrt.git] / package / ppp / patches / 105-debian_demand.patch
1 diff -Naur ppp-2.4.4.orig/pppd/demand.c ppp-2.4.4/pppd/demand.c
2 --- ppp-2.4.4.orig/pppd/demand.c 2005-08-25 08:14:18.000000000 -0400
3 +++ ppp-2.4.4/pppd/demand.c 2009-05-07 16:16:20.000000000 -0400
4 @@ -36,6 +36,8 @@
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <netdb.h>
8 +#include <unistd.h>
9 +#include <syslog.h>
10 #include <sys/param.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13 @@ -43,6 +45,8 @@
14 #include <sys/resource.h>
15 #include <sys/stat.h>
16 #include <sys/socket.h>
17 +#include <netinet/in.h>
18 +#include <arpa/inet.h>
19 #ifdef PPP_FILTER
20 #include <pcap-bpf.h>
21 #endif
22 @@ -221,6 +225,14 @@
23 int c, rv;
24
25 rv = 0;
26 +
27 +/* check for synchronous connection... */
28 +
29 + if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
30 + rv = loop_frame(p,n);
31 + return rv;
32 + }
33 +
34 for (; n > 0; --n) {
35 c = *p++;
36 if (c == PPP_FLAG) {
37 @@ -299,17 +311,102 @@
38 * loopback, now that the real serial link is up.
39 */
40 void
41 -demand_rexmit(proto)
42 +demand_rexmit(proto, newip)
43 int proto;
44 + u_int32_t newip;
45 {
46 struct packet *pkt, *prev, *nextpkt;
47 + unsigned short checksum;
48 + unsigned short pkt_checksum = 0;
49 + unsigned iphdr;
50 + struct timeval tv;
51 + char cv = 0;
52 + char ipstr[16];
53
54 prev = NULL;
55 pkt = pend_q;
56 pend_q = NULL;
57 + tv.tv_sec = 1;
58 + tv.tv_usec = 0;
59 + select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
60 for (; pkt != NULL; pkt = nextpkt) {
61 nextpkt = pkt->next;
62 if (PPP_PROTOCOL(pkt->data) == proto) {
63 + if ( (proto == PPP_IP) && newip ) {
64 + /* Get old checksum */
65 +
66 + iphdr = (pkt->data[4] & 15) << 2;
67 + checksum = *((unsigned short *) (pkt->data+14));
68 + if (checksum == 0xFFFF) {
69 + checksum = 0;
70 + }
71 +
72 +
73 + if (pkt->data[13] == 17) {
74 + pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
75 + if (pkt_checksum) {
76 + cv = 1;
77 + if (pkt_checksum == 0xFFFF) {
78 + pkt_checksum = 0;
79 + }
80 + }
81 + else {
82 + cv = 0;
83 + }
84 + }
85 +
86 + if (pkt->data[13] == 6) {
87 + pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
88 + cv = 1;
89 + if (pkt_checksum == 0xFFFF) {
90 + pkt_checksum = 0;
91 + }
92 + }
93 +
94 + /* Delete old Source-IP-Address */
95 + checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
96 + checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
97 +
98 + pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
99 + pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
100 +
101 + /* Change Source-IP-Address */
102 + * ((u_int32_t *) (pkt->data + 16)) = newip;
103 +
104 + /* Add new Source-IP-Address */
105 + checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
106 + checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
107 +
108 + pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
109 + pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
110 +
111 + /* Write new checksum */
112 + if (!checksum) {
113 + checksum = 0xFFFF;
114 + }
115 + *((unsigned short *) (pkt->data+14)) = checksum;
116 + if (pkt->data[13] == 6) {
117 + *((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
118 + }
119 + if (cv && (pkt->data[13] == 17) ) {
120 + *((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
121 + }
122 +
123 + /* Log Packet */
124 + strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
125 + if (pkt->data[13] == 1) {
126 + syslog(LOG_INFO,"Open ICMP %s -> %s\n",
127 + ipstr,
128 + inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
129 + } else {
130 + syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
131 + pkt->data[13] == 6 ? "TCP" : "UDP",
132 + ipstr,
133 + ntohs(*( (short *) (pkt->data+iphdr+4))),
134 + inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
135 + ntohs(*( (short *) (pkt->data+iphdr+6))));
136 + }
137 + }
138 output(0, pkt->data, pkt->length);
139 free(pkt);
140 } else {
141 diff -Naur ppp-2.4.4.orig/pppd/ipcp.c ppp-2.4.4/pppd/ipcp.c
142 --- ppp-2.4.4.orig/pppd/ipcp.c 2009-05-07 15:49:34.000000000 -0400
143 +++ ppp-2.4.4/pppd/ipcp.c 2009-05-07 16:16:20.000000000 -0400
144 @@ -1776,7 +1776,7 @@
145 proxy_arp_set[f->unit] = 1;
146
147 }
148 - demand_rexmit(PPP_IP);
149 + demand_rexmit(PPP_IP,go->ouraddr);
150 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
151
152 } else {
153 diff -Naur ppp-2.4.4.orig/pppd/ipv6cp.c ppp-2.4.4/pppd/ipv6cp.c
154 --- ppp-2.4.4.orig/pppd/ipv6cp.c 2005-08-25 19:59:34.000000000 -0400
155 +++ ppp-2.4.4/pppd/ipv6cp.c 2009-05-07 16:16:20.000000000 -0400
156 @@ -1232,7 +1232,7 @@
157 }
158
159 }
160 - demand_rexmit(PPP_IPV6);
161 + demand_rexmit(PPP_IPV6,0);
162 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
163
164 } else {
165 diff -Naur ppp-2.4.4.orig/pppd/pppd.h ppp-2.4.4/pppd/pppd.h
166 --- ppp-2.4.4.orig/pppd/pppd.h 2009-05-07 15:49:34.000000000 -0400
167 +++ ppp-2.4.4/pppd/pppd.h 2009-05-07 16:16:20.000000000 -0400
168 @@ -565,7 +565,7 @@
169 void demand_block __P((void)); /* set all NPs to queue up packets */
170 void demand_unblock __P((void)); /* set all NPs to pass packets */
171 void demand_discard __P((void)); /* set all NPs to discard packets */
172 -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
173 +void demand_rexmit __P((int, u_int32_t)); /* retransmit saved frames for an NP*/
174 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
175 int loop_frame __P((unsigned char *, int)); /* should we bring link up? */
176
177 diff -Naur ppp-2.4.4.orig/pppd/demand.c ppp-2.4.4/pppd/demand.c
178 --- ppp-2.4.4.orig/pppd/demand.c 2005-08-25 08:14:18.000000000 -0400
179 +++ ppp-2.4.4/pppd/demand.c 2009-05-07 16:16:20.000000000 -0400
180 @@ -36,6 +36,8 @@
181 #include <errno.h>
182 #include <fcntl.h>
183 #include <netdb.h>
184 +#include <unistd.h>
185 +#include <syslog.h>
186 #include <sys/param.h>
187 #include <sys/types.h>
188 #include <sys/wait.h>
189 @@ -43,6 +45,8 @@
190 #include <sys/resource.h>
191 #include <sys/stat.h>
192 #include <sys/socket.h>
193 +#include <netinet/in.h>
194 +#include <arpa/inet.h>
195 #ifdef PPP_FILTER
196 #include <pcap-bpf.h>
197 #endif
198 @@ -221,6 +225,14 @@
199 int c, rv;
200
201 rv = 0;
202 +
203 +/* check for synchronous connection... */
204 +
205 + if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
206 + rv = loop_frame(p,n);
207 + return rv;
208 + }
209 +
210 for (; n > 0; --n) {
211 c = *p++;
212 if (c == PPP_FLAG) {
213 @@ -299,17 +311,102 @@
214 * loopback, now that the real serial link is up.
215 */
216 void
217 -demand_rexmit(proto)
218 +demand_rexmit(proto, newip)
219 int proto;
220 + u_int32_t newip;
221 {
222 struct packet *pkt, *prev, *nextpkt;
223 + unsigned short checksum;
224 + unsigned short pkt_checksum = 0;
225 + unsigned iphdr;
226 + struct timeval tv;
227 + char cv = 0;
228 + char ipstr[16];
229
230 prev = NULL;
231 pkt = pend_q;
232 pend_q = NULL;
233 + tv.tv_sec = 1;
234 + tv.tv_usec = 0;
235 + select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
236 for (; pkt != NULL; pkt = nextpkt) {
237 nextpkt = pkt->next;
238 if (PPP_PROTOCOL(pkt->data) == proto) {
239 + if ( (proto == PPP_IP) && newip ) {
240 + /* Get old checksum */
241 +
242 + iphdr = (pkt->data[4] & 15) << 2;
243 + checksum = *((unsigned short *) (pkt->data+14));
244 + if (checksum == 0xFFFF) {
245 + checksum = 0;
246 + }
247 +
248 +
249 + if (pkt->data[13] == 17) {
250 + pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
251 + if (pkt_checksum) {
252 + cv = 1;
253 + if (pkt_checksum == 0xFFFF) {
254 + pkt_checksum = 0;
255 + }
256 + }
257 + else {
258 + cv = 0;
259 + }
260 + }
261 +
262 + if (pkt->data[13] == 6) {
263 + pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
264 + cv = 1;
265 + if (pkt_checksum == 0xFFFF) {
266 + pkt_checksum = 0;
267 + }
268 + }
269 +
270 + /* Delete old Source-IP-Address */
271 + checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
272 + checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
273 +
274 + pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
275 + pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
276 +
277 + /* Change Source-IP-Address */
278 + * ((u_int32_t *) (pkt->data + 16)) = newip;
279 +
280 + /* Add new Source-IP-Address */
281 + checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
282 + checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
283 +
284 + pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
285 + pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
286 +
287 + /* Write new checksum */
288 + if (!checksum) {
289 + checksum = 0xFFFF;
290 + }
291 + *((unsigned short *) (pkt->data+14)) = checksum;
292 + if (pkt->data[13] == 6) {
293 + *((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
294 + }
295 + if (cv && (pkt->data[13] == 17) ) {
296 + *((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
297 + }
298 +
299 + /* Log Packet */
300 + strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
301 + if (pkt->data[13] == 1) {
302 + syslog(LOG_INFO,"Open ICMP %s -> %s\n",
303 + ipstr,
304 + inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
305 + } else {
306 + syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
307 + pkt->data[13] == 6 ? "TCP" : "UDP",
308 + ipstr,
309 + ntohs(*( (short *) (pkt->data+iphdr+4))),
310 + inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
311 + ntohs(*( (short *) (pkt->data+iphdr+6))));
312 + }
313 + }
314 output(0, pkt->data, pkt->length);
315 free(pkt);
316 } else {
317 diff -Naur ppp-2.4.4.orig/pppd/ipcp.c ppp-2.4.4/pppd/ipcp.c
318 --- ppp-2.4.4.orig/pppd/ipcp.c 2009-05-07 15:49:34.000000000 -0400
319 +++ ppp-2.4.4/pppd/ipcp.c 2009-05-07 16:16:20.000000000 -0400
320 @@ -1776,7 +1776,7 @@
321 proxy_arp_set[f->unit] = 1;
322
323 }
324 - demand_rexmit(PPP_IP);
325 + demand_rexmit(PPP_IP,go->ouraddr);
326 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
327
328 } else {
329 diff -Naur ppp-2.4.4.orig/pppd/ipv6cp.c ppp-2.4.4/pppd/ipv6cp.c
330 --- ppp-2.4.4.orig/pppd/ipv6cp.c 2005-08-25 19:59:34.000000000 -0400
331 +++ ppp-2.4.4/pppd/ipv6cp.c 2009-05-07 16:16:20.000000000 -0400
332 @@ -1232,7 +1232,7 @@
333 }
334
335 }
336 - demand_rexmit(PPP_IPV6);
337 + demand_rexmit(PPP_IPV6,0);
338 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
339
340 } else {
341 diff -Naur ppp-2.4.4.orig/pppd/pppd.h ppp-2.4.4/pppd/pppd.h
342 --- ppp-2.4.4.orig/pppd/pppd.h 2009-05-07 15:49:34.000000000 -0400
343 +++ ppp-2.4.4/pppd/pppd.h 2009-05-07 16:16:20.000000000 -0400
344 @@ -565,7 +565,7 @@
345 void demand_block __P((void)); /* set all NPs to queue up packets */
346 void demand_unblock __P((void)); /* set all NPs to pass packets */
347 void demand_discard __P((void)); /* set all NPs to discard packets */
348 -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
349 +void demand_rexmit __P((int, u_int32_t)); /* retransmit saved frames for an NP*/
350 int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
351 int loop_frame __P((unsigned char *, int)); /* should we bring link up? */
352
This page took 0.057749 seconds and 3 git commands to generate.