diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-02-15 02:16:31 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-02-15 02:16:31 +0100 |
commit | cce5422e79699bc71e6525d77dfc3d8a9f5b1b9d (patch) | |
tree | d93a7e765ffb05add45ff207ad951edb7a2dcb44 /sys/src/cmd/ip | |
parent | dc6772fccc90d90c700eb679b9dfcde4a71fc8cb (diff) |
ip/tinc: fix mistake from previous commit
Diffstat (limited to 'sys/src/cmd/ip')
-rw-r--r-- | sys/src/cmd/ip/tinc.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sys/src/cmd/ip/tinc.c b/sys/src/cmd/ip/tinc.c index 5da6e989d..b114ed2c0 100644 --- a/sys/src/cmd/ip/tinc.c +++ b/sys/src/cmd/ip/tinc.c @@ -63,8 +63,9 @@ struct Snet Host *owner; Snet *next; /* next subnet on owner */ - uchar mask[IPaddrlen]; uchar ip[IPaddrlen]; + uchar mask[IPaddrlen]; + int prefixlen; int weight; char reported; char deleted; @@ -345,11 +346,11 @@ reportsubnet(Conn *c, Snet *t) if(t->owner == c->host) return; if(t->deleted) - consend(c, "%d %x %s %I %M #%d", DEL_SUBNET, rand(), - t->owner->name, t->ip, t->mask, t->weight); + consend(c, "%d %x %s %I/%d#%d", DEL_SUBNET, rand(), + t->owner->name, t->ip, t->prefixlen, t->weight); else - consend(c, "%d %x %s %I %M #%d", ADD_SUBNET, rand(), t->owner->name, - t->ip, t->mask, t->weight); + consend(c, "%d %x %s %I/%d#%d", ADD_SUBNET, rand(), t->owner->name, + t->ip, t->prefixlen, t->weight); } void reportedge(Conn *c, Edge *e) @@ -459,12 +460,18 @@ Snet* getsubnet(Host *h, char *s, int new) { uchar ip[IPaddrlen], mask[IPaddrlen]; - int weight; + int weight, prefixlen; Snet *t; if(parseipandmask(ip, mask, s, strchr(s, '/')) == -1) return nil; + for(prefixlen = 0; prefixlen < 128; prefixlen++) + if((mask[prefixlen/8] & (0x80 >> (prefixlen%8))) == 0) + break; + if(isv4(ip)) + prefixlen -= 96; + maskip(ip, mask, ip); weight = 10; @@ -486,6 +493,7 @@ if(debug) fprint(2, "%s adding subnet: %I %M #%d\n", h->name, ip, mask, weight); t = emalloc(sizeof(Snet)); ipmove(t->ip, ip); ipmove(t->mask, mask); + t->prefixlen = prefixlen; t->weight = weight; t->owner = h; t->next = h->snet; |