changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: ip/tinc: fix mistake from previous commit

changeset 7037: 5e221ac3a3f6
parent 7036: 7bb53313aac9
child 7038: ba424de99a20
author: cinap_lenrek@felloff.net
date: Fri, 15 Feb 2019 02:16:31 +0100
files: sys/src/cmd/ip/tinc.c
description: ip/tinc: fix mistake from previous commit
     1.1--- a/sys/src/cmd/ip/tinc.c
     1.2+++ b/sys/src/cmd/ip/tinc.c
     1.3@@ -63,8 +63,9 @@ struct Snet
     1.4 	Host	*owner;
     1.5 
     1.6 	Snet	*next;	/* next subnet on owner */
     1.7+	uchar	ip[IPaddrlen];
     1.8 	uchar	mask[IPaddrlen];
     1.9-	uchar	ip[IPaddrlen];
    1.10+	int	prefixlen;
    1.11 	int	weight;
    1.12 	char	reported;
    1.13 	char	deleted;
    1.14@@ -345,11 +346,11 @@ reportsubnet(Conn *c, Snet *t)
    1.15 	if(t->owner == c->host)
    1.16 		return;
    1.17 	if(t->deleted)
    1.18-		consend(c, "%d %x %s %I %M #%d", DEL_SUBNET, rand(),
    1.19-			t->owner->name, t->ip, t->mask, t->weight);
    1.20+		consend(c, "%d %x %s %I/%d#%d", DEL_SUBNET, rand(),
    1.21+			t->owner->name, t->ip, t->prefixlen, t->weight);
    1.22 	else
    1.23-		consend(c, "%d %x %s %I %M #%d", ADD_SUBNET, rand(), t->owner->name,
    1.24-			t->ip, t->mask, t->weight);
    1.25+		consend(c, "%d %x %s %I/%d#%d", ADD_SUBNET, rand(), t->owner->name,
    1.26+			t->ip, t->prefixlen, t->weight);
    1.27 }
    1.28 void
    1.29 reportedge(Conn *c, Edge *e)
    1.30@@ -459,12 +460,18 @@ Snet*
    1.31 getsubnet(Host *h, char *s, int new)
    1.32 {
    1.33 	uchar ip[IPaddrlen], mask[IPaddrlen];
    1.34-	int weight;
    1.35+	int weight, prefixlen;
    1.36 	Snet *t;
    1.37 
    1.38 	if(parseipandmask(ip, mask, s, strchr(s, '/')) == -1)
    1.39 		return nil;
    1.40 
    1.41+	for(prefixlen = 0; prefixlen < 128; prefixlen++)
    1.42+		if((mask[prefixlen/8] & (0x80 >> (prefixlen%8))) == 0)
    1.43+			break;
    1.44+	if(isv4(ip))
    1.45+		prefixlen -= 96;
    1.46+
    1.47 	maskip(ip, mask, ip);
    1.48 
    1.49 	weight = 10;
    1.50@@ -486,6 +493,7 @@ if(debug) fprint(2, "%s adding subnet: %
    1.51 	t = emalloc(sizeof(Snet));
    1.52 	ipmove(t->ip, ip);
    1.53 	ipmove(t->mask, mask);
    1.54+	t->prefixlen = prefixlen;
    1.55 	t->weight = weight;
    1.56 	t->owner = h;
    1.57 	t->next = h->snet;