Deleted Added
full compact
lcp.c (31962) lcp.c (32439)
1/*
2 * PPP Link Control Protocol (LCP) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Link Control Protocol (LCP) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: lcp.c,v 1.50 1997/12/07 23:55:27 brian Exp $
20 * $Id: lcp.c,v 1.51 1997/12/24 09:29:05 brian Exp $
21 *
22 * TODO:
23 * o Validate magic number received from peer.
24 * o Limit data field length by MRU
25 */
26#include <sys/param.h>
27#include <sys/time.h>
28#include <sys/select.h>

--- 137 unchanged lines hidden (view full) ---

166 struct lcpstate *lcp = &LcpInfo;
167 struct fsm *fp = &LcpFsm;
168
169 if (!VarTerm)
170 return 1;
171
172 fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]);
173 fprintf(VarTerm,
21 *
22 * TODO:
23 * o Validate magic number received from peer.
24 * o Limit data field length by MRU
25 */
26#include <sys/param.h>
27#include <sys/time.h>
28#include <sys/select.h>

--- 137 unchanged lines hidden (view full) ---

166 struct lcpstate *lcp = &LcpInfo;
167 struct fsm *fp = &LcpFsm;
168
169 if (!VarTerm)
170 return 1;
171
172 fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]);
173 fprintf(VarTerm,
174 " his side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
175 " REJECT %04lx\n",
176 lcp->his_mru, lcp->his_accmap, lcp->his_protocomp, lcp->his_acfcomp,
177 lcp->his_magic, lcp->his_reject);
174 " his side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
175 " MAGIC %08lx, REJECT %04x\n",
176 lcp->his_mru, (u_long)lcp->his_accmap, lcp->his_protocomp,
177 lcp->his_acfcomp, (u_long)lcp->his_magic, lcp->his_reject);
178 fprintf(VarTerm,
178 fprintf(VarTerm,
179 " my side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
180 " REJECT %04lx\n",
181 lcp->want_mru, lcp->want_accmap, lcp->want_protocomp, lcp->want_acfcomp,
182 lcp->want_magic, lcp->my_reject);
183 fprintf(VarTerm, "\nDefaults: MRU = %ld, ACCMAP = %08x\t", VarMRU, VarAccmap);
184 fprintf(VarTerm, "Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE) ? "active" : "passive");
179 " my side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
180 " MAGIC %08lx, REJECT %04x\n",
181 lcp->want_mru, (u_long)lcp->want_accmap, lcp->want_protocomp,
182 lcp->want_acfcomp, (u_long)lcp->want_magic, lcp->my_reject);
183 fprintf(VarTerm, "\nDefaults: MRU = %d, ACCMAP = %08lx\t",
184 VarMRU, (u_long)VarAccmap);
185 fprintf(VarTerm, "Open Mode: %s\n",
186 (VarOpenMode == OPEN_ACTIVE) ? "active" : "passive");
185 return 0;
186}
187
188/*
189 * Generate random number which will be used as magic number.
190 */
187 return 0;
188}
189
190/*
191 * Generate random number which will be used as magic number.
192 */
191static u_long
193static u_int32_t
192GenerateMagic(void)
193{
194 randinit();
195 return (random());
196}
197
198void
199LcpInit()

--- 52 unchanged lines hidden (view full) ---

252
253#define PUTN(ty) \
254do { \
255 o.id = ty; \
256 o.len = 2; \
257 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], NULL); \
258} while (0)
259
194GenerateMagic(void)
195{
196 randinit();
197 return (random());
198}
199
200void
201LcpInit()

--- 52 unchanged lines hidden (view full) ---

254
255#define PUTN(ty) \
256do { \
257 o.id = ty; \
258 o.len = 2; \
259 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], NULL); \
260} while (0)
261
260#define PUTHEXL(ty, arg) \
262#define PUTHEX32(ty, arg) \
261do { \
262 o.id = ty; \
263 o.len = 6; \
264 *(u_long *)o.data = htonl(arg); \
263do { \
264 o.id = ty; \
265 o.len = 6; \
266 *(u_long *)o.data = htonl(arg); \
265 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "0x%08x", (u_int)arg);\
267 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "0x%08lx", (u_long)arg);\
266} while (0)
267
268} while (0)
269
268#define PUTACCMAP(arg) PUTHEXL(TY_ACCMAP, arg)
269#define PUTMAGIC(arg) PUTHEXL(TY_MAGICNUM, arg)
270#define PUTACCMAP(arg) PUTHEX32(TY_ACCMAP, arg)
271#define PUTMAGIC(arg) PUTHEX32(TY_MAGICNUM, arg)
270
271#define PUTMRU(arg) \
272do { \
273 o.id = TY_MRU; \
274 o.len = 4; \
275 *(u_short *)o.data = htons(arg); \
272
273#define PUTMRU(arg) \
274do { \
275 o.id = TY_MRU; \
276 o.len = 4; \
277 *(u_short *)o.data = htons(arg); \
276 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "%lu", arg); \
278 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "%u", arg); \
277} while (0)
278
279#define PUTLQR(period) \
280do { \
281 o.id = TY_QUALPROTO; \
282 o.len = 8; \
283 *(u_short *)o.data = htons(PROTO_LQR); \
284 *(u_long *)(o.data+2) = htonl(period); \
279} while (0)
280
281#define PUTLQR(period) \
282do { \
283 o.id = TY_QUALPROTO; \
284 o.len = 8; \
285 *(u_short *)o.data = htons(PROTO_LQR); \
286 *(u_long *)(o.data+2) = htonl(period); \
285 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "period %ld", period);\
287 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], \
288 "period %ld", (u_long)period); \
286} while (0)
287
288#define PUTPAP() \
289do { \
290 o.id = TY_AUTHPROTO; \
291 o.len = 4; \
292 *(u_short *)o.data = htons(PROTO_PAP); \
293 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], \

--- 175 unchanged lines hidden (view full) ---

469}
470
471/*
472 * XXX: Should validate option length
473 */
474static void
475LcpDecodeConfig(u_char *cp, int plen, int mode_type)
476{
289} while (0)
290
291#define PUTPAP() \
292do { \
293 o.id = TY_AUTHPROTO; \
294 o.len = 4; \
295 *(u_short *)o.data = htons(PROTO_PAP); \
296 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], \

--- 175 unchanged lines hidden (view full) ---

472}
473
474/*
475 * XXX: Should validate option length
476 */
477static void
478LcpDecodeConfig(u_char *cp, int plen, int mode_type)
479{
477 int type, length, mru, mtu, sz, pos;
478 u_long *lp, magic, accmap;
479 u_short *sp, proto;
480 int type, length, sz, pos;
481 u_int32_t *lp, magic, accmap;
482 u_short mtu, mru, *sp, proto;
480 struct lqrreq *req;
481 char request[20], desc[22];
482
483 ackp = AckBuff;
484 nakp = NakBuff;
485 rejp = RejBuff;
486
487 while (plen >= sizeof(struct fsmconfig)) {

--- 36 unchanged lines hidden (view full) ---

524 break;
525 case MODE_REJ:
526 LcpInfo.his_reject |= (1 << type);
527 break;
528 }
529 break;
530
531 case TY_ACCMAP:
483 struct lqrreq *req;
484 char request[20], desc[22];
485
486 ackp = AckBuff;
487 nakp = NakBuff;
488 rejp = RejBuff;
489
490 while (plen >= sizeof(struct fsmconfig)) {

--- 36 unchanged lines hidden (view full) ---

527 break;
528 case MODE_REJ:
529 LcpInfo.his_reject |= (1 << type);
530 break;
531 }
532 break;
533
534 case TY_ACCMAP:
532 lp = (u_long *) (cp + 2);
535 lp = (u_int32_t *) (cp + 2);
533 accmap = htonl(*lp);
536 accmap = htonl(*lp);
534 LogPrintf(LogLCP, "%s 0x%08x\n", request, accmap);
537 LogPrintf(LogLCP, "%s 0x%08lx\n", request, (u_long)accmap);
535
536 switch (mode_type) {
537 case MODE_REQ:
538 LcpInfo.his_accmap = accmap;
539 memcpy(ackp, cp, 6);
540 ackp += 6;
541 break;
542 case MODE_NAK:

--- 132 unchanged lines hidden (view full) ---

675 break;
676 case MODE_REJ:
677 LcpInfo.his_reject |= (1 << type);
678 break;
679 }
680 break;
681
682 case TY_MAGICNUM:
538
539 switch (mode_type) {
540 case MODE_REQ:
541 LcpInfo.his_accmap = accmap;
542 memcpy(ackp, cp, 6);
543 ackp += 6;
544 break;
545 case MODE_NAK:

--- 132 unchanged lines hidden (view full) ---

678 break;
679 case MODE_REJ:
680 LcpInfo.his_reject |= (1 << type);
681 break;
682 }
683 break;
684
685 case TY_MAGICNUM:
683 lp = (u_long *) (cp + 2);
686 lp = (u_int32_t *) (cp + 2);
684 magic = ntohl(*lp);
687 magic = ntohl(*lp);
685 LogPrintf(LogLCP, "%s 0x%08x\n", request, magic);
688 LogPrintf(LogLCP, "%s 0x%08lx\n", request, (u_long)magic);
686
687 switch (mode_type) {
688 case MODE_REQ:
689 if (LcpInfo.want_magic) {
690 /* Validate magic number */
691 if (magic == LcpInfo.want_magic) {
689
690 switch (mode_type) {
691 case MODE_REQ:
692 if (LcpInfo.want_magic) {
693 /* Validate magic number */
694 if (magic == LcpInfo.want_magic) {
692 LogPrintf(LogLCP, "Magic is same (%08x) - %d times\n",
693 magic, ++LcpFailedMagic);
695 LogPrintf(LogLCP, "Magic is same (%08lx) - %d times\n",
696 (u_long)magic, ++LcpFailedMagic);
694 LcpInfo.want_magic = GenerateMagic();
695 memcpy(nakp, cp, 6);
696 nakp += 6;
697 ualarm(TICKUNIT * (4 + 4 * LcpFailedMagic), 0);
698 sigpause(0);
699 } else {
700 LcpInfo.his_magic = magic;
701 memcpy(ackp, cp, length);
702 ackp += length;
703 LcpFailedMagic = 0;
704 }
705 } else {
706 LcpInfo.my_reject |= (1 << type);
707 goto reqreject;
708 }
709 break;
710 case MODE_NAK:
697 LcpInfo.want_magic = GenerateMagic();
698 memcpy(nakp, cp, 6);
699 nakp += 6;
700 ualarm(TICKUNIT * (4 + 4 * LcpFailedMagic), 0);
701 sigpause(0);
702 } else {
703 LcpInfo.his_magic = magic;
704 memcpy(ackp, cp, length);
705 ackp += length;
706 LcpFailedMagic = 0;
707 }
708 } else {
709 LcpInfo.my_reject |= (1 << type);
710 goto reqreject;
711 }
712 break;
713 case MODE_NAK:
711 LogPrintf(LogLCP, " Magic 0x%08x is NAKed!\n", magic);
714 LogPrintf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
712 LcpInfo.want_magic = GenerateMagic();
713 break;
714 case MODE_REJ:
715 LogPrintf(LogLCP, " Magic 0x%80x is REJected!\n", magic);
716 LcpInfo.want_magic = 0;
717 LcpInfo.his_reject |= (1 << type);
718 break;
719 }

--- 114 unchanged lines hidden ---
715 LcpInfo.want_magic = GenerateMagic();
716 break;
717 case MODE_REJ:
718 LogPrintf(LogLCP, " Magic 0x%80x is REJected!\n", magic);
719 LcpInfo.want_magic = 0;
720 LcpInfo.his_reject |= (1 << type);
721 break;
722 }

--- 114 unchanged lines hidden ---