From d501ab3217b98e69bd64a30fd59c94a78da7218b Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 5 Oct 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-10-05 --- ip/ip.h | 1 + ip/ipifc.c | 54 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/ip/ip.h b/ip/ip.h index 4b9f00d7f96b16c9a6aa3a30cb8c713848f39a37..21cdb87e09e1597161adaa123243e303bf563414 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -459,6 +459,7 @@ extern int ipforme(Fs*, uchar *addr); extern int ipisbm(uchar *); extern int ipismulticast(uchar *); extern Ipifc* findipifc(Fs*, uchar *remote, int type); +extern void findprimaryip(Fs*, uchar*); extern void findlocalip(Fs*, uchar *local, uchar *remote); extern int ipv4local(Ipifc *ifc, uchar *addr); extern int ipv6local(Ipifc *ifc, uchar *addr); diff --git a/ip/ipifc.c b/ip/ipifc.c index d2aa3d66e74de0b546fc3778134abd874ebad31c..27b89ee1df90d3cce88bc68b67f4427b8c46c6a5 100644 --- a/ip/ipifc.c +++ b/ip/ipifc.c @@ -216,6 +216,8 @@ ipifcstate(Conv *c, char *state, int n) " %-20.20I %-20.20M %-20.20I %-7lud %-7lud %-7lud %-7lud\n", lifc->local, lifc->mask, lifc->remote, ifc->in, ifc->out, ifc->inerr, ifc->outerr); + if(ifc->lifc == nil) + m += snprint(state+m, n - m, "\n"); runlock(ifc); return m; } @@ -394,8 +396,12 @@ ipifcadd(Ipifc *ifc, char **argv, int argc) /* add a route for the local network */ type = Rifc; - if(ipcmp(mask, IPallbits) == 0) + if(ipcmp(mask, IPallbits) == 0){ + /* point to point networks are a hack */ + if(ipcmp(ip, rem) == 0) + findprimaryip(f, lifc->local); type |= Rptpt; + } if(isv4(ip)) v4addroute(f, tifc, rem+IPv4off, mask+IPv4off, ip+IPv4off, type); else @@ -403,6 +409,9 @@ ipifcadd(Ipifc *ifc, char **argv, int argc) addselfcache(f, ifc, lifc, ip, Runi); + if(type & Rptpt) + goto out; + /* add subnet directed broadcast addresses to the self cache */ for(i = 0; i < IPaddrlen; i++) bcast[i] = (ip[i] & mask[i]) | ~mask[i]; @@ -947,6 +956,29 @@ findipifc(Fs *f, uchar *remote, int type) return nil; } +/* + * returns first ip address configured + */ +void +findprimaryip(Fs *f, uchar *local) +{ + Conv **cp, **e; + Ipifc *ifc; + Iplifc *lifc; + + /* find first ifc local address */ + e = &f->ipifc->conv[f->ipifc->nc]; + for(cp = f->ipifc->conv; cp < e; cp++){ + if(*cp == 0) + continue; + ifc = (Ipifc*)(*cp)->ptcl; + for(lifc = ifc->lifc; lifc; lifc = lifc->next){ + ipmove(local, lifc->local); + return; + } + } +} + /* * find the local address 'closest' to the remote system, copy it to * local and return the ifc for that address @@ -956,7 +988,6 @@ findlocalip(Fs *f, uchar *local, uchar *remote) { Ipifc *ifc; Iplifc *lifc; - Conv **cp, **e; Route *r; uchar gate[IPaddrlen]; uchar gnet[IPaddrlen]; @@ -971,11 +1002,6 @@ findlocalip(Fs *f, uchar *local, uchar *remote) else ipmove(gate, r->v6.gate); - if(r->type & Rifc){ - ipmove(local, gate); - goto out; - } - /* find ifc address closest to the gateway to use */ for(lifc = ifc->lifc; lifc; lifc = lifc->next){ maskip(gate, lifc->mask, gnet); @@ -985,18 +1011,8 @@ findlocalip(Fs *f, uchar *local, uchar *remote) } } } - - /* no match, choose first ifc local address */ - e = &f->ipifc->conv[f->ipifc->nc]; - for(cp = f->ipifc->conv; cp < e; cp++){ - if(*cp == 0) - continue; - ifc = (Ipifc*)(*cp)->ptcl; - for(lifc = ifc->lifc; lifc; lifc = lifc->next){ - ipmove(local, lifc->local); - goto out; - } - } + + findprimaryip(f, local); out: qunlock(f->ipifc);