Add check for IPv6 aswell

This commit is contained in:
otthorn 2021-04-18 02:47:01 +02:00
parent 0a01989fc6
commit e789a1a891

View file

@ -13,5 +13,16 @@ def zone_is_subset(re2o_reverse_zone, network):
>>> zone_is_subset(zone, net1) >>> zone_is_subset(zone, net1)
True True
""" """
if network.version == 4:
return all(ipaddress.ip_network(n).subnet_of(network) for n in return all(ipaddress.ip_network(n).subnet_of(network) for n in
zone["cidrs"]) re2o_reverse_zone["cidrs"])
elif network.version == 6:
if re2o_reverse_zone["prefix_v6"]:
ipv6_prefix = re2o_reverse_zone["prefix_v6"]
ipv6_prefix_length = re2o_reverse_zone["prefix_v6_length"]
net6 = ipaddress.ip_network(f"{ipv6_prefix}/{ipv6_prefix_length}")
return net6.subnet_of(network)
else:
return False