105-debian_demand.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --- a/pppd/demand.c
  2. +++ b/pppd/demand.c
  3. @@ -36,6 +36,8 @@
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <netdb.h>
  7. +#include <unistd.h>
  8. +#include <syslog.h>
  9. #include <sys/param.h>
  10. #include <sys/types.h>
  11. #include <sys/wait.h>
  12. @@ -43,6 +45,8 @@
  13. #include <sys/resource.h>
  14. #include <sys/stat.h>
  15. #include <sys/socket.h>
  16. +#include <netinet/in.h>
  17. +#include <arpa/inet.h>
  18. #ifdef PPP_FILTER
  19. #include <pcap-bpf.h>
  20. #endif
  21. @@ -221,6 +225,14 @@ loop_chars(p, n)
  22. int c, rv;
  23. rv = 0;
  24. +
  25. +/* check for synchronous connection... */
  26. +
  27. + if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
  28. + rv = loop_frame(p,n);
  29. + return rv;
  30. + }
  31. +
  32. for (; n > 0; --n) {
  33. c = *p++;
  34. if (c == PPP_FLAG) {
  35. @@ -299,17 +311,102 @@ loop_frame(frame, len)
  36. * loopback, now that the real serial link is up.
  37. */
  38. void
  39. -demand_rexmit(proto)
  40. +demand_rexmit(proto, newip)
  41. int proto;
  42. + u_int32_t newip;
  43. {
  44. struct packet *pkt, *prev, *nextpkt;
  45. + unsigned short checksum;
  46. + unsigned short pkt_checksum = 0;
  47. + unsigned iphdr;
  48. + struct timeval tv;
  49. + char cv = 0;
  50. + char ipstr[16];
  51. prev = NULL;
  52. pkt = pend_q;
  53. pend_q = NULL;
  54. + tv.tv_sec = 1;
  55. + tv.tv_usec = 0;
  56. + select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
  57. for (; pkt != NULL; pkt = nextpkt) {
  58. nextpkt = pkt->next;
  59. if (PPP_PROTOCOL(pkt->data) == proto) {
  60. + if ( (proto == PPP_IP) && newip ) {
  61. + /* Get old checksum */
  62. +
  63. + iphdr = (pkt->data[4] & 15) << 2;
  64. + checksum = *((unsigned short *) (pkt->data+14));
  65. + if (checksum == 0xFFFF) {
  66. + checksum = 0;
  67. + }
  68. +
  69. +
  70. + if (pkt->data[13] == 17) {
  71. + pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
  72. + if (pkt_checksum) {
  73. + cv = 1;
  74. + if (pkt_checksum == 0xFFFF) {
  75. + pkt_checksum = 0;
  76. + }
  77. + }
  78. + else {
  79. + cv = 0;
  80. + }
  81. + }
  82. +
  83. + if (pkt->data[13] == 6) {
  84. + pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
  85. + cv = 1;
  86. + if (pkt_checksum == 0xFFFF) {
  87. + pkt_checksum = 0;
  88. + }
  89. + }
  90. +
  91. + /* Delete old Source-IP-Address */
  92. + checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
  93. + checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
  94. +
  95. + pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
  96. + pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
  97. +
  98. + /* Change Source-IP-Address */
  99. + * ((u_int32_t *) (pkt->data + 16)) = newip;
  100. +
  101. + /* Add new Source-IP-Address */
  102. + checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
  103. + checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
  104. +
  105. + pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
  106. + pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
  107. +
  108. + /* Write new checksum */
  109. + if (!checksum) {
  110. + checksum = 0xFFFF;
  111. + }
  112. + *((unsigned short *) (pkt->data+14)) = checksum;
  113. + if (pkt->data[13] == 6) {
  114. + *((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
  115. + }
  116. + if (cv && (pkt->data[13] == 17) ) {
  117. + *((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
  118. + }
  119. +
  120. + /* Log Packet */
  121. + strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
  122. + if (pkt->data[13] == 1) {
  123. + syslog(LOG_INFO,"Open ICMP %s -> %s\n",
  124. + ipstr,
  125. + inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
  126. + } else {
  127. + syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
  128. + pkt->data[13] == 6 ? "TCP" : "UDP",
  129. + ipstr,
  130. + ntohs(*( (short *) (pkt->data+iphdr+4))),
  131. + inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
  132. + ntohs(*( (short *) (pkt->data+iphdr+6))));
  133. + }
  134. + }
  135. output(0, pkt->data, pkt->length);
  136. free(pkt);
  137. } else {
  138. --- a/pppd/ipcp.c
  139. +++ b/pppd/ipcp.c
  140. @@ -1883,7 +1883,7 @@ ipcp_up(f)
  141. proxy_arp_set[f->unit] = 1;
  142. }
  143. - demand_rexmit(PPP_IP);
  144. + demand_rexmit(PPP_IP,go->ouraddr);
  145. sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
  146. } else {
  147. --- a/pppd/ipv6cp.c
  148. +++ b/pppd/ipv6cp.c
  149. @@ -1232,7 +1232,7 @@ ipv6cp_up(f)
  150. }
  151. }
  152. - demand_rexmit(PPP_IPV6);
  153. + demand_rexmit(PPP_IPV6,0);
  154. sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
  155. } else {
  156. --- a/pppd/pppd.h
  157. +++ b/pppd/pppd.h
  158. @@ -599,7 +599,7 @@ void demand_conf __P((void)); /* config
  159. void demand_block __P((void)); /* set all NPs to queue up packets */
  160. void demand_unblock __P((void)); /* set all NPs to pass packets */
  161. void demand_discard __P((void)); /* set all NPs to discard packets */
  162. -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
  163. +void demand_rexmit __P((int, u_int32_t)); /* retransmit saved frames for an NP*/
  164. int loop_chars __P((unsigned char *, int)); /* process chars from loopback */
  165. int loop_frame __P((unsigned char *, int)); /* should we bring link up? */