From e9d6c923d8a2faac4e5336243de8e4a6c453108a Mon Sep 17 00:00:00 2001 From: rdujardin Date: Tue, 26 Jul 2016 18:23:31 +0200 Subject: [PATCH] Fix problem of reverse export with prefixes included in bigger ones --- netbox/ipam/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 759b7bfeb..c5d87a5ad 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -350,10 +350,17 @@ class Prefix(CreatedUpdatedModel): pslash = int(str(self.prefix).split('/')[1]) if pslash > 16: + pbytes[3]='0' zslash = 24 + largerPrefix = Prefix.objects.filter(family=4, prefix__net_contains_or_equals=pbytes[0]+'.'+pbytes[1]+'.0.0/16') + if largerPrefix: + pbytes[2]='0' + zslash = 16 else: + pbytes[2]='0' zslash = 16 + if pslash > zslash: pslash = zslash @@ -387,6 +394,18 @@ class Prefix(CreatedUpdatedModel): pslash = int(str(self.prefix).split('/')[1]) zslash = pslash if pslash % 16 == 0 else pslash/16+16 + pnibbles = pnibbles[:zslash/16] + ['0000'] * (8 - zslash/16) + + largerPrefix = Prefix.objects.filter(family=6, prefix__net_contains_or_equals=':'.join(pnibbles)+'/'+str(zslash)) + if largerPrefix: + #choper le plus grand + minSlash = 128 + for pp in largerPrefix: + ppslash = int(str(pp.prefix).split('/')[1]) + if ppslash < minSlash: + minSlash = ppslash + zslash = minSlash + pnibbles = pnibbles[:zslash/16] + ['0000'] * (8 - zslash/16) for ip in ipaddresses: if ip.hostname: