26_all_pppd-usepeerwins.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. --- ppp-2.4.6/pppd/ipcp.c
  2. +++ ppp-2.4.6/pppd/ipcp.c
  3. @@ -91,6 +91,7 @@
  4. static int default_route_set[NUM_PPP]; /* Have set up a default route */
  5. static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
  6. static bool usepeerdns; /* Ask peer for DNS addrs */
  7. +static bool usepeerwins; /* Ask peer for WINS addrs */
  8. static int ipcp_is_up; /* have called np_up() */
  9. static int ipcp_is_open; /* haven't called np_finished() */
  10. static bool ask_for_local; /* request our address from peer */
  11. @@ -210,6 +211,9 @@
  12. { "usepeerdns", o_bool, &usepeerdns,
  13. "Ask peer for DNS address(es)", 1 },
  14. + { "usepeerwins", o_bool, &usepeerwins,
  15. + "Ask peer for WINS address(es)", 1 },
  16. +
  17. { "netmask", o_special, (void *)setnetmask,
  18. "set netmask", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, netmask_str },
  19. @@ -703,6 +707,8 @@
  20. wo->accept_remote = 1;
  21. wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
  22. wo->req_dns2 = usepeerdns;
  23. + wo->req_wins1 = usepeerwins; /* Request WINS addresses from the peer */
  24. + wo->req_wins2 = usepeerwins;
  25. *go = *wo;
  26. if (!ask_for_local)
  27. go->ouraddr = 0;
  28. @@ -755,8 +761,8 @@
  29. LENCIADDR(go->neg_addr) +
  30. LENCIDNS(go->req_dns1) +
  31. LENCIDNS(go->req_dns2) +
  32. - LENCIWINS(go->winsaddr[0]) +
  33. - LENCIWINS(go->winsaddr[1])) ;
  34. + LENCIWINS(go->req_wins1) +
  35. + LENCIWINS(go->req_wins2)) ;
  36. }
  37. @@ -830,8 +836,8 @@
  38. neg = 0; \
  39. }
  40. -#define ADDCIWINS(opt, addr) \
  41. - if (addr) { \
  42. +#define ADDCIWINS(opt, neg, addr) \
  43. + if (neg) { \
  44. if (len >= CILEN_ADDR) { \
  45. u_int32_t l; \
  46. PUTCHAR(opt, ucp); \
  47. @@ -840,7 +846,7 @@
  48. PUTLONG(l, ucp); \
  49. len -= CILEN_ADDR; \
  50. } else \
  51. - addr = 0; \
  52. + neg = 0; \
  53. }
  54. ADDCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
  55. @@ -855,9 +861,9 @@
  56. ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
  57. - ADDCIWINS(CI_MS_WINS1, go->winsaddr[0]);
  58. + ADDCIWINS(CI_MS_WINS1, go->req_wins1, go->winsaddr[0]);
  59. - ADDCIWINS(CI_MS_WINS2, go->winsaddr[1]);
  60. + ADDCIWINS(CI_MS_WINS2, go->req_wins2, go->winsaddr[1]);
  61. *lenp -= len;
  62. }
  63. @@ -962,8 +968,8 @@
  64. goto bad; \
  65. }
  66. -#define ACKCIWINS(opt, addr) \
  67. - if (addr) { \
  68. +#define ACKCIWINS(opt, neg, addr) \
  69. + if (neg) { \
  70. u_int32_t l; \
  71. if ((len -= CILEN_ADDR) < 0) \
  72. goto bad; \
  73. @@ -989,9 +995,9 @@
  74. ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
  75. - ACKCIWINS(CI_MS_WINS1, go->winsaddr[0]);
  76. + ACKCIWINS(CI_MS_WINS1, go->req_wins1, go->winsaddr[0]);
  77. - ACKCIWINS(CI_MS_WINS2, go->winsaddr[1]);
  78. + ACKCIWINS(CI_MS_WINS2, go->req_wins2, go->winsaddr[1]);
  79. /*
  80. * If there are any remaining CIs, then this packet is bad.
  81. @@ -1026,7 +1032,7 @@
  82. u_char cimaxslotindex, cicflag;
  83. u_char citype, cilen, *next;
  84. u_short cishort;
  85. - u_int32_t ciaddr1, ciaddr2, l, cidnsaddr;
  86. + u_int32_t ciaddr1, ciaddr2, l, cidnsaddr, ciwinsaddr;
  87. ipcp_options no; /* options we've seen Naks for */
  88. ipcp_options try; /* options to request next time */
  89. @@ -1091,6 +1097,19 @@
  90. code \
  91. }
  92. +#define NAKCIWINS(opt, neg, code) \
  93. + if (go->neg && \
  94. + ((cilen = p[1]) == CILEN_ADDR) && \
  95. + len >= cilen && \
  96. + p[0] == opt) { \
  97. + len -= cilen; \
  98. + INCPTR(2, p); \
  99. + GETLONG(l, p); \
  100. + ciwinsaddr = htonl(l); \
  101. + no.neg = 1; \
  102. + code \
  103. + }
  104. +
  105. /*
  106. * Accept the peer's idea of {our,his} address, if different
  107. * from our idea, only if the accept_{local,remote} flag is set.
  108. @@ -1167,6 +1186,22 @@
  109. }
  110. );
  111. + NAKCIWINS(CI_MS_WINS1, req_wins1,
  112. + if (treat_as_reject) {
  113. + try.req_wins1 = 0;
  114. + } else {
  115. + try.winsaddr[0] = ciwinsaddr;
  116. + }
  117. + );
  118. +
  119. + NAKCIWINS(CI_MS_WINS2, req_wins2,
  120. + if (treat_as_reject) {
  121. + try.req_wins2 = 0;
  122. + } else {
  123. + try.winsaddr[1] = ciwinsaddr;
  124. + }
  125. + );
  126. +
  127. /*
  128. * There may be remaining CIs, if the peer is requesting negotiation
  129. * on an option that we didn't include in our request packet.
  130. @@ -1259,7 +1294,6 @@
  131. return 0;
  132. }
  133. -
  134. /*
  135. * ipcp_rejci - Reject some of our CIs.
  136. * Callback from fsm_rconfnakrej.
  137. @@ -1357,8 +1391,8 @@
  138. try.neg = 0; \
  139. }
  140. -#define REJCIWINS(opt, addr) \
  141. - if (addr && \
  142. +#define REJCIWINS(opt, neg, addr) \
  143. + if (go->neg && \
  144. ((cilen = p[1]) == CILEN_ADDR) && \
  145. len >= cilen && \
  146. p[0] == opt) { \
  147. @@ -1370,7 +1404,7 @@
  148. /* Check rejected value. */ \
  149. if (cilong != addr) \
  150. goto bad; \
  151. - try.winsaddr[opt == CI_MS_WINS2] = 0; \
  152. + try.neg = 0; \
  153. }
  154. REJCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
  155. @@ -1385,9 +1419,9 @@
  156. REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
  157. - REJCIWINS(CI_MS_WINS1, go->winsaddr[0]);
  158. + REJCIWINS(CI_MS_WINS1, req_wins1, go->winsaddr[0]);
  159. - REJCIWINS(CI_MS_WINS2, go->winsaddr[1]);
  160. + REJCIWINS(CI_MS_WINS2, req_wins2, go->winsaddr[1]);
  161. /*
  162. * If there are any remaining CIs, then this packet is bad.
  163. @@ -1581,7 +1615,7 @@
  164. /* Microsoft primary or secondary WINS request */
  165. d = citype == CI_MS_WINS2;
  166. - /* If we do not have a DNS address then we cannot send it */
  167. + /* If we do not have a WINS address then we cannot send it */
  168. if (ao->winsaddr[d] == 0 ||
  169. cilen != CILEN_ADDR) { /* Check CI length */
  170. orc = CONFREJ; /* Reject CI */
  171. @@ -1830,6 +1864,13 @@
  172. create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
  173. }
  174. + if (go->winsaddr[0])
  175. + script_setenv("WINS1", ip_ntoa(go->winsaddr[0]), 0);
  176. + if (go->winsaddr[1])
  177. + script_setenv("WINS2", ip_ntoa(go->winsaddr[1]), 0);
  178. + if (usepeerwins && (go->winsaddr[0] || go->winsaddr[1]))
  179. + script_setenv("USEPEERWINS", "1", 0);
  180. +
  181. /*
  182. * Check that the peer is allowed to use the IP address it wants.
  183. */
  184. --- ppp-2.4.6/pppd/ipcp.h
  185. +++ ppp-2.4.6/pppd/ipcp.h
  186. @@ -77,6 +77,8 @@
  187. bool accept_remote; /* accept peer's value for hisaddr */
  188. bool req_dns1; /* Ask peer to send primary DNS address? */
  189. bool req_dns2; /* Ask peer to send secondary DNS address? */
  190. + bool req_wins1; /* Ask peer to send primary WINS address? */
  191. + bool req_wins2; /* Ask peer to send secondary WINS address? */
  192. int vj_protocol; /* protocol value to use in VJ option */
  193. int maxslotindex; /* values for RFC1332 VJ compression neg. */
  194. bool cflag;
  195. --- ppp-2.4.6/pppd/pppd.8
  196. +++ ppp-2.4.6/pppd/pppd.8
  197. @@ -1102,6 +1102,16 @@
  198. /etc/ppp/resolv.conf file containing one or two nameserver lines with
  199. the address(es) supplied by the peer.
  200. .TP
  201. +.B usepeerwins
  202. +Ask the peer for up to 2 WINS server addresses. The addresses supplied
  203. +by the peer (if any) are passed to the /etc/ppp/ip\-up script in the
  204. +environment variables WINS1 and WINS2, and the environment variable
  205. +USEPEERWINS will be set to 1.
  206. +.LP
  207. +Please note that some modems (like the Huawei E220) requires this option in
  208. +order to avoid a race condition that results in the incorrect DNS servers
  209. +being assigned.
  210. +.TP
  211. .B user \fIname
  212. Sets the name used for authenticating the local system to the peer to
  213. \fIname\fR.
  214. @@ -1650,6 +1660,15 @@
  215. If the peer supplies DNS server addresses, this variable is set to the
  216. second DNS server address supplied (whether or not the usepeerdns
  217. option was given).
  218. +.TP
  219. +.B WINS1
  220. +If the peer supplies WINS server addresses, this variable is set to the
  221. +first WINS server address supplied.
  222. +.TP
  223. +.B WINS2
  224. +If the peer supplies WINS server addresses, this variable is set to the
  225. +second WINS server address supplied.
  226. +.P
  227. .P
  228. Pppd invokes the following scripts, if they exist. It is not an error
  229. if they don't exist.