| 1 |
Forwarded: https://github.com/ppp-project/ppp/issues/187 |
| 2 |
|
| 3 |
Upstream said: |
| 4 |
|
| 5 |
" |
| 6 |
Hmmm, dial-on-demand was never tested with the sync option, and in fact I don't |
| 7 |
know what devices would use that option. |
| 8 |
|
| 9 |
To be accepted, the patch would need a sign-off and a description that |
| 10 |
explained the changes in the patch - in particular, what the large lump of code |
| 11 |
added to demand_rexmit() is doing. |
| 12 |
" |
| 13 |
|
| 14 |
--- a/pppd/demand.c |
| 15 |
+++ b/pppd/demand.c |
| 16 |
@@ -40,6 +40,8 @@ |
| 17 |
#include <errno.h> |
| 18 |
#include <fcntl.h> |
| 19 |
#include <netdb.h> |
| 20 |
+#include <unistd.h> |
| 21 |
+#include <syslog.h> |
| 22 |
#include <sys/param.h> |
| 23 |
#include <sys/types.h> |
| 24 |
#include <sys/wait.h> |
| 25 |
@@ -47,6 +49,8 @@ |
| 26 |
#include <sys/resource.h> |
| 27 |
#include <sys/stat.h> |
| 28 |
#include <sys/socket.h> |
| 29 |
+#include <netinet/in.h> |
| 30 |
+#include <arpa/inet.h> |
| 31 |
#ifdef PPP_WITH_FILTER |
| 32 |
#include <pcap-bpf.h> |
| 33 |
#endif |
| 34 |
@@ -223,6 +227,14 @@ loop_chars(unsigned char *p, int n) |
| 35 |
int c, rv; |
| 36 |
|
| 37 |
rv = 0; |
| 38 |
+ |
| 39 |
+/* check for synchronous connection... */ |
| 40 |
+ |
| 41 |
+ if ( (p[0] == 0xFF) && (p[1] == 0x03) ) { |
| 42 |
+ rv = loop_frame(p,n); |
| 43 |
+ return rv; |
| 44 |
+ } |
| 45 |
+ |
| 46 |
for (; n > 0; --n) { |
| 47 |
c = *p++; |
| 48 |
if (c == PPP_FLAG) { |
| 49 |
@@ -299,16 +311,101 @@ loop_frame(unsigned char *frame, int len |
| 50 |
* loopback, now that the real serial link is up. |
| 51 |
*/ |
| 52 |
void |
| 53 |
-demand_rexmit(int proto) |
| 54 |
+demand_rexmit(int proto, u_int32_t newip) |
| 55 |
{ |
| 56 |
struct packet *pkt, *prev, *nextpkt; |
| 57 |
+ unsigned short checksum; |
| 58 |
+ unsigned short pkt_checksum = 0; |
| 59 |
+ unsigned iphdr; |
| 60 |
+ struct timeval tv; |
| 61 |
+ char cv = 0; |
| 62 |
+ char ipstr[16]; |
| 63 |
|
| 64 |
prev = NULL; |
| 65 |
pkt = pend_q; |
| 66 |
pend_q = NULL; |
| 67 |
+ |
| 68 |
+ tv.tv_sec = 1; |
| 69 |
+ tv.tv_usec = 0; |
| 70 |
+ select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Second */ |
| 71 |
+ |
| 72 |
for (; pkt != NULL; pkt = nextpkt) { |
| 73 |
nextpkt = pkt->next; |
| 74 |
if (PPP_PROTOCOL(pkt->data) == proto) { |
| 75 |
+ if ( (proto == PPP_IP) && newip ) { |
| 76 |
+ /* Get old checksum */ |
| 77 |
+ |
| 78 |
+ iphdr = (pkt->data[4] & 15) << 2; |
| 79 |
+ checksum = *((unsigned short *) (pkt->data+14)); |
| 80 |
+ if (checksum == 0xFFFF) { |
| 81 |
+ checksum = 0; |
| 82 |
+ } |
| 83 |
+ |
| 84 |
+ if (pkt->data[13] == 17) { |
| 85 |
+ pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr)); |
| 86 |
+ if (pkt_checksum) { |
| 87 |
+ cv = 1; |
| 88 |
+ if (pkt_checksum == 0xFFFF) { |
| 89 |
+ pkt_checksum = 0; |
| 90 |
+ } |
| 91 |
+ } |
| 92 |
+ else { |
| 93 |
+ cv = 0; |
| 94 |
+ } |
| 95 |
+ } |
| 96 |
+ |
| 97 |
+ if (pkt->data[13] == 6) { |
| 98 |
+ pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr)); |
| 99 |
+ cv = 1; |
| 100 |
+ if (pkt_checksum == 0xFFFF) { |
| 101 |
+ pkt_checksum = 0; |
| 102 |
+ } |
| 103 |
+ } |
| 104 |
+ |
| 105 |
+ /* Delete old Source-IP-Address */ |
| 106 |
+ checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF; |
| 107 |
+ checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF; |
| 108 |
+ |
| 109 |
+ pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF; |
| 110 |
+ pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF; |
| 111 |
+ |
| 112 |
+ /* Change Source-IP-Address */ |
| 113 |
+ * ((u_int32_t *) (pkt->data + 16)) = newip; |
| 114 |
+ |
| 115 |
+ /* Add new Source-IP-Address */ |
| 116 |
+ checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF; |
| 117 |
+ checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF; |
| 118 |
+ |
| 119 |
+ pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF; |
| 120 |
+ pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF; |
| 121 |
+ |
| 122 |
+ /* Write new checksum */ |
| 123 |
+ if (!checksum) { |
| 124 |
+ checksum = 0xFFFF; |
| 125 |
+ } |
| 126 |
+ *((unsigned short *) (pkt->data+14)) = checksum; |
| 127 |
+ if (pkt->data[13] == 6) { |
| 128 |
+ *((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum; |
| 129 |
+ } |
| 130 |
+ if (cv && (pkt->data[13] == 17) ) { |
| 131 |
+ *((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum; |
| 132 |
+ } |
| 133 |
+ |
| 134 |
+ /* Log Packet */ |
| 135 |
+ strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16)))); |
| 136 |
+ if (pkt->data[13] == 1) { |
| 137 |
+ syslog(LOG_INFO,"Open ICMP %s -> %s\n", |
| 138 |
+ ipstr, |
| 139 |
+ inet_ntoa(*( (struct in_addr *) (pkt->data+20)))); |
| 140 |
+ } else { |
| 141 |
+ syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n", |
| 142 |
+ pkt->data[13] == 6 ? "TCP" : "UDP", |
| 143 |
+ ipstr, |
| 144 |
+ ntohs(*( (short *) (pkt->data+iphdr+4))), |
| 145 |
+ inet_ntoa(*( (struct in_addr *) (pkt->data+20))), |
| 146 |
+ ntohs(*( (short *) (pkt->data+iphdr+6)))); |
| 147 |
+ } |
| 148 |
+ } |
| 149 |
output(0, pkt->data, pkt->length); |
| 150 |
free(pkt); |
| 151 |
} else { |
| 152 |
--- a/pppd/ipcp.c |
| 153 |
+++ b/pppd/ipcp.c |
| 154 |
@@ -1911,7 +1911,7 @@ ipcp_up(fsm *f) |
| 155 |
proxy_arp_set[f->unit] = 1; |
| 156 |
|
| 157 |
} |
| 158 |
- demand_rexmit(PPP_IP); |
| 159 |
+ demand_rexmit(PPP_IP,go->ouraddr); |
| 160 |
sifnpmode(f->unit, PPP_IP, NPMODE_PASS); |
| 161 |
|
| 162 |
} else { |
| 163 |
--- a/pppd/ipv6cp.c |
| 164 |
+++ b/pppd/ipv6cp.c |
| 165 |
@@ -1338,7 +1338,7 @@ ipv6cp_up(fsm *f) |
| 166 |
if (sif6defaultroute(f->unit, go->ourid, ho->hisid)) |
| 167 |
default_route_set[f->unit] = 1; |
| 168 |
} |
| 169 |
- demand_rexmit(PPP_IPV6); |
| 170 |
+ demand_rexmit(PPP_IPV6,0); |
| 171 |
sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS); |
| 172 |
|
| 173 |
} else { |
| 174 |
--- a/pppd/pppd-private.h |
| 175 |
+++ b/pppd/pppd-private.h |
| 176 |
@@ -362,7 +362,7 @@ void demand_conf(void); /* config interf |
| 177 |
void demand_block(void); /* set all NPs to queue up packets */ |
| 178 |
void demand_unblock(void); /* set all NPs to pass packets */ |
| 179 |
void demand_discard(void); /* set all NPs to discard packets */ |
| 180 |
-void demand_rexmit(int); /* retransmit saved frames for an NP */ |
| 181 |
+void demand_rexmit(int, u_int32_t); /* retransmit saved frames for an NP */ |
| 182 |
int loop_chars(unsigned char *, int); /* process chars from loopback */ |
| 183 |
int loop_frame(unsigned char *, int); /* should we bring link up? */ |
| 184 |
|