Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/netif.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/netif.c 1993/0525
## diff -e /dev/null /n/fornaxdump/1993/0525/sys/src/brazil/port/netif.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"../port/error.h"
#include	"../port/netif.h"

uchar etherbcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

static int netown(Netfile*, char*, int);
static int openfile(Netif*, int);
static char* matchtoken(char*, char*);

/*
 *  set up a new network interface
 */
void
netifinit(Netif *nif, char *name, int nfile, ulong limit)
{
	nif->name = name;
	nif->nfile = nfile;
	nif->f = xalloc(nfile*sizeof(Netfile*));
	memset(nif->f, 0, nfile*sizeof(Netfile*));
	nif->limit = limit;
	nif->out = qopen(limit, 0, 0);
}

/*
 *  generate a 3 level directory
 */
static int
netifgen(Chan *c, void *vp, int ntab, int i, Dir *dp)
{
	Qid q;
	char buf[32];
	Netif *nif = vp;
	Netfile *f;
	int t;
	int perm;
	char *o;

	USED(ntab);
	q.vers = 0;

	/* top level directory contains the name of the network */
	if(c->qid.path == CHDIR){
		switch(i){
		case 0:
			q.path = CHDIR | N2ndqid;
			strcpy(buf, nif->name);
			devdir(c, q, buf, 0, eve, 0555, dp);
			break;
		default:
			return -1;
		}
		return 1;
	}

	/* second level contains clone plus all the conversations */
	t = NETTYPE(c->qid.path);
	if(t == N2ndqid || t == Ncloneqid){
		if(i == 0){
			q.path = Ncloneqid;
			devdir(c, q, "clone", 0, eve, 0666, dp);
		}else if(i <= nif->nfile){
			if(nif->f[i-1] == 0)
				return 0;
			q.path = CHDIR|NETQID(i-1, N3rdqid);
			sprint(buf, "%d", i-1);
			devdir(c, q, buf, 0, eve, 0555, dp);
		}else
			return -1;
		return 1;
	}

	/* third level */
	f = nif->f[NETID(c->qid.path)];
	if(f == 0)
		return 0;
	if(*f->owner){
		o = f->owner;
		perm = f->mode;
	} else {
		o = eve;
		perm = 0666;
	}
	switch(i){
	case 0:
		q.path = NETQID(NETID(c->qid.path), Ndataqid);
		devdir(c, q, "data", 0, o, perm, dp);
		break;
	case 1:
		q.path = NETQID(NETID(c->qid.path), Nctlqid);
		devdir(c, q, "ctl", 0, o, perm, dp);
		break;
	case 2:
		q.path = NETQID(NETID(c->qid.path), Nstatqid);
		devdir(c, q, "stat", 0, eve, 0444, dp);
		break;
	case 3:
		q.path = NETQID(NETID(c->qid.path), Ntypeqid);
		devdir(c, q, "type", 0, eve, 0444, dp);
		break;
	default:
		return -1;
	}
	return 1;
}

int
netifwalk(Netif *nif, Chan *c, char *name)
{
	return devwalk(c, name, (Dirtab *)nif, 0, netifgen);
}

Chan*
netifopen(Netif *nif, Chan *c, int omode)
{
	int id = 0;
	Netfile *f;

	if(c->qid.path & CHDIR){
		if(omode != OREAD)
			error(Eperm);
	} else {
		switch(NETTYPE(c->qid.path)){
		case Ndataqid:
		case Nctlqid:
			id = NETID(c->qid.path);
			openfile(nif, id);
			break;
		case Ncloneqid:
			id = openfile(nif, -1);
			c->qid.path = NETQID(id, Nctlqid);
			ptclone(c, 0, id);
			break;
		default:
			if(omode != OREAD)
				error(Ebadarg);
		}
		switch(NETTYPE(c->qid.path)){
		case Ndataqid:
		case Nctlqid:
			f = nif->f[id];
			if(netown(f, up->user, omode&7) < 0)
				error(Eperm);
			break;
		}
	}
	c->mode = openmode(omode);
	c->flag |= COPEN;
	c->offset = 0;
	return c;
}

long
netifread(Netif *nif, Chan *c, void *a, long n, ulong offset)
{
	Netfile *f;
	int i;
	char buf[256];

	if(c->qid.path&CHDIR)
		return devdirread(c, a, n, (Dirtab*)nif, 0, netifgen);

	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
		f = nif->f[NETID(c->qid.path)];
		return qread(f->in, a, n);
	case Nctlqid:
		return readnum(offset, a, n, NETID(c->qid.path), NUMSIZE);
	case Nstatqid:
		n = sprint(buf, "in: %d\n", nif->inpackets);
		n += sprint(buf+n, "out: %d\n", nif->outpackets);
		n += sprint(buf+n, "crc errs: %d\n", nif->crcs);
		n += sprint(buf+n, "overflows: %d\n", nif->overflows);
		n += sprint(buf+n, "framing errs: %d\n", nif->frames);
		n += sprint(buf+n, "buffer errs: %d\n", nif->buffs);
		n += sprint(buf+n, "output errs: %d\n", nif->oerrs);
		n += sprint(buf+n, "addr:", nif->oerrs);
		for(i = 0; i < nif->alen; i++)
			n += sprint(buf+n, "%2.2ux", nif->addr[i]);
		n += sprint(buf+n, "\n");
		return readstr(offset, a, n, buf);
	case Ntypeqid:
		f = nif->f[NETID(c->qid.path)];
		return readnum(offset, a, n, f->type, NUMSIZE);
	}
	error(Ebadarg);
	return -1;	/* not reached */
}

/*
 *  the devxxx.c that calls us handles writing data, it knows best
 */
long
netifwrite(Netif *nif, Chan *c, void *a, long n)
{
	Netfile *f;
	char *p;
	char buf[256];

	if(NETTYPE(c->qid.path) != Nctlqid)
		error(Eperm);

	if(n >= sizeof(buf))
		n = sizeof(buf)-1;
	memmove(buf, a, n);
	buf[n] = 0;

	qlock(nif);
	f = nif->f[NETID(c->qid.path)];
	if(p = matchtoken(buf, "connect")){
		f->type = atoi(p);
	} else if(matchtoken(buf, "promiscuous")){
		f->prom = 1;
		nif->prom++;
		if(nif->prom == 1)
			(*nif->promiscuous)(nif->arg, 1);
	}
	qunlock(nif);
	return n;
}

void
netifwstat(Netif *nif, Chan *c, char *db)
{
	Dir dir;
	Netfile *f;

	f = nif->f[NETID(c->qid.path)];
	if(f == 0)
		error(Enonexist);

	if(netown(f, up->user, OWRITE) < 0)
		error(Eperm);

	convM2D(db, &dir);
	strncpy(f->owner, dir.uid, NAMELEN);
	f->mode = dir.mode;
}

void
netifstat(Netif *nif, Chan *c, char *db)
{

	devstat(c, db, (Dirtab *)nif, 0, netifgen);
}

void
netifclose(Netif *nif, Chan *c)
{
	Netfile *f;
	int t;

	t = NETTYPE(c->qid.path);
	if(t != Ndataqid && t != Nctlqid)
		return;

	f = nif->f[NETID(c->qid.path)];
	qlock(f);
	if(--(f->inuse) == 0){
		if(f->prom){
			qlock(nif);
			if(--(nif->prom) == 0)
				(*nif->promiscuous)(nif->arg, 0);
			qunlock(nif);
		}
		f->owner[0] = 0;
	}
	qunlock(f);
}

Lock netlock;

static int
netown(Netfile *p, char *o, int omode)
{
	static int access[] = { 0400, 0200, 0600, 0100 };
	int mode;
	int t;

	lock(&netlock);
	if(*p->owner){
		if(strncmp(o, p->owner, NAMELEN) == 0)	/* User */
			mode = p->mode;
		else if(strncmp(o, eve, NAMELEN) == 0)	/* Bootes is group */
			mode = p->mode<<3;
		else
			mode = p->mode<<6;		/* Other */

		t = access[omode&3];
		if((t & mode) == t){
			unlock(&netlock);
			return 0;
		} else {
			unlock(&netlock);
			return -1;
		}
	}
	strncpy(p->owner, o, NAMELEN);
	p->mode = 0660;
	unlock(&netlock);
	return 0;
}

/*
 *  Increment the reference count of a network device.
 *  If id < 0, return an unused ether device.
 */
static int
openfile(Netif *nif, int id)
{
	Netfile *f, **fp, **efp;

	if(id >= 0){
		f = nif->f[id];
		if(f == 0)
			error(Enodev);
		qlock(f);
		f->inuse++;
		qunlock(f);
		return id;
	}

	qlock(nif);
	efp = &nif->f[nif->nfile];
	for(fp = nif->f; fp < efp; fp++){
		f = *fp;
		if(f == 0){
			f = malloc(sizeof(Netfile));
			if(f == 0){
				qunlock(nif);
				error(Enodev);
			}
			*fp = f;
			f->in = qopen(nif->limit, 0, 0);
			qlock(f);
		} else {
			qlock(f);
			if(f->inuse){
				qunlock(f);
				continue;
			}
		}
		f->inuse = 1;
		netown(f, up->user, 0);
		qunlock(f);
		qunlock(nif);
		return fp - nif->f;
	}
	qunlock(nif);
	error(Enodev);
	return -1;	/* not reached */
}

/*
 *  look for a token starting a string, return a pointer to first non-space char after it
 */
static char*
matchtoken(char *p, char *token)
{
	int n;

	n = strlen(token);
	if(strncmp(p, token, n))
		return 0;
	p += n;
	if(*p == 0)
		return p;
	if(*p != ' ' && *p != '\t' && *p != '\n')
		return 0;
	while(*p == ' ' || *p == '\t' || *p == '\n')
		p++;
	return p;
}
.
## diffname port/netif.c 1993/0528
## diff -e /n/fornaxdump/1993/0525/sys/src/brazil/port/netif.c /n/fornaxdump/1993/0528/sys/src/brazil/port/netif.c
348a
		qreopen(f->in);
.
322a
		qreopen(f->in);
.
271a
		f->type = 0;
		qclose(f->in);
.
## diffname port/netif.c 1993/0530
## diff -e /n/fornaxdump/1993/0528/sys/src/brazil/port/netif.c /n/fornaxdump/1993/0530/sys/src/brazil/port/netif.c
342c
			f->in = qopen(nif->limit, 1, 0, 0);
.
27c
	nif->out = qopen(limit, 1, 0, 0);
.
## diffname port/netif.c 1993/0725
## diff -e /n/fornaxdump/1993/0530/sys/src/brazil/port/netif.c /n/fornaxdump/1993/0725/sys/src/brazil/port/netif.c
184,185c
			j += sprint(buf+j, "%2.2ux", nif->addr[i]);
		sprint(buf+j, "\n");
.
175,182c
		j = sprint(buf, "in: %d\n", nif->inpackets);
		j += sprint(buf+j, "out: %d\n", nif->outpackets);
		j += sprint(buf+j, "crc errs: %d\n", nif->crcs);
		j += sprint(buf+j, "overflows: %d\n", nif->overflows);
		j += sprint(buf+j, "framing errs: %d\n", nif->frames);
		j += sprint(buf+j, "buffer errs: %d\n", nif->buffs);
		j += sprint(buf+j, "output errs: %d\n", nif->oerrs);
		j += sprint(buf+j, "addr: ");
.
162d
160a
	int i, j;
.
100c
		devdir(c, q, "stats", 0, eve, 0444, dp);
.
## diffname port/netif.c 1994/0214
## diff -e /n/fornaxdump/1993/0725/sys/src/brazil/port/netif.c /n/fornaxdump/1994/0214/sys/src/brazil/port/netif.c
364c
 *  look for a token starting a string,
 *  return a pointer to first non-space char after it
.
248d
## diffname port/netif.c 1994/0624
## diff -e /n/fornaxdump/1994/0214/sys/src/brazil/port/netif.c /n/fornaxdump/1994/0624/sys/src/brazil/port/netif.c
6d
## diffname port/netif.c 1994/0629
## diff -e /n/fornaxdump/1994/0624/sys/src/brazil/port/netif.c /n/fornaxdump/1994/0629/sys/src/brazil/port/netif.c
266a
			qunlock(nif);
		}
		if(f->type < 0){
			qlock(nif);
			--(nif->all);
.
215a
		if(f->type < 0)
			nif->all++;
.
## diffname port/netif.c 1994/0915
## diff -e /n/fornaxdump/1994/0629/sys/src/brazil/port/netif.c /n/fornaxdump/1994/0915/sys/src/brazil/port/netif.c
257a
	if((c->flag & COPEN) == 0)
		return;

.
## diffname port/netif.c 1995/0112
## diff -e /n/fornaxdump/1994/0915/sys/src/brazil/port/netif.c /n/fornaxdump/1995/0112/sys/src/brazil/port/netif.c
162c
	char buf[512];
.
## diffname port/netif.c 1995/0711
## diff -e /n/fornaxdump/1995/0112/sys/src/brazil/port/netif.c /n/fornaxdump/1995/0711/sys/src/brazil/port/netif.c
177a
		j += sprint(buf+j, "soft overflows: %d\n", nif->soverflows);
.
162c
	char buf[1024];
.
## diffname port/netif.c 1995/0804
## diff -e /n/fornaxdump/1995/0711/sys/src/brazil/port/netif.c /n/fornaxdump/1995/0804/sys/src/brazil/port/netif.c
189a
	case Nifstatqid:
		return 0;
.
104a
	case 4:
		q.path = NETQID(NETID(c->qid.path), Nifstatqid);
		devdir(c, q, "ifstats", 0, eve, 0444, dp);
		break;
.
43d
33c
netifgen(Chan *c, void *vp, int, int i, Dir *dp)
.
## diffname port/netif.c 1995/0808
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/netif.c /n/fornaxdump/1995/0808/sys/src/brazil/port/netif.c
397a

void
hnputl(void *p, ulong v)
{
	uchar *a;

	a = p;
	a[0] = v>>24;
	a[1] = v>>16;
	a[2] = v>>8;
	a[3] = v;
}

void
hnputs(void *p, ushort v)
{
	uchar *a;

	a = p;
	a[0] = v>>8;
	a[1] = v;
}

ulong
nhgetl(void *p)
{
	uchar *a;
	a = p;
	return (a[0]<<24)|(a[1]<<16)|(a[2]<<8)|(a[3]<<0);
}

ushort
nhgets(void *p)
{
	uchar *a;
	a = p;
	return (a[0]<<8)|(a[1]<<0);
}
.
## diffname port/netif.c 1995/1104
## diff -e /n/fornaxdump/1995/0808/sys/src/brazil/port/netif.c /n/fornaxdump/1995/1104/sys/src/brazil/port/netif.c
278a
			f->prom = 0;
.
184a
		j += sprint(buf+j, "prom: %d\n", nif->prom);
.
## diffname port/netif.c 1996/0706
## diff -e /n/fornaxdump/1995/1104/sys/src/brazil/port/netif.c /n/fornaxdump/1996/0706/sys/src/brazil/port/netif.c
26d
## diffname port/netif.c 1997/0327
## diff -e /n/fornaxdump/1996/0706/sys/src/brazil/port/netif.c /n/emeliedump/1997/0327/sys/src/brazil/port/netif.c
433a

.
425a

.
276,277c
			if(--(nif->prom) == 0 && nif->promiscuous != nil)
				nif->promiscuous(nif->arg, 0);
.
227,228c
		if(nif->prom == 1 && nif->promiscuous != nil)
			nif->promiscuous(nif->arg, 1);
.
199a
Block*
netifbread(Netif *nif, Chan *c, long n, ulong offset)
{
	if((c->qid.path & CHDIR) || NETTYPE(c->qid.path) != Ndataqid)
		return devbread(c, n, offset);

	return qbread(nif->f[NETID(c->qid.path)]->in, n);
}

.
21c
	strncpy(nif->name, name, NAMELEN-1);
	nif->name[NAMELEN-1] = 0;
.
9,10d
## diffname port/netif.c 1997/0401
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/netif.c /n/emeliedump/1997/0401/sys/src/brazil/port/netif.c
445a
}

/* called with nif locked */
static void
netmulti(Netif *nif, char *addr, int add)
{
	Netaddr **l, *ap;

	if(nif->multicast == nil)
		return;

	l = &nif->maddr;
	for(ap = *l; ap; ap = *l){
		if(strcmp(addr, ap->addr) == 0)
			break;
		l = &ap->next;
	}

	if(add){
		if(ap == 0){
			ap = smalloc(sizeof(*ap));
			ap->addr = smalloc(strlen(addr)+1);
			strcpy(ap->addr, addr);
			ap->next = nif->maddr;
			ap->ref = 1;
			nif->maddr = ap;
		} else {
			ap->ref++;
		}
		if(ap->ref == 1)
			nif->multicast(nif->arg, addr, 1);
	} else {
		if(ap == 0 || ap->ref == 0)
			return;
		ap->ref--;
		if(ap->ref == 0)
			nif->multicast(nif->arg, addr, 0);
	}
.
236a
	} else if(p = matchtoken(buf, "addmulti")){
		netmulti(nif, p, 1);
	} else if(p = matchtoken(buf, "remmulti")){
		netmulti(nif, p, 0);
.
11a
static void netmulti(Netif*, char*, int);
.
## diffname port/netif.c 1997/0403
## diff -e /n/emeliedump/1997/0401/sys/src/brazil/port/netif.c /n/emeliedump/1997/0403/sys/src/brazil/port/netif.c
487a
		}
		if(i < 8*sizeof(f->maddr)){
			if((f->maddr[i/8] & (1<<(i%8))) != 0)
				f->nmaddr--;
			f->maddr[i/8] &= ~(1<<(i%8));
		}
.
486c
		if(ap->ref == 0){
			nif->nmaddr--;
.
481a
		}
		if(i < 8*sizeof(f->maddr)){
			if((f->maddr[i/8] & (1<<(i%8))) == 0)
				f->nmaddr++;
			f->maddr[i/8] |= 1<<(i%8);
		}
.
480c
		if(ap->ref == 1){
			nif->nmaddr++;
.
476d
474c
			ap->next = 0;
.
471c
			*l = ap = smalloc(sizeof(*ap));
.
465a
		i++;
.
462a
	i = 0;
.
461a
	if(strlen(addr) != 2*nif->alen)
		return;

.
457a
	int i;
	uchar hexaddr[Nmaxaddr];
.
455c
netmulti(Netif *nif, Netfile *f, char *addr, int add)
.
453c
/*
 *  keep track of multicast addresses
 */
.
293a
		if(f->nmaddr){
			qlock(nif);
			t = 0;
			for(ap = nif->maddr; ap; ap = ap->next){
				if(f->maddr[t/8] & (1<<(t%8)))
					netmulti(nif, f, ap->addr, 0);
			}
			qunlock(nif);
			f->nmaddr = 0;
		}
.
275a
	Netaddr *ap;
.
238,241c
	} else if((p = matchtoken(buf, "addmulti")) != 0){
		netmulti(nif, f, p, 1);
	} else if((p = matchtoken(buf, "remmulti")) != 0){
		netmulti(nif, f, p, 0);
.
229c
	if((p = matchtoken(buf, "connect")) != 0){
.
12c
static void netmulti(Netif*, Netfile*, char*, int);
.
## diffname port/netif.c 1997/0404
## diff -e /n/emeliedump/1997/0403/sys/src/brazil/port/netif.c /n/emeliedump/1997/0404/sys/src/brazil/port/netif.c
521a
	return 0;
.
510c
			return 0;
.
495a
			h = hash(addr, nif->alen);
			ap->hnext = nif->mhash[h];
			nif->mhash[h] = ap;
.
492,493c
			memmove(ap->addr, addr, nif->alen);
.
483c
		if(memcmp(addr, ap->addr, nif->alen) == 0)
.
477,479d
475c
		return "interface does not support multicast";
.
472c
	ulong h;
.
467,468c
static char*
netmulti(Netif *nif, Netfile *f, uchar *addr, int add)
.
463a
static ulong
hash(uchar *a, int len)
{
	ulong sum = 0;

	while(len-- > 0)
		sum = (sum << 1) + *a++;
	return sum%Nmhash;
}

int
activemulti(Netif *nif, uchar *addr, int alen)
{
	Netaddr *hp;

	for(hp = nif->mhash[hash(addr, alen)]; hp; hp = hp->hnext)
		if(memcmp(addr, hp->addr, alen) == 0){
			if(hp->ref)
				return 1;
			else
				break;
		}
	return 0;
}

static int
parseaddr(uchar *to, char *from, int alen)
{
	char nip[4];
	char *p;
	int i;

	p = from;
	for(i = 0; i < alen; i++){
		if(*p == 0)
			return -1;
		nip[0] = *p++;
		if(*p == 0)
			return -1;
		nip[1] = *p++;
		nip[2] = 0;
		to[i] = strtoul(nip, 0, 16);
		if(*p == ':')
			p++;
	}
	return 0;
}

.
243a
	poperror();
.
241c
		if(parseaddr(binaddr, p, nif->alen) < 0)
			error("bad address");
		p = netmulti(nif, f, binaddr, 0);
		if(p)
			error(p);
.
239c
		if(parseaddr(binaddr, p, nif->alen) < 0)
			error("bad address");
		p = netmulti(nif, f, binaddr, 1);
		if(p)
			error(p);
.
226a
	if(waserror()){
		qunlock(nif);
		nexterror();
	}

.
217a
	uchar binaddr[Nmaxaddr];
.
12c
static char* netmulti(Netif*, Netfile*, uchar*, int);
static int parseaddr(uchar*, char*, int);
.
## diffname port/netif.c 1997/0417
## diff -e /n/emeliedump/1997/0404/sys/src/brazil/port/netif.c /n/emeliedump/1997/0417/sys/src/brazil/port/netif.c
217,218c
	char *p, buf[64];
.
188,190c
			j += snprint(p+j, READSTR-j, "%2.2ux", nif->addr[i]);
		snprint(p+j, READSTR-j, "\n");
		n = readstr(offset, a, n, p);
		free(p);
		return n;
.
177,186c
		p = malloc(READSTR);
		j = snprint(p, READSTR, "in: %d\n", nif->inpackets);
		j += snprint(p+j, READSTR-j, "out: %d\n", nif->outpackets);
		j += snprint(p+j, READSTR-j, "crc errs: %d\n", nif->crcs);
		j += snprint(p+j, READSTR-j, "overflows: %d\n", nif->overflows);
		j += snprint(p+j, READSTR-j, "soft overflows: %d\n", nif->soverflows);
		j += snprint(p+j, READSTR-j, "framing errs: %d\n", nif->frames);
		j += snprint(p+j, READSTR-j, "buffer errs: %d\n", nif->buffs);
		j += snprint(p+j, READSTR-j, "output errs: %d\n", nif->oerrs);
		j += snprint(p+j, READSTR-j, "prom: %d\n", nif->prom);
		j += snprint(p+j, READSTR-j, "addr: ");
.
165c
	char *p;
.
125a
	id = 0;
.
123c
	int id;
.
## diffname port/netif.c 1997/1105
## diff -e /n/emeliedump/1997/0417/sys/src/brazil/port/netif.c /n/emeliedump/1997/1105/sys/src/brazil/port/netif.c
416d
413a
		poperror();
.
400d
395,397c
			if(f == 0)
				exhausted("memory");
			f->in = qopen(nif->limit, 1, 0, 0);
			if(f->in == nil){
				free(f);
				exhausted("memory");
.
389a
	if(waserror()){
		qunlock(nif);
		nexterror();
	}
.
## diffname port/netif.c 1997/1106
## diff -e /n/emeliedump/1997/1105/sys/src/brazil/port/netif.c /n/emeliedump/1997/1106/sys/src/brazil/port/netif.c
240c
		type = atoi(p);
		if(typeinuse(nif, type))
			error(Einuse);
		f->type = type;
.
220a
	int type;
.
214a
 *  make sure this type isn't already in use on this device
 */
static int
typeinuse(Netif *nif, int type)
{
	Netfile *f, **fp, **efp;

	if(type <= 0)
		return 0;

	efp = &nif->f[nif->nfile];
	for(fp = nif->f; fp < efp; fp++){
		f = *fp;
		if(f == 0)
			continue;
		if(f->type == type)
			return 1;
	}
	return 0;
}

/*
.
## diffname port/netif.c 1997/1208
## diff -e /n/emeliedump/1997/1106/sys/src/brazil/port/netif.c /n/emeliedump/1997/1208/sys/src/brazil/port/netif.c
173a
okchan("before qread", 0);
j = qread(f->in, a, n);
okchan("after qread", j);
return j;
.
## diffname port/netif.c 1998/0221
## diff -e /n/emeliedump/1997/1208/sys/src/brazil/port/netif.c /n/emeliedump/1998/0221/sys/src/brazil/port/netif.c
174,177d
## diffname port/netif.c 1998/0325
## diff -e /n/emeliedump/1998/0221/sys/src/brazil/port/netif.c /n/emeliedump/1998/0325/sys/src/brazil/port/netif.c
494a
}

vlong
nhgetv(void *p)
{
	uchar *a;

	a = p;
	return ((vlong)nhgetl(a) << 32) | nhgetl(a+8);
.
475a
hnputv(void *p, vlong v)
{
	uchar *a;

	a = p;
	hnputl(a, v>>32);
	hnputl(a+8, v);
}

void
.
## diffname port/netif.c 1998/0326
## diff -e /n/emeliedump/1998/0325/sys/src/brazil/port/netif.c /n/emeliedump/1998/0326/sys/src/brazil/port/netif.c
513c
	return ((vlong)nhgetl(a) << 32) | nhgetl(a+4);
.
482c
	hnputl(a+4, v);
.
## diffname port/netif.c 1999/0316
## diff -e /n/emeliedump/1998/0326/sys/src/brazil/port/netif.c /n/emeliedump/1999/0316/sys/src/brazil/port/netif.c
191a
		n = readstr(offset, a, n, p);
		free(p);
		return n;
	case Naddrqid:
		p = malloc(READSTR);
		j = 0;
		for(i = 0; i < nif->alen; i++)
			j += snprint(p+j, READSTR-j, "%2.2ux", nif->addr[i]);
.
71,72c
			break;
		}
.
68,69c
			q.path = CHDIR|NETQID(i, N3rdqid);
			sprint(buf, "%d", i);
.
65,66c
			break;
		case 1:
			q.path = Naddrqid;
			devdir(c, q, "addr", 0, eve, 0666, dp);
			break;
		default:
			i -= 2;
			if(i >= nif->nfile)
				return -1;
			if(nif->f[i] == 0)
.
62c
		switch(i) {
		case 0:
.
## diffname port/netif.c 1999/0320
## diff -e /n/emeliedump/1999/0316/sys/src/brazil/port/netif.c /n/emeliedump/1999/0320/sys/src/brazil/port/netif.c
37c
	Netif *nif = (Netif*)vp;
.
33c
netifgen(Chan *c, Dirtab *vp, int, int i, Dir *dp)
.
## diffname port/netif.c 1999/0625
## diff -e /n/emeliedump/1999/0320/sys/src/brazil/port/netif.c /n/emeliedump/1999/0625/sys/src/brazil/port/netif.c
287,290c
		if(f->prom == 0){
			if(nif->prom == 0 && nif->promiscuous != nil)
				nif->promiscuous(nif->arg, 1);
			f->prom = 1;
			nif->prom++;
		}
	} else if(matchtoken(buf, "bridge")){
		f->bridge = 1;
	} else if(matchtoken(buf, "headersonly")){
		f->headersonly = 1;
.
## diffname port/netif.c 1999/0629
## diff -e /n/emeliedump/1999/0625/sys/src/brazil/port/netif.c /n/emeliedump/1999/0629/sys/src/brazil/port/netif.c
149d
## diffname port/netif.c 1999/0828
## diff -e /n/emeliedump/1999/0629/sys/src/brazil/port/netif.c /n/emeliedump/1999/0828/sys/src/brazil/port/netif.c
61c
	if(t == N2ndqid || t == Ncloneqid || t == Naddrqid){
.
## diffname port/netif.c 1999/1230
## diff -e /n/emeliedump/1999/0828/sys/src/brazil/port/netif.c /n/emeliedump/1999/1230/sys/src/9/port/netif.c
96a
	case DEVDOTDOT:
		q.path = CHDIR | N2ndqid;
		strcpy(buf, nif->name);
		devdir(c, q, buf, 0, eve, CHDIR|0555, dp);
		break;
.
79c
			devdir(c, q, buf, 0, eve, CHDIR|0555, dp);
.
62a
		case DEVDOTDOT:
			q.path = CHDIR;
			devdir(c, q, ".", 0, eve, CHDIR|0555, dp);
			break;
.
51c
			devdir(c, q, buf, 0, eve, CHDIR|0555, dp);
.
47a
		case DEVDOTDOT:
			q.path = CHDIR;
			devdir(c, q, ".", 0, eve, CHDIR|0555, dp);
			break;
.
## diffname port/netif.c 2000/1107
## diff -e /n/emeliedump/1999/1230/sys/src/9/port/netif.c /n/emeliedump/2000/1107/sys/src/9/port/netif.c
321c
	} else
		n = -1;
.
## diffname port/netif.c 2001/0527
## diff -e /n/emeliedump/2000/1107/sys/src/9/port/netif.c /n/emeliedump/2001/0527/sys/src/9/port/netif.c
425c
	strncpy(p->owner, o, KNAMELEN);
.
411c
		else if(strncmp(o, eve, KNAMELEN) == 0)	/* Bootes is group */
.
409c
		if(strncmp(o, p->owner, KNAMELEN) == 0)	/* User */
.
349c
	return devstat(c, db, n, (Dirtab *)nif, 0, netifgen);
.
346,347c
int
netifstat(Netif *nif, Chan *c, uchar *db, int n)
.
341,343c
	dir = smalloc(sizeof(Dir)+n);
	m = convM2D(db, n, &dir[0], (char*)&dir[1]);
	if(m > 0){
		strncpy(f->owner, dir[0].uid, KNAMELEN);
		f->mode = dir[0].mode;
	}
	free(dir);
	return m;
.
332a
	int m;
.
331c
	Dir *dir;
.
328,329c
int
netifwstat(Netif *nif, Chan *c, uchar *db, int n)
.
237c
	if((c->qid.type & QTDIR) || NETTYPE(c->qid.path) != Ndataqid)
.
189c
	if(c->qid.type&QTDIR)
.
149c
	if(c->qid.type & QTDIR){
.
139c
	return devwalk(c, nc, name, nname, (Dirtab *)nif, 0, netifgen);
.
136,137c
Walkqid*
netifwalk(Netif *nif, Chan *c, Chan *nc, char **name, int nname)
.
106,108c
		q.type = QTDIR;
		q.path = N2ndqid;
		strcpy(up->genbuf, nif->name);
		devdir(c, q, up->genbuf, 0, eve, DMDIR|0555, dp);
.
85,87c
			q.type = QTDIR;
			q.path = NETQID(i, N3rdqid);
			sprint(up->genbuf, "%d", i);
			devdir(c, q, up->genbuf, 0, eve, DMDIR|0555, dp);
.
68,69c
			q.type = QTDIR;
			q.path = 0;
			devdir(c, q, ".", 0, eve, DMDIR|0555, dp);
.
53,55c
			q.path = N2ndqid;
			q.type = QTDIR;
			strcpy(up->genbuf, nif->name);
			devdir(c, q, up->genbuf, 0, eve, 0555, dp);
.
49,50c
			q.path = 0;
			q.type = QTDIR;
			devdir(c, q, ".", 0, eve, 0555, dp);
.
46c
	if(c->qid.path == 0){
.
42a
	q.type = QTFILE;
.
36d
33c
netifgen(Chan *c, char*, Dirtab *vp, int, int i, Dir *dp)
.
21,22c
	strncpy(nif->name, name, KNAMELEN-1);
	nif->name[KNAMELEN-1] = 0;
.
## diffname port/netif.c 2001/0610
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/netif.c /n/emeliedump/2001/0610/sys/src/9/port/netif.c
403a
		f->bridge = 0;
		f->headersonly = 0;
.
## diffname port/netif.c 2001/1106
## diff -e /n/emeliedump/2001/0610/sys/src/9/port/netif.c /n/emeliedump/2001/1106/sys/src/9/port/netif.c
352d
350a
	if(dir[0].mode != ~0UL)
.
349c
	if(m == 0){
		free(dir);
		error(Eshortstat);
	}
	if(!emptystr(dir[0].uid))
.
## diffname port/netif.c 2001/1207
## diff -e /n/emeliedump/2001/1106/sys/src/9/port/netif.c /n/emeliedump/2001/1207/sys/src/9/port/netif.c
183a
	c->iounit = qiomaxatomic;
.
## diffname port/netif.c 2002/0711
## diff -e /n/emeliedump/2001/1207/sys/src/9/port/netif.c /n/emeliedump/2002/0711/sys/src/9/port/netif.c
481c
			f->in = qopen(nif->limit, Qmsg, 0, 0);
.
## diffname port/netif.c 2003/0118
## diff -e /n/emeliedump/2002/0711/sys/src/9/port/netif.c /n/emeliedump/2003/0118/sys/src/9/port/netif.c
390a
		}
		if(f->scan){
			qlock(nif);
			if(--(nif->scan) == 0 && nif->scanbs != nil)
				nif->scanbs(nif->arg, 0);
			qunlock(nif);
			f->prom = 0;
			f->scan = 0;
.
310a
	} else if((p = matchtoken(buf, "scanbs")) != 0){
		/* scan for base stations */
		if(f->scan == 0){
			type = atoi(p);
			if(type < 5)
				type = 5;
			if(nif->scanbs != nil)
				nif->scanbs(nif->arg, type);
			f->scan = type;
			nif->scan++;
		}
.
## diffname port/netif.c 2003/0209
## diff -e /n/emeliedump/2003/0118/sys/src/9/port/netif.c /n/emeliedump/2003/0209/sys/src/9/port/netif.c
214a
		j += snprint(p+j, READSTR-j, "mbps: %d\n", nif->mbps);
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.