plan 9 kernel history: overview | file list | diff list

1997/0403/port/netif.c (diff list | history)

1997/0401/sys/src/9/port/netif.c:9,151997/0403/sys/src/9/port/netif.c:9,15 (short | long | prev | next)
1993/0525    
static int netown(Netfile*, char*, int); 
static int openfile(Netif*, int); 
static char* matchtoken(char*, char*); 
1997/0401    
static void netmulti(Netif*, char*, int); 
1997/0403    
static void netmulti(Netif*, Netfile*, char*, int); 
1993/0525    
 
/* 
 *  set up a new network interface 
1997/0401/sys/src/9/port/netif.c:226,2321997/0403/sys/src/9/port/netif.c:226,232
1993/0525    
 
	qlock(nif); 
	f = nif->f[NETID(c->qid.path)]; 
	if(p = matchtoken(buf, "connect")){ 
1997/0403    
	if((p = matchtoken(buf, "connect")) != 0){ 
1993/0525    
		f->type = atoi(p); 
1994/0629    
		if(f->type < 0) 
			nif->all++; 
1997/0401/sys/src/9/port/netif.c:235,2441997/0403/sys/src/9/port/netif.c:235,244
1993/0525    
		nif->prom++; 
1997/0327    
		if(nif->prom == 1 && nif->promiscuous != nil) 
			nif->promiscuous(nif->arg, 1); 
1997/0401    
	} else if(p = matchtoken(buf, "addmulti")){ 
		netmulti(nif, p, 1); 
	} else if(p = matchtoken(buf, "remmulti")){ 
		netmulti(nif, p, 0); 
1997/0403    
	} else if((p = matchtoken(buf, "addmulti")) != 0){ 
		netmulti(nif, f, p, 1); 
	} else if((p = matchtoken(buf, "remmulti")) != 0){ 
		netmulti(nif, f, p, 0); 
1993/0525    
	} 
	qunlock(nif); 
	return n; 
1997/0401/sys/src/9/port/netif.c:273,2781997/0403/sys/src/9/port/netif.c:273,279
1993/0525    
{ 
	Netfile *f; 
	int t; 
1997/0403    
	Netaddr *ap; 
1993/0525    
 
1994/0915    
	if((c->flag & COPEN) == 0) 
		return; 
1997/0401/sys/src/9/port/netif.c:291,2961997/0403/sys/src/9/port/netif.c:292,307
1994/0629    
			qunlock(nif); 
1995/1104    
			f->prom = 0; 
1994/0629    
		} 
1997/0403    
		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; 
		} 
1994/0629    
		if(f->type < 0){ 
			qlock(nif); 
			--(nif->all); 
1997/0401/sys/src/9/port/netif.c:450,4891997/0403/sys/src/9/port/netif.c:461,522
1995/0808    
	return (a[0]<<8)|(a[1]<<0); 
1997/0401    
} 
 
/* called with nif locked */ 
1997/0403    
/* 
 *  keep track of multicast addresses 
 */ 
1997/0401    
static void 
netmulti(Netif *nif, char *addr, int add) 
1997/0403    
netmulti(Netif *nif, Netfile *f, char *addr, int add) 
1997/0401    
{ 
	Netaddr **l, *ap; 
1997/0403    
	int i; 
	uchar hexaddr[Nmaxaddr]; 
1997/0401    
 
	if(nif->multicast == nil) 
		return; 
 
1997/0403    
	if(strlen(addr) != 2*nif->alen) 
		return; 
 
1997/0401    
	l = &nif->maddr; 
1997/0403    
	i = 0; 
1997/0401    
	for(ap = *l; ap; ap = *l){ 
		if(strcmp(addr, ap->addr) == 0) 
			break; 
1997/0403    
		i++; 
1997/0401    
		l = &ap->next; 
	} 
 
	if(add){ 
		if(ap == 0){ 
			ap = smalloc(sizeof(*ap)); 
1997/0403    
			*l = ap = smalloc(sizeof(*ap)); 
1997/0401    
			ap->addr = smalloc(strlen(addr)+1); 
			strcpy(ap->addr, addr); 
			ap->next = nif->maddr; 
1997/0403    
			ap->next = 0; 
1997/0401    
			ap->ref = 1; 
			nif->maddr = ap; 
		} else { 
			ap->ref++; 
		} 
		if(ap->ref == 1) 
1997/0403    
		if(ap->ref == 1){ 
			nif->nmaddr++; 
1997/0401    
			nif->multicast(nif->arg, addr, 1); 
1997/0403    
		} 
		if(i < 8*sizeof(f->maddr)){ 
			if((f->maddr[i/8] & (1<<(i%8))) == 0) 
				f->nmaddr++; 
			f->maddr[i/8] |= 1<<(i%8); 
		} 
1997/0401    
	} else { 
		if(ap == 0 || ap->ref == 0) 
			return; 
		ap->ref--; 
		if(ap->ref == 0) 
1997/0403    
		if(ap->ref == 0){ 
			nif->nmaddr--; 
1997/0401    
			nif->multicast(nif->arg, addr, 0); 
1997/0403    
		} 
		if(i < 8*sizeof(f->maddr)){ 
			if((f->maddr[i/8] & (1<<(i%8))) != 0) 
				f->nmaddr--; 
			f->maddr[i/8] &= ~(1<<(i%8)); 
		} 
1997/0401    
	} 
1995/0808    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)