#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include <ip.h>
#include <auth.h>
#include "dat.h"
#include "fns.h"
extern Srv fs;
static char buf[Blen];
static UserPasswd*upwd;
static uchar defmac[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
void
usage(void)
{
fprint(2, "usage: 8021x [-d] [-D] [-T] [-m mtpt] [-t /sys/lib/tls/xxx] [-x /sys/lib/tls/xxx.exclude]\n");
syslog(0, logname, "usage");
threadexitsall("usage");
}
void
threadmain(int argc, char *argv[])
{
char *thumbFile, *thumbFilex, *mtpt;
Etherstate *e;
PAEstate *s;
Phasestate *p;
Timers *t;
mtpt = "/net";
fmtinstall('E', eipfmt);
thumbFile = nil;
thumbFilex = nil;
ARGBEGIN{
case 'd':
debug++;
break;
case 'D':
chatty9p++;
break;
case 'T':
debugTLS++;
break;
case 'm':
mtpt = ARGF();
break;
case 't':
thumbFile = EARGF(usage());
break;
case 'x':
thumbFilex = EARGF(usage());
break;
}ARGEND;
logname = "8021x";
loglog("====== starting =======");
syslog(0, logname, "starting");
if(mtpt == nil || argc > 0)
usage();
if(thumbFilex && !thumbFile)
logfatal(1, "specifying -x without -t is useless");
initbufs();
e = initether();
p = phasesinit();
t = initTimers();
s = init8021x(e, t, p);
initTTLS(thumbFile, thumbFilex, t);
initFs();
if(argc == 0)
e->dir = "/net/ether0";
else
e->dir = argv[0];
snprint(buf, Blen, "%s!0x888e", e->dir);
e->fd = dial(buf, 0, 0, &e->cfd);
if(e->fd < 0)
logfatal(1, "could not dial %s: %r", buf);
if (myetheraddr(e->ourmac, e->dir) < 0)
logfatal(1, "could not read own ether addres from %s", e->dir);
upwd = auth_getuserpasswd(auth_getkey, "proto=pass service=8021x-pap");
if (upwd) {
myId = upwd->user;
myPasswd = upwd->passwd;
} else
logfatal(1, "cannot get user/passwd");
// we could try to threadcreate backproc and paeproc
// (since they are coroutines),
// such that they are in a single process,
// as we had them before we turned this into an fs,
// but then the current process does not exit
// and things don't work.
// this may just be because of my limited understanding.
procrfork(tickproc, t, SMALLSTACK, RFNAMEG|RFNOTEG);
start8021xprocs(s);
procrfork(etherproc, e, SMALLSTACK, RFNAMEG|RFNOTEG);
threadpostmountsrv(&fs, logname, mtpt, MAFTER);
threadexits(0);
}
|