From 1dc21e5bc59f78e94690237bddd81ce8bac58369 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Fri, 19 Sep 2014 14:37:48 -0500 Subject: [PATCH] gmap: Limit new IPv4 nodes to a class-b private network * 172 is generally used for auto-config... so it fits well with the ad-hoc mesh nature of Netsukuku * IPv6 could be limited to a uni-cast local address as well. --- src/gmap.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/gmap.c b/src/gmap.c index 4dad050..74974ad 100644 --- a/src/gmap.c +++ b/src/gmap.c @@ -572,11 +572,31 @@ random_ip(inet_prefix * ipstart, int final_level, int final_gid, for (;;) { /* * Let's choose a completely random ip. + * New gnodes are limited to: + * IPv4: 172.16.0.0/12 + * IPv6: fe6e:746b::/32 */ levels = total_levels; - if (my_family == AF_INET) - idata[0] = rand(); - else { + if (my_family == AF_INET) { + int i = 0; + while (i < 4) { + int octet = 0; + switch (i) { + case 0: + octet = 172; + break; + case 1: + octet = (rand() % (31-16)) + 16; + break; + default: + octet = rand() % 255; + break; + } + idata[0] |= (octet << (i * 8)); + i++; + } + } else { + // TODO: Generate a random address in fe6e:746b::/32 idata[0] = rand(); idata[1] = rand(); idata[2] = rand();