105-debian_demand.patch 5.1 KB

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