2 #include "../port/lib.h"
6 #include "../port/error.h"
12 static void pppreader(void *a);
13 static void pppbind(Ipifc *ifc, int argc, char **argv);
14 static void pppunbind(Ipifc *ifc);
15 static void pppbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip);
16 static void deadremote(Ipifc *ifc);
28 .unbindonclose= 0, /* don't unbind on last close */
32 * called to bind an IP ifc to an ethernet device
33 * called with ifc wlock'd
36 pppbind(Ipifc *ifc, int argc, char **argv)
41 char *chapname, *secret;
46 ipmove(ipaddr, IPnoaddr);
47 ipmove(remip, IPnoaddr);
63 framing = strtoul(argv[6], 0, 0);
66 mtu = strtoul(argv[5], 0, 0);
69 parseip(remip, argv[4]);
72 parseip(ipaddr, argv[3]);
77 ppp = smalloc(sizeof(*ppp));
79 ppp->f = ifc->conv->p->f;
85 if(pppopen(ppp, argv[2], ipaddr, remip, mtu, framing, chapname, secret) == nil)
86 error("ppp open failed");
88 ktask("pppreader", pppreader, ifc);
100 ppp->readp = up; /* hide identity under a rock for unbind */
104 netlog(ppp->f, Logppp, "pppreader: %I: %s\n", ppp->local, up->env->errstr);
126 ipiput(ppp->f, ifc, bp);
133 * called with ifc wlock'd
136 pppunbind(Ipifc *ifc)
143 postnote(ppp->readp, 1, "unbind", 0);
145 postnote(ppp->timep, 1, "unbind", 0);
147 /* wait for kprocs to die */
148 while(ppp->readp != 0 || ppp->timep != 0)
149 udelay_sched(300 * 1000);
152 qclose(ifc->conv->eq);
157 * called by ipoput with a single packet to write with ifc rlock'd
160 pppbwrite(Ipifc *ifc, Block *bp, int, uchar*)
169 * If the other end hangs up, we have to unbind the interface. An extra
170 * unbind (in the case where we are hanging up) won't do any harm.
173 deadremote(Ipifc *ifc)
180 snprint(path, sizeof path, "#I%d/ipifc/%d/ctl", ppp->f->dev, ifc->conv->x);
181 fd = kopen(path, ORDWR);
184 kwrite(fd, "unbind", sizeof("unbind")-1);
191 addipmedium(&pppmedium);