Fix gcc 3.0 warnings.
[tinc] / src / subnet.c
index 51b1cd7..ade4765 100644 (file)
     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.23 2001/06/29 13:09:55 guus Exp $
 */
 
 #include "config.h"
 
 #include <stdio.h>
 #include <syslog.h>
+#include <string.h>
 
 #include "conf.h"
 #include "net.h"
@@ -127,7 +128,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 +263,7 @@ cp
                    subnet->net.ipv6.mask.x[7]);
         break;
       default:
-        asprintf(&netstr, _("unknown"));
+        asprintf(&netstr, _("unknown subnet type"));
     }
 cp
   return netstr;
@@ -289,7 +308,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);