9front - general discussion about 9front
 help / color / mirror / Atom feed
* Patches for ppp and pppoe
@ 2016-03-15 18:37 k0ga
  0 siblings, 0 replies; only message in thread
From: k0ga @ 2016-03-15 18:37 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

Hi,

I had some problems setting my pppoe connection with my ISP,
and in the process I discovered a few things in the code of
ppp and pppoe. I attach 5 patches to this mail:

p1.patch: Add support for -c and -C in pppoe

p2.patch: Do not request encriptation with -c or -C in ppp
(it was a bit annoying request compression, and when the ACK
from the server was received then send a NAK).

p3.patch: Add support for md5 and mschap in in chap
(without this patch ppp was passing to the net stage
without worring about chap).

p4.patch: Small format and log fixes

p5.patch: Avoid buffer overflow in ppp
(ppp->secret comes from factotum and it can have any size)
This patch also sets the correct state after success and
failure cases in chap negotiation (without them the code was
working because it expected the other point to pass to net
phase or due to the timer).

Regard,

[-- Attachment #2: p1.patch --]
[-- Type: text/plain, Size: 1212 bytes --]

diff -r 94844cc7f1fd -r 3e63050481a8 sys/man/8/ppp
--- a/sys/man/8/ppp	Tue Mar 01 21:27:37 2016 -0500
+++ b/sys/man/8/ppp	Sat Mar 05 07:44:02 2016 +0100
@@ -34,7 +34,7 @@
 .PP
 .B ip/pppoe
 [
-.B -Pd
+.B -PdcC
 ]
 [
 .B -A
diff -r 94844cc7f1fd -r 3e63050481a8 sys/src/cmd/ip/pppoe.c
--- a/sys/src/cmd/ip/pppoe.c	Tue Mar 01 21:27:37 2016 -0500
+++ b/sys/src/cmd/ip/pppoe.c	Sat Mar 05 07:44:02 2016 +0100
@@ -28,11 +28,12 @@
 int cookielen;
 uchar etherdst[6];
 int mtu = 1492;
+int pktcompress, hdrcompress;
 
 void
 usage(void)
 {
-	fprint(2, "usage: pppoe [-Pd] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-x pppnet] [ether0]\n");
+	fprint(2, "usage: pppoe [-PdcC] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-x pppnet] [ether0]\n");
 	exits("usage");
 }
 
@@ -75,6 +76,12 @@
 	case 'k':
 		keyspec = EARGF(usage());
 		break;
+	case 'c':
+		pktcompress = 1;
+		break;
+	case 'C':
+		hdrcompress = 1;
+		break;
 	case 'x':
 		pppnetmtpt = EARGF(usage());
 		break;
@@ -526,6 +533,10 @@
 		argv[argc++] = "-d";
 	if(primary)
 		argv[argc++] = "-P";
+	if(hdrcompress)
+		argv[argc++] = "-C";
+	if(pktcompress)
+		argv[argc++] = "-c";
 	if(pppnetmtpt){
 		argv[argc++] = "-x";
 		argv[argc++] = pppnetmtpt;

[-- Attachment #3: p2.patch --]
[-- Type: text/plain, Size: 503 bytes --]

diff -r 3e63050481a8 sys/src/cmd/ip/ppp/ppp.c
--- a/sys/src/cmd/ip/ppp/ppp.c	Sat Mar 05 07:44:02 2016 +0100
+++ b/sys/src/cmd/ip/ppp/ppp.c	Sat Mar 05 07:47:52 2016 +0100
@@ -276,7 +276,14 @@
 		ppp->rctlmap = 0;
 		ppp->ipcp->state = Sclosed;
 		ppp->ipcp->optmask = 0xffffffff;
-
+		if(noipcompress) {
+			p->optmask &= ~Fac;
+			ppp->ipcp->optmask &= ~Fipaddrs;
+		}
+		if(nocompress) {
+			p->optmask &= ~Fpc;
+			ppp->ipcp->optmask &= ~Fipcompress;
+		}
 		p->echotimeout = 0;
 
 		/* quality goo */

[-- Attachment #4: p3.patch --]
[-- Type: text/plain, Size: 612 bytes --]

diff -r 3e63050481a8 sys/src/cmd/ip/ppp/ppp.c
--- a/sys/src/cmd/ip/ppp/ppp.c	Sat Mar 05 07:44:02 2016 +0100
+++ b/sys/src/cmd/ip/ppp/ppp.c	Mon Mar 14 23:36:40 2016 +0100
@@ -243,12 +244,21 @@
 		}
 		break;
 	case Pauth:
-		if(server)
+		if(server) {
 			chapinit(ppp);
-		else if(ppp->chap->proto == APpasswd)
-			papinit(ppp);
-		else
-			setphase(ppp, Pnet);
+		} else {
+			switch (ppp->chap->proto) {
+			case APpasswd:
+				papinit(ppp);
+				break;
+			case APmd5:
+			case APmschap:
+				break;
+			default:
+				setphase(ppp, Pnet);
+				break;
+			}
+		}
 		break;
 	case Pnet:
 		pinit(ppp, ppp->ccp);

[-- Attachment #5: p4.patch --]
[-- Type: text/plain, Size: 773 bytes --]

diff -r 3e63050481a8 sys/src/cmd/ip/ppp/ppp.c
--- a/sys/src/cmd/ip/ppp/ppp.c	Sat Mar 05 07:44:02 2016 +0100
+++ b/sys/src/cmd/ip/ppp/ppp.c	Mon Mar 14 23:36:40 2016 +0100
@@ -693,10 +709,10 @@
 		}
 		break;
 	case Pipcp:
-		if(p->optmask & Fipaddr)
-{syslog(0, "ppp", "requesting %I", ppp->local);
+		if(p->optmask & Fipaddr){
+			syslog(0, "ppp", "requesting %I", ppp->local);
 			putv4o(b, Oipaddr, ppp->local);
-}
+		}
 		if(primary && (p->optmask & Fipdns))
 			putv4o(b, Oipdns, ppp->dns[0]);
 		if(primary && (p->optmask & Fipdns2))
@@ -1350,7 +1366,7 @@
 		break;
 	case Lprotorej:
 		proto = nhgets(m->data);
-		netlog("ppp: proto reject %ux", proto);
+		netlog("ppp: proto reject %ux\n", proto);
 		if(proto == Pccp)
 			newstate(ppp, ppp->ccp, Sclosed);
 		break;

[-- Attachment #6: p5.patch --]
[-- Type: text/plain, Size: 1152 bytes --]

diff -r 3e63050481a8 sys/src/cmd/ip/ppp/ppp.c
--- a/sys/src/cmd/ip/ppp/ppp.c	Sat Mar 05 07:44:02 2016 +0100
+++ b/sys/src/cmd/ip/ppp/ppp.c	Mon Mar 14 23:36:40 2016 +0100
@@ -2081,18 +2097,23 @@
 			netlog("PPP: chap: bad challenge len\n");
 			break;
 		}
 
 		id = m->id;
 		switch(ppp->chap->proto){
 		default:
 			abort();
 		case APmd5:
+			n = strlen(ppp->secret);
+			if(n + vlen + 1 > sizeof(md5buf)) {
+				netlog("PPP: chap: bad challenge len\n");
+				goto end;
+			}
 			md5buf[0] = m->id;
-			strcpy(md5buf+1, ppp->secret);
-			n = strlen(ppp->secret) + 1;
-			memmove(md5buf+n, m->data+1, vlen);
-			n += vlen;
-			md5((uchar*)md5buf, n, digest, nil);
+			memcpy(md5buf+1, ppp->secret, n);
+			memcpy(md5buf+1+n, m->data+1, vlen);
+			md5((uchar*)md5buf, n + vlen + 1, digest, nil);
 			resp = digest;
 			nresp = 16;
 			break;
@@ -2213,14 +2234,17 @@
 		break;
 	case Csuccess:
 		netlog("ppp: chap succeeded\n");
+		setphase(ppp, Pnet);
 		break;
 	case Cfailure:
 		netlog("ppp: chap failed\n");
+		terminate(ppp, 0);
 		break;
 	default:
 		syslog(0, LOG, "chap code %d?", m->code);
 		break;
 	}
+end:
 	qunlock(ppp);
 	freeb(b);
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-03-15 18:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-15 18:37 Patches for ppp and pppoe k0ga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).