From 42a7de39f49444aa5f17242383221b8fa90ee549 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 6 Nov 1997 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1997-11-06 --- port/netif.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/port/netif.c b/port/netif.c index 6af9bb38b5a11b518b8f93371b179276bc02a401..75e65aff7f256a5e078a3fd9b26f496737bf312c 100644 --- a/port/netif.c +++ b/port/netif.c @@ -211,6 +211,28 @@ netifbread(Netif *nif, Chan *c, long n, ulong offset) return qbread(nif->f[NETID(c->qid.path)]->in, n); } +/* + * 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; +} + /* * the devxxx.c that calls us handles writing data, it knows best */ @@ -218,6 +240,7 @@ long netifwrite(Netif *nif, Chan *c, void *a, long n) { Netfile *f; + int type; char *p, buf[64]; uchar binaddr[Nmaxaddr]; @@ -237,7 +260,10 @@ netifwrite(Netif *nif, Chan *c, void *a, long n) qlock(nif); f = nif->f[NETID(c->qid.path)]; if((p = matchtoken(buf, "connect")) != 0){ - f->type = atoi(p); + type = atoi(p); + if(typeinuse(nif, type)) + error(Einuse); + f->type = type; if(f->type < 0) nif->all++; } else if(matchtoken(buf, "promiscuous")){