ref: cce5422e79699bc71e6525d77dfc3d8a9f5b1b9d
parent: dc6772fccc90d90c700eb679b9dfcde4a71fc8cb
author: cinap_lenrek <[email protected]>
date: Thu Feb 14 21:16:31 EST 2019
ip/tinc: fix mistake from previous commit
--- a/sys/src/cmd/ip/tinc.c
+++ b/sys/src/cmd/ip/tinc.c
@@ -63,8 +63,9 @@
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 @@
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 @@
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 @@
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;