1
0

patch-pppd_ccp_c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. --- ppp-2.4.4.orig/pppd/ccp.c 2005-07-09 02:23:05.000000000 +0200
  2. +++ ppp-2.4.4/pppd/ccp.c 2009-06-05 19:12:00.000000000 +0200
  3. @@ -62,12 +62,10 @@ static int setdeflate __P((char **));
  4. static char bsd_value[8];
  5. static char deflate_value[8];
  6. -/*
  7. - * Option variables.
  8. - */
  9. #ifdef MPPE
  10. -bool refuse_mppe_stateful = 1; /* Allow stateful mode? */
  11. -#endif
  12. +static int setmppe(char **);
  13. +static int setnomppe(void);
  14. +#endif /* MPPE */
  15. static option_t ccp_option_list[] = {
  16. { "noccp", o_bool, &ccp_protent.enabled_flag,
  17. @@ -108,54 +106,36 @@ static option_t ccp_option_list[] = {
  18. "don't allow Predictor-1", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
  19. &ccp_allowoptions[0].predictor_1 },
  20. -#ifdef MPPE
  21. - /* MPPE options are symmetrical ... we only set wantoptions here */
  22. - { "require-mppe", o_bool, &ccp_wantoptions[0].mppe,
  23. - "require MPPE encryption",
  24. - OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
  25. - { "+mppe", o_bool, &ccp_wantoptions[0].mppe,
  26. - "require MPPE encryption",
  27. - OPT_ALIAS | OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
  28. - { "nomppe", o_bool, &ccp_wantoptions[0].mppe,
  29. - "don't allow MPPE encryption", OPT_PRIO },
  30. - { "-mppe", o_bool, &ccp_wantoptions[0].mppe,
  31. - "don't allow MPPE encryption", OPT_ALIAS | OPT_PRIO },
  32. -
  33. - /* We use ccp_allowoptions[0].mppe as a junk var ... it is reset later */
  34. - { "require-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
  35. - "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
  36. - &ccp_wantoptions[0].mppe },
  37. - { "+mppe-40", o_bool, &ccp_allowoptions[0].mppe,
  38. - "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
  39. - &ccp_wantoptions[0].mppe },
  40. - { "nomppe-40", o_bool, &ccp_allowoptions[0].mppe,
  41. - "don't allow MPPE 40-bit encryption",
  42. - OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40, &ccp_wantoptions[0].mppe },
  43. - { "-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
  44. - "don't allow MPPE 40-bit encryption",
  45. - OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40,
  46. - &ccp_wantoptions[0].mppe },
  47. -
  48. - { "require-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
  49. - "require MPPE 128-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
  50. - &ccp_wantoptions[0].mppe },
  51. - { "+mppe-128", o_bool, &ccp_allowoptions[0].mppe,
  52. - "require MPPE 128-bit encryption",
  53. - OPT_ALIAS | OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
  54. - &ccp_wantoptions[0].mppe },
  55. - { "nomppe-128", o_bool, &ccp_allowoptions[0].mppe,
  56. - "don't allow MPPE 128-bit encryption",
  57. - OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128, &ccp_wantoptions[0].mppe },
  58. - { "-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
  59. - "don't allow MPPE 128-bit encryption",
  60. - OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128,
  61. - &ccp_wantoptions[0].mppe },
  62. + { "lzs", o_bool, &ccp_wantoptions[0].lzs,
  63. + "request Stac LZS", 1, &ccp_allowoptions[0].lzs, OPT_PRIO },
  64. + { "+lzs", o_bool, &ccp_wantoptions[0].lzs,
  65. + "request Stac LZS", 1, &ccp_allowoptions[0].lzs, OPT_ALIAS | OPT_PRIO },
  66. + { "nolzs", o_bool, &ccp_wantoptions[0].lzs,
  67. + "don't allow Stac LZS", OPT_PRIOSUB | OPT_A2CLR,
  68. + &ccp_allowoptions[0].lzs },
  69. + { "-lzs", o_bool, &ccp_wantoptions[0].lzs,
  70. + "don't allow Stac LZS", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
  71. + &ccp_allowoptions[0].lzs },
  72. - /* strange one; we always request stateless, but will we allow stateful? */
  73. - { "mppe-stateful", o_bool, &refuse_mppe_stateful,
  74. - "allow MPPE stateful mode", OPT_PRIO },
  75. - { "nomppe-stateful", o_bool, &refuse_mppe_stateful,
  76. - "disallow MPPE stateful mode", OPT_PRIO | 1 },
  77. +#ifdef MPPE
  78. + { "mppc", o_bool, &ccp_wantoptions[0].mppc,
  79. + "request MPPC compression", 1, &ccp_allowoptions[0].mppc },
  80. + { "+mppc", o_bool, &ccp_wantoptions[0].mppc,
  81. + "request MPPC compression", 1, &ccp_allowoptions[0].mppc, OPT_ALIAS },
  82. + { "nomppc", o_bool, &ccp_wantoptions[0].mppc,
  83. + "don't allow MPPC compression", OPT_PRIOSUB | OPT_A2CLR,
  84. + &ccp_allowoptions[0].mppc },
  85. + { "-mppc", o_bool, &ccp_wantoptions[0].mppc,
  86. + "don't allow MPPC compression", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
  87. + &ccp_allowoptions[0].mppc },
  88. + { "mppe", o_special, (void *)setmppe,
  89. + "request MPPE encryption" },
  90. + { "+mppe", o_special, (void *)setmppe,
  91. + "request MPPE encryption" },
  92. + { "nomppe", o_special_noarg, (void *)setnomppe,
  93. + "don't allow MPPE encryption" },
  94. + { "-mppe", o_special_noarg, (void *)setnomppe,
  95. + "don't allow MPPE encryption" },
  96. #endif /* MPPE */
  97. { NULL }
  98. @@ -241,7 +221,7 @@ static fsm_callbacks ccp_callbacks = {
  99. */
  100. #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
  101. || (opt).predictor_1 || (opt).predictor_2 \
  102. - || (opt).mppe)
  103. + || (opt).lzs || (opt).mppc || (opt).mppe)
  104. /*
  105. * Local state (mainly for handling reset-reqs and reset-acks).
  106. @@ -344,6 +324,100 @@ setdeflate(argv)
  107. return 1;
  108. }
  109. +#ifdef MPPE
  110. +/*
  111. + * Functions called from config options
  112. + */
  113. +/*
  114. + MPPE suboptions:
  115. + required - require MPPE; disconnect if peer doesn't support it
  116. + stateless - use stateless mode
  117. + no40 - disable 40 bit keys
  118. + no56 - disable 56 bit keys
  119. + no128 - disable 128 bit keys
  120. +*/
  121. +int setmppe(char **argv)
  122. +{
  123. + int i;
  124. + char *str, cmdbuf[16];
  125. +
  126. + ccp_allowoptions[0].mppe = 1;
  127. + ccp_allowoptions[0].mppe_40 = 1;
  128. + ccp_allowoptions[0].mppe_56 = 1;
  129. + ccp_allowoptions[0].mppe_128 = 1;
  130. + ccp_allowoptions[0].mppe_stateless = 0;
  131. + ccp_wantoptions[0].mppe = 0;
  132. +
  133. + str = *argv;
  134. +
  135. + while (1) {
  136. + i = 0;
  137. + memset(cmdbuf, '\0', 16);
  138. + while ((i < 16) && (*str != ',') && (*str != '\0'))
  139. + cmdbuf[i++] = *str++;
  140. + cmdbuf[i] = '\0';
  141. + if (!strncasecmp(cmdbuf, "no40", strlen("no40"))) {
  142. + ccp_allowoptions[0].mppe_40 = 0;
  143. + goto next_param;
  144. + } else if (!strncasecmp(cmdbuf, "no56", strlen("no56"))) {
  145. + ccp_allowoptions[0].mppe_56 = 0;
  146. + goto next_param;
  147. + } else if (!strncasecmp(cmdbuf, "no128", strlen("no128"))) {
  148. + ccp_allowoptions[0].mppe_128 = 0;
  149. + goto next_param;
  150. + } else if (!strncasecmp(cmdbuf, "stateless", strlen("stateless"))) {
  151. + ccp_allowoptions[0].mppe_stateless = 1;
  152. + goto next_param;
  153. + } else if (!strncasecmp(cmdbuf, "required", strlen("required"))) {
  154. + ccp_wantoptions[0].mppe = 1;
  155. + goto next_param;
  156. + } else {
  157. + option_error("invalid parameter '%s' for mppe option", cmdbuf);
  158. + return 0;
  159. + }
  160. +
  161. + next_param:
  162. + if (*str == ',') {
  163. + str++;
  164. + continue;
  165. + }
  166. + if (*str == '\0') {
  167. + if (!(ccp_allowoptions[0].mppe_40 || ccp_allowoptions[0].mppe_56 ||
  168. + ccp_allowoptions[0].mppe_128)) {
  169. + if (ccp_wantoptions[0].mppe == 1) {
  170. + option_error("You require MPPE but you have switched off "
  171. + "all encryption key lengths.");
  172. + return 0;
  173. + }
  174. + ccp_wantoptions[0].mppe = ccp_allowoptions[0].mppe = 0;
  175. + ccp_wantoptions[0].mppe_stateless =
  176. + ccp_allowoptions[0].mppe_stateless = 0;
  177. + } else {
  178. + ccp_allowoptions[0].mppe = 1;
  179. + ccp_wantoptions[0].mppe_stateless =
  180. + ccp_allowoptions[0].mppe_stateless;
  181. + if (ccp_wantoptions[0].mppe == 1) {
  182. + ccp_wantoptions[0].mppe_40 = ccp_allowoptions[0].mppe_40;
  183. + ccp_wantoptions[0].mppe_56 = ccp_allowoptions[0].mppe_56;
  184. + ccp_wantoptions[0].mppe_128 = ccp_allowoptions[0].mppe_128;
  185. + }
  186. + }
  187. + return 1;
  188. + }
  189. + }
  190. +}
  191. +
  192. +int setnomppe(void)
  193. +{
  194. + ccp_wantoptions[0].mppe = ccp_allowoptions[0].mppe = 0;
  195. + ccp_wantoptions[0].mppe_40 = ccp_allowoptions[0].mppe_40 = 0;
  196. + ccp_wantoptions[0].mppe_56 = ccp_allowoptions[0].mppe_56 = 0;
  197. + ccp_wantoptions[0].mppe_128 = ccp_allowoptions[0].mppe_128 = 0;
  198. + ccp_wantoptions[0].mppe_stateless = ccp_allowoptions[0].mppe_stateless = 0;
  199. + return 1;
  200. +}
  201. +#endif /* MPPE */
  202. +
  203. /*
  204. * ccp_init - initialize CCP.
  205. */
  206. @@ -378,6 +452,30 @@ ccp_init(unit)
  207. ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
  208. ccp_allowoptions[0].predictor_1 = 1;
  209. +
  210. + ccp_wantoptions[0].lzs = 0; /* Stac LZS - will be enabled in the future */
  211. + ccp_wantoptions[0].lzs_mode = LZS_MODE_SEQ;
  212. + ccp_wantoptions[0].lzs_hists = 1;
  213. + ccp_allowoptions[0].lzs = 0; /* Stac LZS - will be enabled in the future */
  214. + ccp_allowoptions[0].lzs_mode = LZS_MODE_SEQ;
  215. + ccp_allowoptions[0].lzs_hists = 1;
  216. +
  217. +#ifdef MPPE
  218. + /* by default allow and request MPPC... */
  219. + ccp_wantoptions[0].mppc = ccp_allowoptions[0].mppc = 1;
  220. +
  221. + /* ... and allow but don't request MPPE */
  222. + ccp_allowoptions[0].mppe = 1;
  223. + ccp_allowoptions[0].mppe_40 = 1;
  224. + ccp_allowoptions[0].mppe_56 = 1;
  225. + ccp_allowoptions[0].mppe_128 = 1;
  226. + ccp_allowoptions[0].mppe_stateless = 1;
  227. + ccp_wantoptions[0].mppe = 0;
  228. + ccp_wantoptions[0].mppe_40 = 0;
  229. + ccp_wantoptions[0].mppe_56 = 0;
  230. + ccp_wantoptions[0].mppe_128 = 0;
  231. + ccp_wantoptions[0].mppe_stateless = 0;
  232. +#endif /* MPPE */
  233. }
  234. /*
  235. @@ -455,11 +553,11 @@ ccp_input(unit, p, len)
  236. if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED) {
  237. notice("Compression disabled by peer.");
  238. #ifdef MPPE
  239. - if (ccp_gotoptions[unit].mppe) {
  240. + if (ccp_wantoptions[unit].mppe) {
  241. error("MPPE disabled, closing LCP");
  242. lcp_close(unit, "MPPE disabled by peer");
  243. }
  244. -#endif
  245. +#endif /* MPPE */
  246. }
  247. /*
  248. @@ -487,6 +585,15 @@ ccp_extcode(f, code, id, p, len)
  249. break;
  250. /* send a reset-ack, which the transmitter will see and
  251. reset its compression state. */
  252. +
  253. + /* In case of MPPE/MPPC or LZS we shouldn't send CCP_RESETACK,
  254. + but we do it in order to reset compressor; CCP_RESETACK is
  255. + then silently discarded. See functions ppp_send_frame and
  256. + ppp_ccp_peek in ppp_generic.c (Linux only !!!). All the
  257. + confusion is caused by the fact that CCP code is splited
  258. + into two parts - one part is handled by pppd, the other one
  259. + is handled by kernel. */
  260. +
  261. fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
  262. break;
  263. @@ -515,12 +622,11 @@ ccp_protrej(unit)
  264. fsm_lowerdown(&ccp_fsm[unit]);
  265. #ifdef MPPE
  266. - if (ccp_gotoptions[unit].mppe) {
  267. + if (ccp_wantoptions[unit].mppe) {
  268. error("MPPE required but peer negotiation failed");
  269. lcp_close(unit, "MPPE required but peer negotiation failed");
  270. }
  271. -#endif
  272. -
  273. +#endif /* MPPE */
  274. }
  275. /*
  276. @@ -537,7 +643,7 @@ ccp_resetci(f)
  277. all_rejected[f->unit] = 0;
  278. #ifdef MPPE
  279. - if (go->mppe) {
  280. + if (go->mppe || go->mppc) {
  281. ccp_options *ao = &ccp_allowoptions[f->unit];
  282. int auth_mschap_bits = auth_done[f->unit];
  283. int numbits;
  284. @@ -551,80 +657,109 @@ ccp_resetci(f)
  285. * NB: If MPPE is required, all other compression opts are invalid.
  286. * So, we return right away if we can't do it.
  287. */
  288. + if (ccp_wantoptions[f->unit].mppe) {
  289. + /* Leave only the mschap auth bits set */
  290. + auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
  291. + CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
  292. + /* Count the mschap auths */
  293. + auth_mschap_bits >>= CHAP_MS_SHIFT;
  294. + numbits = 0;
  295. + do {
  296. + numbits += auth_mschap_bits & 1;
  297. + auth_mschap_bits >>= 1;
  298. + } while (auth_mschap_bits);
  299. + if (numbits > 1) {
  300. + error("MPPE required, but auth done in both directions.");
  301. + lcp_close(f->unit, "MPPE required but not available");
  302. + return;
  303. + }
  304. + if (!numbits) {
  305. + error("MPPE required, but MS-CHAP[v2] auth not performed.");
  306. + lcp_close(f->unit, "MPPE required but not available");
  307. + return;
  308. + }
  309. - /* Leave only the mschap auth bits set */
  310. - auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
  311. - CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
  312. - /* Count the mschap auths */
  313. - auth_mschap_bits >>= CHAP_MS_SHIFT;
  314. - numbits = 0;
  315. - do {
  316. - numbits += auth_mschap_bits & 1;
  317. - auth_mschap_bits >>= 1;
  318. - } while (auth_mschap_bits);
  319. - if (numbits > 1) {
  320. - error("MPPE required, but auth done in both directions.");
  321. - lcp_close(f->unit, "MPPE required but not available");
  322. - return;
  323. - }
  324. - if (!numbits) {
  325. - error("MPPE required, but MS-CHAP[v2] auth not performed.");
  326. - lcp_close(f->unit, "MPPE required but not available");
  327. - return;
  328. + /* A plugin (eg radius) may not have obtained key material. */
  329. + if (!mppe_keys_set) {
  330. + error("MPPE required, but keys are not available. "
  331. + "Possible plugin problem?");
  332. + lcp_close(f->unit, "MPPE required but not available");
  333. + return;
  334. + }
  335. }
  336. - /* A plugin (eg radius) may not have obtained key material. */
  337. - if (!mppe_keys_set) {
  338. - error("MPPE required, but keys are not available. "
  339. - "Possible plugin problem?");
  340. - lcp_close(f->unit, "MPPE required but not available");
  341. - return;
  342. + /*
  343. + * Check whether the kernel knows about the various
  344. + * compression methods we might request. Key material
  345. + * unimportant here.
  346. + */
  347. + if (go->mppc) {
  348. + opt_buf[0] = CI_MPPE;
  349. + opt_buf[1] = CILEN_MPPE;
  350. + opt_buf[2] = 0;
  351. + opt_buf[3] = 0;
  352. + opt_buf[4] = 0;
  353. + opt_buf[5] = MPPE_MPPC;
  354. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE, 0) <= 0)
  355. + go->mppc = 0;
  356. }
  357. -
  358. - /* LM auth not supported for MPPE */
  359. - if (auth_done[f->unit] & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) {
  360. - /* This might be noise */
  361. - if (go->mppe & MPPE_OPT_40) {
  362. - notice("Disabling 40-bit MPPE; MS-CHAP LM not supported");
  363. - go->mppe &= ~MPPE_OPT_40;
  364. - ccp_wantoptions[f->unit].mppe &= ~MPPE_OPT_40;
  365. - }
  366. + if (go->mppe_40) {
  367. + opt_buf[0] = CI_MPPE;
  368. + opt_buf[1] = CILEN_MPPE;
  369. + opt_buf[2] = MPPE_STATELESS;
  370. + opt_buf[3] = 0;
  371. + opt_buf[4] = 0;
  372. + opt_buf[5] = MPPE_40BIT;
  373. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0)
  374. + go->mppe_40 = 0;
  375. }
  376. -
  377. - /* Last check: can we actually negotiate something? */
  378. - if (!(go->mppe & (MPPE_OPT_40 | MPPE_OPT_128))) {
  379. - /* Could be misconfig, could be 40-bit disabled above. */
  380. - error("MPPE required, but both 40-bit and 128-bit disabled.");
  381. - lcp_close(f->unit, "MPPE required but not available");
  382. - return;
  383. + if (go->mppe_56) {
  384. + opt_buf[0] = CI_MPPE;
  385. + opt_buf[1] = CILEN_MPPE;
  386. + opt_buf[2] = MPPE_STATELESS;
  387. + opt_buf[3] = 0;
  388. + opt_buf[4] = 0;
  389. + opt_buf[5] = MPPE_56BIT;
  390. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0)
  391. + go->mppe_56 = 0;
  392. + }
  393. + if (go->mppe_128) {
  394. + opt_buf[0] = CI_MPPE;
  395. + opt_buf[1] = CILEN_MPPE;
  396. + opt_buf[2] = MPPE_STATELESS;
  397. + opt_buf[3] = 0;
  398. + opt_buf[4] = 0;
  399. + opt_buf[5] = MPPE_128BIT;
  400. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0)
  401. + go->mppe_128 = 0;
  402. + }
  403. + if (!go->mppe_40 && !go->mppe_56 && !go->mppe_128) {
  404. + if (ccp_wantoptions[f->unit].mppe) {
  405. + error("MPPE required, but kernel has no support.");
  406. + lcp_close(f->unit, "MPPE required but not available");
  407. + }
  408. + go->mppe = go->mppe_stateless = 0;
  409. + } else {
  410. + /* MPPE is not compatible with other compression types */
  411. + if (ccp_wantoptions[f->unit].mppe) {
  412. + ao->bsd_compress = go->bsd_compress = 0;
  413. + ao->predictor_1 = go->predictor_1 = 0;
  414. + ao->predictor_2 = go->predictor_2 = 0;
  415. + ao->deflate = go->deflate = 0;
  416. + ao->lzs = go->lzs = 0;
  417. + }
  418. }
  419. -
  420. - /* sync options */
  421. - ao->mppe = go->mppe;
  422. - /* MPPE is not compatible with other compression types */
  423. - ao->bsd_compress = go->bsd_compress = 0;
  424. - ao->predictor_1 = go->predictor_1 = 0;
  425. - ao->predictor_2 = go->predictor_2 = 0;
  426. - ao->deflate = go->deflate = 0;
  427. }
  428. #endif /* MPPE */
  429. -
  430. - /*
  431. - * Check whether the kernel knows about the various
  432. - * compression methods we might request.
  433. - */
  434. -#ifdef MPPE
  435. - if (go->mppe) {
  436. - opt_buf[0] = CI_MPPE;
  437. - opt_buf[1] = CILEN_MPPE;
  438. - MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
  439. - /* Key material unimportant here. */
  440. - if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0) {
  441. - error("MPPE required, but kernel has no support.");
  442. - lcp_close(f->unit, "MPPE required but not available");
  443. - }
  444. + if (go->lzs) {
  445. + opt_buf[0] = CI_LZS;
  446. + opt_buf[1] = CILEN_LZS;
  447. + opt_buf[2] = go->lzs_hists >> 8;
  448. + opt_buf[3] = go->lzs_hists & 0xff;
  449. + opt_buf[4] = LZS_MODE_SEQ;
  450. + if (ccp_test(f->unit, opt_buf, CILEN_LZS, 0) <= 0)
  451. + go->lzs = 0;
  452. }
  453. -#endif
  454. if (go->bsd_compress) {
  455. opt_buf[0] = CI_BSD_COMPRESS;
  456. opt_buf[1] = CILEN_BSD_COMPRESS;
  457. @@ -679,7 +814,8 @@ ccp_cilen(f)
  458. + (go->deflate? CILEN_DEFLATE: 0)
  459. + (go->predictor_1? CILEN_PREDICTOR_1: 0)
  460. + (go->predictor_2? CILEN_PREDICTOR_2: 0)
  461. - + (go->mppe? CILEN_MPPE: 0);
  462. + + (go->lzs? CILEN_LZS: 0)
  463. + + ((go->mppe || go->mppc)? CILEN_MPPE: 0);
  464. }
  465. /*
  466. @@ -693,6 +829,8 @@ ccp_addci(f, p, lenp)
  467. {
  468. int res;
  469. ccp_options *go = &ccp_gotoptions[f->unit];
  470. + ccp_options *ao = &ccp_allowoptions[f->unit];
  471. + ccp_options *wo = &ccp_wantoptions[f->unit];
  472. u_char *p0 = p;
  473. /*
  474. @@ -701,22 +839,43 @@ ccp_addci(f, p, lenp)
  475. * in case it gets Acked.
  476. */
  477. #ifdef MPPE
  478. - if (go->mppe) {
  479. + if (go->mppe || go->mppc || (!wo->mppe && ao->mppe)) {
  480. u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
  481. - p[0] = opt_buf[0] = CI_MPPE;
  482. - p[1] = opt_buf[1] = CILEN_MPPE;
  483. - MPPE_OPTS_TO_CI(go->mppe, &p[2]);
  484. - MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
  485. + p[0] = CI_MPPE;
  486. + p[1] = CILEN_MPPE;
  487. + p[2] = (go->mppe_stateless ? MPPE_STATELESS : 0);
  488. + p[3] = 0;
  489. + p[4] = 0;
  490. + p[5] = (go->mppe_40 ? MPPE_40BIT : 0) | (go->mppe_56 ? MPPE_56BIT : 0) |
  491. + (go->mppe_128 ? MPPE_128BIT : 0) | (go->mppc ? MPPE_MPPC : 0);
  492. +
  493. + BCOPY(p, opt_buf, CILEN_MPPE);
  494. BCOPY(mppe_recv_key, &opt_buf[CILEN_MPPE], MPPE_MAX_KEY_LEN);
  495. res = ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0);
  496. - if (res > 0)
  497. + if (res > 0) {
  498. p += CILEN_MPPE;
  499. - else
  500. + } else {
  501. /* This shouldn't happen, we've already tested it! */
  502. - lcp_close(f->unit, "MPPE required but not available in kernel");
  503. + go->mppe = go->mppe_40 = go->mppe_56 = go->mppe_128 =
  504. + go->mppe_stateless = go->mppc = 0;
  505. + if (ccp_wantoptions[f->unit].mppe)
  506. + lcp_close(f->unit, "MPPE required but not available in kernel");
  507. + }
  508. + }
  509. +#endif /* MPPE */
  510. + if (go->lzs) {
  511. + p[0] = CI_LZS;
  512. + p[1] = CILEN_LZS;
  513. + p[2] = go->lzs_hists >> 8;
  514. + p[3] = go->lzs_hists & 0xff;
  515. + p[4] = LZS_MODE_SEQ;
  516. + res = ccp_test(f->unit, p, CILEN_LZS, 0);
  517. + if (res > 0) {
  518. + p += CILEN_LZS;
  519. + } else
  520. + go->lzs = 0;
  521. }
  522. -#endif
  523. if (go->deflate) {
  524. p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
  525. p[1] = CILEN_DEFLATE;
  526. @@ -802,7 +961,7 @@ ccp_addci(f, p, lenp)
  527. /*
  528. * ccp_ackci - process a received configure-ack, and return
  529. - * 1 iff the packet was OK.
  530. + * 1 if the packet was OK.
  531. */
  532. static int
  533. ccp_ackci(f, p, len)
  534. @@ -811,24 +970,44 @@ ccp_ackci(f, p, len)
  535. int len;
  536. {
  537. ccp_options *go = &ccp_gotoptions[f->unit];
  538. + ccp_options *ao = &ccp_allowoptions[f->unit];
  539. + ccp_options *wo = &ccp_wantoptions[f->unit];
  540. u_char *p0 = p;
  541. #ifdef MPPE
  542. - if (go->mppe) {
  543. - u_char opt_buf[CILEN_MPPE];
  544. -
  545. - opt_buf[0] = CI_MPPE;
  546. - opt_buf[1] = CILEN_MPPE;
  547. - MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
  548. - if (len < CILEN_MPPE || memcmp(opt_buf, p, CILEN_MPPE))
  549. + if (go->mppe || go->mppc || (!wo->mppe && ao->mppe)) {
  550. + if (len < CILEN_MPPE
  551. + || p[1] != CILEN_MPPE || p[0] != CI_MPPE
  552. + || p[2] != (go->mppe_stateless ? MPPE_STATELESS : 0)
  553. + || p[3] != 0
  554. + || p[4] != 0
  555. + || (p[5] != ((go->mppe_40 ? MPPE_40BIT : 0) |
  556. + (go->mppc ? MPPE_MPPC : 0))
  557. + && p[5] != ((go->mppe_56 ? MPPE_56BIT : 0) |
  558. + (go->mppc ? MPPE_MPPC : 0))
  559. + && p[5] != ((go->mppe_128 ? MPPE_128BIT : 0) |
  560. + (go->mppc ? MPPE_MPPC : 0))))
  561. return 0;
  562. + if (go->mppe_40 || go->mppe_56 || go->mppe_128)
  563. + go->mppe = 1;
  564. p += CILEN_MPPE;
  565. len -= CILEN_MPPE;
  566. + /* Cope with first/fast ack */
  567. + if (p == p0 && len == 0)
  568. + return 1;
  569. + }
  570. +#endif /* MPPE */
  571. + if (go->lzs) {
  572. + if (len < CILEN_LZS || p[0] != CI_LZS || p[1] != CILEN_LZS
  573. + || p[2] != go->lzs_hists>>8 || p[3] != (go->lzs_hists&0xff)
  574. + || p[4] != LZS_MODE_SEQ)
  575. + return 0;
  576. + p += CILEN_LZS;
  577. + len -= CILEN_LZS;
  578. /* XXX Cope with first/fast ack */
  579. - if (len == 0)
  580. + if (p == p0 && len == 0)
  581. return 1;
  582. }
  583. -#endif
  584. if (go->deflate) {
  585. if (len < CILEN_DEFLATE
  586. || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
  587. @@ -891,7 +1070,7 @@ ccp_ackci(f, p, len)
  588. /*
  589. * ccp_nakci - process received configure-nak.
  590. - * Returns 1 iff the nak was OK.
  591. + * Returns 1 if the nak was OK.
  592. */
  593. static int
  594. ccp_nakci(f, p, len, treat_as_reject)
  595. @@ -901,6 +1080,8 @@ ccp_nakci(f, p, len, treat_as_reject)
  596. int treat_as_reject;
  597. {
  598. ccp_options *go = &ccp_gotoptions[f->unit];
  599. + ccp_options *ao = &ccp_allowoptions[f->unit];
  600. + ccp_options *wo = &ccp_wantoptions[f->unit];
  601. ccp_options no; /* options we've seen already */
  602. ccp_options try; /* options to ask for next time */
  603. @@ -908,28 +1089,100 @@ ccp_nakci(f, p, len, treat_as_reject)
  604. try = *go;
  605. #ifdef MPPE
  606. - if (go->mppe && len >= CILEN_MPPE
  607. - && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
  608. - no.mppe = 1;
  609. - /*
  610. - * Peer wants us to use a different strength or other setting.
  611. - * Fail if we aren't willing to use his suggestion.
  612. - */
  613. - MPPE_CI_TO_OPTS(&p[2], try.mppe);
  614. - if ((try.mppe & MPPE_OPT_STATEFUL) && refuse_mppe_stateful) {
  615. - error("Refusing MPPE stateful mode offered by peer");
  616. - try.mppe = 0;
  617. - } else if (((go->mppe | MPPE_OPT_STATEFUL) & try.mppe) != try.mppe) {
  618. - /* Peer must have set options we didn't request (suggest) */
  619. - try.mppe = 0;
  620. + if ((go->mppe || go->mppc || (!wo->mppe && ao->mppe)) &&
  621. + len >= CILEN_MPPE && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
  622. +
  623. + if (go->mppc) {
  624. + no.mppc = 1;
  625. + if (!(p[5] & MPPE_MPPC))
  626. + try.mppc = 0;
  627. }
  628. - if (!try.mppe) {
  629. - error("MPPE required but peer negotiation failed");
  630. - lcp_close(f->unit, "MPPE required but peer negotiation failed");
  631. + if (go->mppe)
  632. + no.mppe = 1;
  633. + if (go->mppe_40)
  634. + no.mppe_40 = 1;
  635. + if (go->mppe_56)
  636. + no.mppe_56 = 1;
  637. + if (go->mppe_128)
  638. + no.mppe_128 = 1;
  639. + if (go->mppe_stateless)
  640. + no.mppe_stateless = 1;
  641. +
  642. + if (ao->mppe_40) {
  643. + if ((p[5] & MPPE_40BIT))
  644. + try.mppe_40 = 1;
  645. + else
  646. + try.mppe_40 = (p[5] == 0) ? 1 : 0;
  647. }
  648. + if (ao->mppe_56) {
  649. + if ((p[5] & MPPE_56BIT))
  650. + try.mppe_56 = 1;
  651. + else
  652. + try.mppe_56 = (p[5] == 0) ? 1 : 0;
  653. + }
  654. + if (ao->mppe_128) {
  655. + if ((p[5] & MPPE_128BIT))
  656. + try.mppe_128 = 1;
  657. + else
  658. + try.mppe_128 = (p[5] == 0) ? 1 : 0;
  659. + }
  660. +
  661. + if (ao->mppe_stateless) {
  662. + if ((p[2] & MPPE_STATELESS) || wo->mppe_stateless)
  663. + try.mppe_stateless = 1;
  664. + else
  665. + try.mppe_stateless = 0;
  666. + }
  667. +
  668. + if (!try.mppe_56 && !try.mppe_40 && !try.mppe_128) {
  669. + try.mppe = try.mppe_stateless = 0;
  670. + if (wo->mppe) {
  671. + /* we require encryption, but peer doesn't support it
  672. + so we close connection */
  673. + wo->mppc = wo->mppe = wo->mppe_stateless = wo->mppe_40 =
  674. + wo->mppe_56 = wo->mppe_128 = 0;
  675. + lcp_close(f->unit, "MPPE required but cannot negotiate MPPE "
  676. + "key length");
  677. + }
  678. + }
  679. + if (wo->mppe && (wo->mppe_40 != try.mppe_40) &&
  680. + (wo->mppe_56 != try.mppe_56) && (wo->mppe_128 != try.mppe_128)) {
  681. + /* cannot negotiate key length */
  682. + wo->mppc = wo->mppe = wo->mppe_stateless = wo->mppe_40 =
  683. + wo->mppe_56 = wo->mppe_128 = 0;
  684. + lcp_close(f->unit, "Cannot negotiate MPPE key length");
  685. + }
  686. + if (try.mppe_40 && try.mppe_56 && try.mppe_128)
  687. + try.mppe_40 = try.mppe_56 = 0;
  688. + else
  689. + if (try.mppe_56 && try.mppe_128)
  690. + try.mppe_56 = 0;
  691. + else
  692. + if (try.mppe_40 && try.mppe_128)
  693. + try.mppe_40 = 0;
  694. + else
  695. + if (try.mppe_40 && try.mppe_56)
  696. + try.mppe_40 = 0;
  697. +
  698. + p += CILEN_MPPE;
  699. + len -= CILEN_MPPE;
  700. }
  701. #endif /* MPPE */
  702. +
  703. + if (go->lzs && len >= CILEN_LZS && p[0] == CI_LZS && p[1] == CILEN_LZS) {
  704. + no.lzs = 1;
  705. + if (((p[2]<<8)|p[3]) > 1 || (p[4] != LZS_MODE_SEQ &&
  706. + p[4] != LZS_MODE_EXT))
  707. + try.lzs = 0;
  708. + else {
  709. + try.lzs_mode = p[4];
  710. + try.lzs_hists = (p[2] << 8) | p[3];
  711. + }
  712. + p += CILEN_LZS;
  713. + len -= CILEN_LZS;
  714. + }
  715. +
  716. if (go->deflate && len >= CILEN_DEFLATE
  717. && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
  718. && p[1] == CILEN_DEFLATE) {
  719. @@ -1002,14 +1255,50 @@ ccp_rejci(f, p, len)
  720. return -1;
  721. #ifdef MPPE
  722. - if (go->mppe && len >= CILEN_MPPE
  723. + if ((go->mppe || go->mppc) && len >= CILEN_MPPE
  724. && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
  725. - error("MPPE required but peer refused");
  726. - lcp_close(f->unit, "MPPE required but peer refused");
  727. + ccp_options *wo = &ccp_wantoptions[f->unit];
  728. + if (p[2] != (go->mppe_stateless ? MPPE_STATELESS : 0) ||
  729. + p[3] != 0 ||
  730. + p[4] != 0 ||
  731. + p[5] != ((go->mppe_40 ? MPPE_40BIT : 0) |
  732. + (go->mppe_56 ? MPPE_56BIT : 0) |
  733. + (go->mppe_128 ? MPPE_128BIT : 0) |
  734. + (go->mppc ? MPPE_MPPC : 0)))
  735. + return 0;
  736. + if (go->mppc)
  737. + try.mppc = 0;
  738. + if (go->mppe) {
  739. + try.mppe = 0;
  740. + if (go->mppe_40)
  741. + try.mppe_40 = 0;
  742. + if (go->mppe_56)
  743. + try.mppe_56 = 0;
  744. + if (go->mppe_128)
  745. + try.mppe_128 = 0;
  746. + if (go->mppe_stateless)
  747. + try.mppe_stateless = 0;
  748. + if (!try.mppe_56 && !try.mppe_40 && !try.mppe_128)
  749. + try.mppe = try.mppe_stateless = 0;
  750. + if (wo->mppe) { /* we want MPPE but cannot negotiate key length */
  751. + wo->mppc = wo->mppe = wo->mppe_stateless = wo->mppe_40 =
  752. + wo->mppe_56 = wo->mppe_128 = 0;
  753. + lcp_close(f->unit, "MPPE required but cannot negotiate MPPE "
  754. + "key length");
  755. + }
  756. + }
  757. p += CILEN_MPPE;
  758. len -= CILEN_MPPE;
  759. }
  760. -#endif
  761. +#endif /* MPPE */
  762. + if (go->lzs && len >= CILEN_LZS && p[0] == CI_LZS && p[1] == CILEN_LZS) {
  763. + if (p[2] != go->lzs_hists>>8 || p[3] != (go->lzs_hists&0xff)
  764. + || p[4] != go->lzs_mode)
  765. + return 0;
  766. + try.lzs = 0;
  767. + p += CILEN_LZS;
  768. + len -= CILEN_LZS;
  769. + }
  770. if (go->deflate_correct && len >= CILEN_DEFLATE
  771. && p[0] == CI_DEFLATE && p[1] == CILEN_DEFLATE) {
  772. if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
  773. @@ -1073,14 +1362,15 @@ ccp_reqci(f, p, lenp, dont_nak)
  774. int dont_nak;
  775. {
  776. int ret, newret, res;
  777. - u_char *p0, *retp;
  778. + u_char *p0, *retp, p2, p5;
  779. int len, clen, type, nb;
  780. ccp_options *ho = &ccp_hisoptions[f->unit];
  781. ccp_options *ao = &ccp_allowoptions[f->unit];
  782. + ccp_options *wo = &ccp_wantoptions[f->unit];
  783. #ifdef MPPE
  784. - bool rej_for_ci_mppe = 1; /* Are we rejecting based on a bad/missing */
  785. - /* CI_MPPE, or due to other options? */
  786. -#endif
  787. + u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
  788. +/* int mtu; */
  789. +#endif /* MPPE */
  790. ret = CONFACK;
  791. retp = p0 = p;
  792. @@ -1103,106 +1393,307 @@ ccp_reqci(f, p, lenp, dont_nak)
  793. switch (type) {
  794. #ifdef MPPE
  795. case CI_MPPE:
  796. - if (!ao->mppe || clen != CILEN_MPPE) {
  797. + if ((!ao->mppc && !ao->mppe) || clen != CILEN_MPPE) {
  798. newret = CONFREJ;
  799. break;
  800. }
  801. - MPPE_CI_TO_OPTS(&p[2], ho->mppe);
  802. - /* Nak if anything unsupported or unknown are set. */
  803. - if (ho->mppe & MPPE_OPT_UNSUPPORTED) {
  804. - newret = CONFNAK;
  805. - ho->mppe &= ~MPPE_OPT_UNSUPPORTED;
  806. - }
  807. - if (ho->mppe & MPPE_OPT_UNKNOWN) {
  808. + p2 = p[2];
  809. + p5 = p[5];
  810. + /* not sure what they want, tell 'em what we got */
  811. + if (((p[2] & ~MPPE_STATELESS) != 0 || p[3] != 0 || p[4] != 0 ||
  812. + (p[5] & ~(MPPE_40BIT | MPPE_56BIT | MPPE_128BIT |
  813. + MPPE_MPPC)) != 0 || p[5] == 0) ||
  814. + (p[2] == 0 && p[3] == 0 && p[4] == 0 && p[5] == 0)) {
  815. newret = CONFNAK;
  816. - ho->mppe &= ~MPPE_OPT_UNKNOWN;
  817. + p[2] = (wo->mppe_stateless ? MPPE_STATELESS : 0);
  818. + p[3] = 0;
  819. + p[4] = 0;
  820. + p[5] = (wo->mppe_40 ? MPPE_40BIT : 0) |
  821. + (wo->mppe_56 ? MPPE_56BIT : 0) |
  822. + (wo->mppe_128 ? MPPE_128BIT : 0) |
  823. + (wo->mppc ? MPPE_MPPC : 0);
  824. + break;
  825. }
  826. - /* Check state opt */
  827. - if (ho->mppe & MPPE_OPT_STATEFUL) {
  828. - /*
  829. - * We can Nak and request stateless, but it's a
  830. - * lot easier to just assume the peer will request
  831. - * it if he can do it; stateful mode is bad over
  832. - * the Internet -- which is where we expect MPPE.
  833. - */
  834. - if (refuse_mppe_stateful) {
  835. - error("Refusing MPPE stateful mode offered by peer");
  836. + if ((p[5] & MPPE_MPPC)) {
  837. + if (ao->mppc) {
  838. + ho->mppc = 1;
  839. + BCOPY(p, opt_buf, CILEN_MPPE);
  840. + opt_buf[2] = opt_buf[3] = opt_buf[4] = 0;
  841. + opt_buf[5] = MPPE_MPPC;
  842. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE, 1) <= 0) {
  843. + ho->mppc = 0;
  844. + p[5] &= ~MPPE_MPPC;
  845. + newret = CONFNAK;
  846. + }
  847. + } else {
  848. newret = CONFREJ;
  849. - break;
  850. + if (wo->mppe || ao->mppe) {
  851. + p[5] &= ~MPPE_MPPC;
  852. + newret = CONFNAK;
  853. + }
  854. }
  855. }
  856. - /* Find out which of {S,L} are set. */
  857. - if ((ho->mppe & MPPE_OPT_128)
  858. - && (ho->mppe & MPPE_OPT_40)) {
  859. - /* Both are set, negotiate the strongest. */
  860. + if (ao->mppe)
  861. + ho->mppe = 1;
  862. +
  863. + if ((p[2] & MPPE_STATELESS)) {
  864. + if (ao->mppe_stateless) {
  865. + if (wo->mppe_stateless)
  866. + ho->mppe_stateless = 1;
  867. + else {
  868. + newret = CONFNAK;
  869. + if (!dont_nak)
  870. + p[2] &= ~MPPE_STATELESS;
  871. + }
  872. + } else {
  873. + newret = CONFNAK;
  874. + if (!dont_nak)
  875. + p[2] &= ~MPPE_STATELESS;
  876. + }
  877. + } else {
  878. + if (wo->mppe_stateless && !dont_nak) {
  879. + wo->mppe_stateless = 0;
  880. + newret = CONFNAK;
  881. + p[2] |= MPPE_STATELESS;
  882. + }
  883. + }
  884. +
  885. + if ((p[5] & ~MPPE_MPPC) == (MPPE_40BIT|MPPE_56BIT|MPPE_128BIT)) {
  886. newret = CONFNAK;
  887. - if (ao->mppe & MPPE_OPT_128)
  888. - ho->mppe &= ~MPPE_OPT_40;
  889. - else if (ao->mppe & MPPE_OPT_40)
  890. - ho->mppe &= ~MPPE_OPT_128;
  891. - else {
  892. - newret = CONFREJ;
  893. - break;
  894. + if (ao->mppe_128) {
  895. + ho->mppe_128 = 1;
  896. + p[5] &= ~(MPPE_40BIT|MPPE_56BIT);
  897. + BCOPY(p, opt_buf, CILEN_MPPE);
  898. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  899. + MPPE_MAX_KEY_LEN);
  900. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  901. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  902. + ho->mppe_128 = 0;
  903. + p[5] |= (MPPE_40BIT|MPPE_56BIT);
  904. + p[5] &= ~MPPE_128BIT;
  905. + goto check_mppe_56_40;
  906. + }
  907. + goto check_mppe;
  908. }
  909. - } else if (ho->mppe & MPPE_OPT_128) {
  910. - if (!(ao->mppe & MPPE_OPT_128)) {
  911. - newret = CONFREJ;
  912. - break;
  913. + p[5] &= ~MPPE_128BIT;
  914. + goto check_mppe_56_40;
  915. + }
  916. + if ((p[5] & ~MPPE_MPPC) == (MPPE_56BIT|MPPE_128BIT)) {
  917. + newret = CONFNAK;
  918. + if (ao->mppe_128) {
  919. + ho->mppe_128 = 1;
  920. + p[5] &= ~MPPE_56BIT;
  921. + BCOPY(p, opt_buf, CILEN_MPPE);
  922. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  923. + MPPE_MAX_KEY_LEN);
  924. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  925. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  926. + ho->mppe_128 = 0;
  927. + p[5] |= MPPE_56BIT;
  928. + p[5] &= ~MPPE_128BIT;
  929. + goto check_mppe_56;
  930. + }
  931. + goto check_mppe;
  932. }
  933. - } else if (ho->mppe & MPPE_OPT_40) {
  934. - if (!(ao->mppe & MPPE_OPT_40)) {
  935. - newret = CONFREJ;
  936. - break;
  937. + p[5] &= ~MPPE_128BIT;
  938. + goto check_mppe_56;
  939. + }
  940. + if ((p[5] & ~MPPE_MPPC) == (MPPE_40BIT|MPPE_128BIT)) {
  941. + newret = CONFNAK;
  942. + if (ao->mppe_128) {
  943. + ho->mppe_128 = 1;
  944. + p[5] &= ~MPPE_40BIT;
  945. + BCOPY(p, opt_buf, CILEN_MPPE);
  946. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  947. + MPPE_MAX_KEY_LEN);
  948. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  949. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  950. + ho->mppe_128 = 0;
  951. + p[5] |= MPPE_40BIT;
  952. + p[5] &= ~MPPE_128BIT;
  953. + goto check_mppe_40;
  954. + }
  955. + goto check_mppe;
  956. + }
  957. + p[5] &= ~MPPE_128BIT;
  958. + goto check_mppe_40;
  959. + }
  960. + if ((p[5] & ~MPPE_MPPC) == MPPE_128BIT) {
  961. + if (ao->mppe_128) {
  962. + ho->mppe_128 = 1;
  963. + BCOPY(p, opt_buf, CILEN_MPPE);
  964. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  965. + MPPE_MAX_KEY_LEN);
  966. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  967. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  968. + ho->mppe_128 = 0;
  969. + p[5] &= ~MPPE_128BIT;
  970. + newret = CONFNAK;
  971. + }
  972. + goto check_mppe;
  973. + }
  974. + p[5] &= ~MPPE_128BIT;
  975. + newret = CONFNAK;
  976. + goto check_mppe;
  977. + }
  978. + check_mppe_56_40:
  979. + if ((p[5] & ~MPPE_MPPC) == (MPPE_40BIT|MPPE_56BIT)) {
  980. + newret = CONFNAK;
  981. + if (ao->mppe_56) {
  982. + ho->mppe_56 = 1;
  983. + p[5] &= ~MPPE_40BIT;
  984. + BCOPY(p, opt_buf, CILEN_MPPE);
  985. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  986. + MPPE_MAX_KEY_LEN);
  987. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  988. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  989. + ho->mppe_56 = 0;
  990. + p[5] |= MPPE_40BIT;
  991. + p[5] &= ~MPPE_56BIT;
  992. + newret = CONFNAK;
  993. + goto check_mppe_40;
  994. + }
  995. + goto check_mppe;
  996. + }
  997. + p[5] &= ~MPPE_56BIT;
  998. + goto check_mppe_40;
  999. + }
  1000. + check_mppe_56:
  1001. + if ((p[5] & ~MPPE_MPPC) == MPPE_56BIT) {
  1002. + if (ao->mppe_56) {
  1003. + ho->mppe_56 = 1;
  1004. + BCOPY(p, opt_buf, CILEN_MPPE);
  1005. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  1006. + MPPE_MAX_KEY_LEN);
  1007. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  1008. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  1009. + ho->mppe_56 = 0;
  1010. + p[5] &= ~MPPE_56BIT;
  1011. + newret = CONFNAK;
  1012. + }
  1013. + goto check_mppe;
  1014. + }
  1015. + p[5] &= ~MPPE_56BIT;
  1016. + newret = CONFNAK;
  1017. + goto check_mppe;
  1018. + }
  1019. + check_mppe_40:
  1020. + if ((p[5] & ~MPPE_MPPC) == MPPE_40BIT) {
  1021. + if (ao->mppe_40) {
  1022. + ho->mppe_40 = 1;
  1023. + BCOPY(p, opt_buf, CILEN_MPPE);
  1024. + BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  1025. + MPPE_MAX_KEY_LEN);
  1026. + if (ccp_test(f->unit, opt_buf, CILEN_MPPE +
  1027. + MPPE_MAX_KEY_LEN, 1) <= 0) {
  1028. + ho->mppe_40 = 0;
  1029. + p[5] &= ~MPPE_40BIT;
  1030. + newret = CONFNAK;
  1031. + }
  1032. + goto check_mppe;
  1033. + }
  1034. + p[5] &= ~MPPE_40BIT;
  1035. + }
  1036. +
  1037. + check_mppe:
  1038. + if (!ho->mppe_40 && !ho->mppe_56 && !ho->mppe_128) {
  1039. + if (wo->mppe_40 || wo->mppe_56 || wo->mppe_128) {
  1040. + newret = CONFNAK;
  1041. + p[2] |= (wo->mppe_stateless ? MPPE_STATELESS : 0);
  1042. + p[5] |= (wo->mppe_40 ? MPPE_40BIT : 0) |
  1043. + (wo->mppe_56 ? MPPE_56BIT : 0) |
  1044. + (wo->mppe_128 ? MPPE_128BIT : 0) |
  1045. + (wo->mppc ? MPPE_MPPC : 0);
  1046. + } else {
  1047. + ho->mppe = ho->mppe_stateless = 0;
  1048. }
  1049. } else {
  1050. - /* Neither are set. */
  1051. - /* We cannot accept this. */
  1052. + /* MPPE is not compatible with other compression types */
  1053. + if (wo->mppe) {
  1054. + ao->bsd_compress = 0;
  1055. + ao->predictor_1 = 0;
  1056. + ao->predictor_2 = 0;
  1057. + ao->deflate = 0;
  1058. + ao->lzs = 0;
  1059. + }
  1060. + }
  1061. + if ((!ho->mppc || !ao->mppc) && !ho->mppe) {
  1062. + p[2] = p2;
  1063. + p[5] = p5;
  1064. newret = CONFNAK;
  1065. /* Give the peer our idea of what can be used,
  1066. so it can choose and confirm */
  1067. ho->mppe = ao->mppe;
  1068. }
  1069. - /* rebuild the opts */
  1070. - MPPE_OPTS_TO_CI(ho->mppe, &p[2]);
  1071. - if (newret == CONFACK) {
  1072. - u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
  1073. - int mtu;
  1074. -
  1075. - BCOPY(p, opt_buf, CILEN_MPPE);
  1076. - BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
  1077. - MPPE_MAX_KEY_LEN);
  1078. - if (ccp_test(f->unit, opt_buf,
  1079. - CILEN_MPPE + MPPE_MAX_KEY_LEN, 1) <= 0) {
  1080. - /* This shouldn't happen, we've already tested it! */
  1081. - error("MPPE required, but kernel has no support.");
  1082. - lcp_close(f->unit, "MPPE required but not available");
  1083. - newret = CONFREJ;
  1084. - break;
  1085. - }
  1086. - /*
  1087. - * We need to decrease the interface MTU by MPPE_PAD
  1088. - * because MPPE frames **grow**. The kernel [must]
  1089. - * allocate MPPE_PAD extra bytes in xmit buffers.
  1090. - */
  1091. - mtu = netif_get_mtu(f->unit);
  1092. - if (mtu)
  1093. - netif_set_mtu(f->unit, mtu - MPPE_PAD);
  1094. - else
  1095. - newret = CONFREJ;
  1096. - }
  1097. + /*
  1098. + * I have commented the code below because according to RFC1547
  1099. + * MTU is only information for higher level protocols about
  1100. + * "the maximum allowable length for a packet (q.v.) transmitted
  1101. + * over a point-to-point link without incurring network layer
  1102. + * fragmentation." Of course a PPP implementation should be able
  1103. + * to handle overhead added by MPPE - in our case apropriate code
  1104. + * is located in drivers/net/ppp_generic.c in the kernel sources.
  1105. + *
  1106. + * According to RFC1661:
  1107. + * - when negotiated MRU is less than 1500 octets, a PPP
  1108. + * implementation must still be able to receive at least 1500
  1109. + * octets,
  1110. + * - when PFC is negotiated, a PPP implementation is still
  1111. + * required to receive frames with uncompressed protocol field.
  1112. + *
  1113. + * So why not to handle MPPE overhead without changing MTU value?
  1114. + * I am sure that RFC3078, unfortunately silently, assumes that.
  1115. + */
  1116. /*
  1117. - * We have accepted MPPE or are willing to negotiate
  1118. - * MPPE parameters. A CONFREJ is due to subsequent
  1119. - * (non-MPPE) processing.
  1120. + * We need to decrease the interface MTU by MPPE_PAD
  1121. + * because MPPE frames **grow**. The kernel [must]
  1122. + * allocate MPPE_PAD extra bytes in xmit buffers.
  1123. */
  1124. - rej_for_ci_mppe = 0;
  1125. +/*
  1126. + mtu = netif_get_mtu(f->unit);
  1127. + if (mtu) {
  1128. + netif_set_mtu(f->unit, mtu - MPPE_PAD);
  1129. + } else {
  1130. + newret = CONFREJ;
  1131. + if (ccp_wantoptions[f->unit].mppe) {
  1132. + error("Cannot adjust MTU needed by MPPE.");
  1133. + lcp_close(f->unit, "Cannot adjust MTU needed by MPPE.");
  1134. + }
  1135. + }
  1136. +*/
  1137. break;
  1138. #endif /* MPPE */
  1139. +
  1140. + case CI_LZS:
  1141. + if (!ao->lzs || clen != CILEN_LZS) {
  1142. + newret = CONFREJ;
  1143. + break;
  1144. + }
  1145. +
  1146. + ho->lzs = 1;
  1147. + ho->lzs_hists = (p[2] << 8) | p[3];
  1148. + ho->lzs_mode = p[4];
  1149. + if ((ho->lzs_hists != ao->lzs_hists) ||
  1150. + (ho->lzs_mode != ao->lzs_mode)) {
  1151. + newret = CONFNAK;
  1152. + if (!dont_nak) {
  1153. + p[2] = ao->lzs_hists >> 8;
  1154. + p[3] = ao->lzs_hists & 0xff;
  1155. + p[4] = ao->lzs_mode;
  1156. + } else
  1157. + break;
  1158. + }
  1159. +
  1160. + if (p == p0 && ccp_test(f->unit, p, CILEN_LZS, 1) <= 0) {
  1161. + newret = CONFREJ;
  1162. + }
  1163. + break;
  1164. +
  1165. case CI_DEFLATE:
  1166. case CI_DEFLATE_DRAFT:
  1167. if (!ao->deflate || clen != CILEN_DEFLATE
  1168. @@ -1344,12 +1835,6 @@ ccp_reqci(f, p, lenp, dont_nak)
  1169. else
  1170. *lenp = retp - p0;
  1171. }
  1172. -#ifdef MPPE
  1173. - if (ret == CONFREJ && ao->mppe && rej_for_ci_mppe) {
  1174. - error("MPPE required but peer negotiation failed");
  1175. - lcp_close(f->unit, "MPPE required but peer negotiation failed");
  1176. - }
  1177. -#endif
  1178. return ret;
  1179. }
  1180. @@ -1371,24 +1856,35 @@ method_name(opt, opt2)
  1181. char *p = result;
  1182. char *q = result + sizeof(result); /* 1 past result */
  1183. - slprintf(p, q - p, "MPPE ");
  1184. - p += 5;
  1185. - if (opt->mppe & MPPE_OPT_128) {
  1186. - slprintf(p, q - p, "128-bit ");
  1187. - p += 8;
  1188. - }
  1189. - if (opt->mppe & MPPE_OPT_40) {
  1190. - slprintf(p, q - p, "40-bit ");
  1191. - p += 7;
  1192. - }
  1193. - if (opt->mppe & MPPE_OPT_STATEFUL)
  1194. - slprintf(p, q - p, "stateful");
  1195. - else
  1196. - slprintf(p, q - p, "stateless");
  1197. -
  1198. + if (opt->mppe) {
  1199. + if (opt->mppc) {
  1200. + slprintf(p, q - p, "MPPC/MPPE ");
  1201. + p += 10;
  1202. + } else {
  1203. + slprintf(p, q - p, "MPPE ");
  1204. + p += 5;
  1205. + }
  1206. + if (opt->mppe_128) {
  1207. + slprintf(p, q - p, "128-bit ");
  1208. + p += 8;
  1209. + } else if (opt->mppe_56) {
  1210. + slprintf(p, q - p, "56-bit ");
  1211. + p += 7;
  1212. + } else if (opt->mppe_40) {
  1213. + slprintf(p, q - p, "40-bit ");
  1214. + p += 7;
  1215. + }
  1216. + if (opt->mppe_stateless)
  1217. + slprintf(p, q - p, "stateless");
  1218. + else
  1219. + slprintf(p, q - p, "stateful");
  1220. + } else if (opt->mppc)
  1221. + slprintf(p, q - p, "MPPC");
  1222. break;
  1223. }
  1224. -#endif
  1225. +#endif /* MPPE */
  1226. + case CI_LZS:
  1227. + return "Stac LZS";
  1228. case CI_DEFLATE:
  1229. case CI_DEFLATE_DRAFT:
  1230. if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
  1231. @@ -1444,12 +1940,12 @@ ccp_up(f)
  1232. } else if (ANY_COMPRESS(*ho))
  1233. notice("%s transmit compression enabled", method_name(ho, NULL));
  1234. #ifdef MPPE
  1235. - if (go->mppe) {
  1236. + if (go->mppe || go->mppc) {
  1237. BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN);
  1238. BZERO(mppe_send_key, MPPE_MAX_KEY_LEN);
  1239. continue_networks(f->unit); /* Bring up IP et al */
  1240. }
  1241. -#endif
  1242. +#endif /* MPPE */
  1243. }
  1244. /*
  1245. @@ -1472,7 +1968,7 @@ ccp_down(f)
  1246. lcp_close(f->unit, "MPPE disabled");
  1247. }
  1248. }
  1249. -#endif
  1250. +#endif /* MPPE */
  1251. }
  1252. /*
  1253. @@ -1532,24 +2028,28 @@ ccp_printpkt(p, plen, printer, arg)
  1254. #ifdef MPPE
  1255. case CI_MPPE:
  1256. if (optlen >= CILEN_MPPE) {
  1257. - u_char mppe_opts;
  1258. -
  1259. - MPPE_CI_TO_OPTS(&p[2], mppe_opts);
  1260. - printer(arg, "mppe %s %s %s %s %s %s%s",
  1261. - (p[2] & MPPE_H_BIT)? "+H": "-H",
  1262. - (p[5] & MPPE_M_BIT)? "+M": "-M",
  1263. - (p[5] & MPPE_S_BIT)? "+S": "-S",
  1264. - (p[5] & MPPE_L_BIT)? "+L": "-L",
  1265. + printer(arg, "mppe %s %s %s %s %s %s",
  1266. + (p[2] & MPPE_STATELESS)? "+H": "-H",
  1267. + (p[5] & MPPE_56BIT)? "+M": "-M",
  1268. + (p[5] & MPPE_128BIT)? "+S": "-S",
  1269. + (p[5] & MPPE_40BIT)? "+L": "-L",
  1270. (p[5] & MPPE_D_BIT)? "+D": "-D",
  1271. - (p[5] & MPPE_C_BIT)? "+C": "-C",
  1272. - (mppe_opts & MPPE_OPT_UNKNOWN)? " +U": "");
  1273. - if (mppe_opts & MPPE_OPT_UNKNOWN)
  1274. + (p[5] & MPPE_MPPC)? "+C": "-C");
  1275. + if ((p[5] & ~(MPPE_56BIT | MPPE_128BIT | MPPE_40BIT |
  1276. + MPPE_D_BIT | MPPE_MPPC)) ||
  1277. + (p[2] & ~MPPE_STATELESS))
  1278. printer(arg, " (%.2x %.2x %.2x %.2x)",
  1279. p[2], p[3], p[4], p[5]);
  1280. p += CILEN_MPPE;
  1281. }
  1282. break;
  1283. -#endif
  1284. +#endif /* MPPE */
  1285. + case CI_LZS:
  1286. + if (optlen >= CILEN_LZS) {
  1287. + printer(arg, "lzs %.2x %.2x %.2x", p[2], p[3], p[4]);
  1288. + p += CILEN_LZS;
  1289. + }
  1290. + break;
  1291. case CI_DEFLATE:
  1292. case CI_DEFLATE_DRAFT:
  1293. if (optlen >= CILEN_DEFLATE) {
  1294. @@ -1635,6 +2135,7 @@ ccp_datainput(unit, pkt, len)
  1295. error("Lost compression sync: disabling compression");
  1296. ccp_close(unit, "Lost compression sync");
  1297. #ifdef MPPE
  1298. + /* My module dosn't need this. J.D., 2003-07-06 */
  1299. /*
  1300. * If we were doing MPPE, we must also take the link down.
  1301. */
  1302. @@ -1642,9 +2143,18 @@ ccp_datainput(unit, pkt, len)
  1303. error("Too many MPPE errors, closing LCP");
  1304. lcp_close(unit, "Too many MPPE errors");
  1305. }
  1306. -#endif
  1307. +#endif /* MPPE */
  1308. } else {
  1309. /*
  1310. + * When LZS or MPPE/MPPC is negotiated we just send CCP_RESETREQ
  1311. + * and don't wait for CCP_RESETACK
  1312. + */
  1313. + if ((ccp_gotoptions[f->unit].method == CI_LZS) ||
  1314. + (ccp_gotoptions[f->unit].method == CI_MPPE)) {
  1315. + fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
  1316. + return;
  1317. + }
  1318. + /*
  1319. * Send a reset-request to reset the peer's compressor.
  1320. * We don't do that if we are still waiting for an
  1321. * acknowledgement to a previous reset-request.
  1322. @@ -1675,4 +2185,3 @@ ccp_rack_timeout(arg)
  1323. } else
  1324. ccp_localstate[f->unit] &= ~RACK_PENDING;
  1325. }
  1326. -