commit d3d795868cb6ad9a86b9499d50e7a604cc399f6b Author: lufia Date: Tue Sep 22 20:57:30 2020 +0900 sys/src/9/ip: direct attached network diff --git a/sys/src/9/ip/ip.c b/sys/src/9/ip/ip.c index 098e46f56..3b0cab82e 100644 --- a/sys/src/9/ip/ip.c +++ b/sys/src/9/ip/ip.c @@ -129,6 +129,7 @@ ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c) Route *r, *sr; IP *ip; int rv = 0; + uchar v4dst[IPv4addrlen]; ip = f->ip; @@ -169,7 +170,11 @@ ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c) gate = eh->dst; else if(r->type & (Rbcast|Rmulti)) { - gate = eh->dst; + if(nhgetl(r->v4.gate) == 0){ + hnputl(v4dst, r->v4.address); + gate = v4dst; + }else + gate = eh->dst; sr = v4lookup(f, eh->src, nil); if(sr != nil && (sr->type & Runi)) ifc = sr->ifc; diff --git a/sys/src/9/ip/iproute.c b/sys/src/9/ip/iproute.c index e7646c72e..70c816429 100644 --- a/sys/src/9/ip/iproute.c +++ b/sys/src/9/ip/iproute.c @@ -493,6 +493,7 @@ v4lookup(Fs *f, uchar *a, Conv *c) return c->r; la = nhgetl(a); +again: q = nil; for(p=f->v4root[V4H(la)]; p;) if(la >= p->v4.address) { @@ -511,8 +512,14 @@ v4lookup(Fs *f, uchar *a, Conv *c) } else v4tov6(gate, q->v4.gate); ifc = findipifc(f, gate, q->type); - if(ifc == nil) + if(ifc == nil){ + /* find a direct attached route */ + if(q->v4.address == 0 && q->v4.endaddress == ~0){ + la = nhgetl(q->v4.gate); + goto again; + } return nil; + } q->ifc = ifc; q->ifcid = ifc->ifcid; } @@ -817,6 +824,7 @@ routewrite(Fs *f, Chan *c, char *p, int n) uchar gate[IPaddrlen]; IPaux *a, *na; Route *q; + uchar type; cb = parsecmd(p, n); if(waserror()){ @@ -863,9 +871,12 @@ routewrite(Fs *f, Chan *c, char *p, int n) a = c->aux; tag = a->tag; } - if(memcmp(addr, v4prefix, IPv4off) == 0) - v4addroute(f, tag, addr+IPv4off, mask+IPv4off, gate+IPv4off, 0); - else + if(memcmp(addr, v4prefix, IPv4off) == 0){ + type = 0; + if(ipcmp(mask, IPallbits) == 0) + type = Rbcast; + v4addroute(f, tag, addr+IPv4off, mask+IPv4off, gate+IPv4off, type); + }else v6addroute(f, tag, addr, mask, gate, 0); } else if(strcmp(cb->f[0], "tag") == 0) { if(cb->nf < 2)