X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fsubnet.c;h=cb9cbb75e345e12952f5ac384e1008d859733226;hp=51b1cd7a3158677a13d43e8c344ac78aabad0a81;hb=8b5e4211304aaa5d39bc95f04398bd5ecaa887d8;hpb=0a3c8cefd4a154948799baaaa246cf0eba050eff diff --git a/src/subnet.c b/src/subnet.c index 51b1cd7a..cb9cbb75 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -17,13 +17,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: subnet.c,v 1.1.2.19 2001/06/01 08:02:09 guus Exp $ + $Id: subnet.c,v 1.1.2.24 2001/08/28 20:52:39 guus Exp $ */ #include "config.h" #include #include +#include #include "conf.h" #include "net.h" @@ -60,9 +61,23 @@ cp /* We compare as if a subnet is a number that equals (address << 32 + netmask). */ if(a->net.ipv4.address == b->net.ipv4.address) - return a->net.ipv4.mask - b->net.ipv4.mask; + { + if(a->net.ipv4.mask < b->net.ipv4.mask) + return -1; + else if(a->net.ipv4.mask > b->net.ipv4.mask) + return 1; + else + return 0; + } else - return a->net.ipv4.address - b->net.ipv4.address; + { + if(a->net.ipv4.address < b->net.ipv4.address) + return -1; + else if(a->net.ipv4.address > b->net.ipv4.address) + return 1; + else + return 0; + } } int subnet_compare_ipv6(subnet_t *a, subnet_t *b) @@ -127,7 +142,25 @@ void subnet_add(connection_t *cl, subnet_t *subnet) { cp subnet->owner = cl; - avl_insert(subnet_tree, subnet); + + while(!avl_insert(subnet_tree, subnet)) + { + subnet_t *old; + + old = (subnet_t *)avl_search(subnet_tree, subnet); + + if(debug_lvl >= DEBUG_PROTOCOL) + { + char *subnetstr; + subnetstr = net2str(subnet); + syslog(LOG_WARNING, _("Duplicate subnet %s for %s (%s), previous owner %s (%s)!"), + subnetstr, cl->name, cl->hostname, old->owner->name, old->owner->hostname); + free(subnetstr); + } + + subnet_del(old); + } + avl_insert(cl->subnet_tree, subnet); cp } @@ -244,7 +277,7 @@ cp subnet->net.ipv6.mask.x[7]); break; default: - asprintf(&netstr, _("unknown")); + asprintf(&netstr, _("unknown subnet type")); } cp return netstr; @@ -289,7 +322,7 @@ cp /* Otherwise, see if there is a bigger enclosing subnet */ subnet.net.ipv4.mask = p->net.ipv4.mask << 1; - subnet.net.ipv4.address &= subnet.net.ipv4.mask; + subnet.net.ipv4.address = p->net.ipv4.address & subnet.net.ipv4.mask; } } } while (p);