Browse Source

FD3-805 ip range validation in pool that prevents overlap with others pool

Guillermo Espinoza 6 years ago
parent
commit
028e2ec15a

+ 12 - 0
src/IPv4Bundle/Entity/Pool.php

@@ -246,6 +246,18 @@ class Pool implements TenancyIdTraitInterface, WorkflowInterface
             if (!IpUtils::checkIp($this->firstIp, $this->subNet->getAddress()) || !IpUtils::checkIp($this->lastIp, $this->subNet->getAddress())) {
                 $context->addViolation('pool.ips.outrange');
             }
+
+            foreach ($this->subNet->getIpPool() as $pool) {
+                if ($pool->getId() != $this->id) {
+                    $poolFirstIP = ip2long($pool->getFirstIp());
+                    $poolLastIP = ip2long($pool->getLastIp());
+                    $firstIP = ip2long($this->firstIp);
+                    $lastIP = ip2long($this->lastIp);
+                    if (($poolFirstIP <= $firstIP && $poolLastIP >= $firstIP) || ($poolFirstIP <= $lastIP && $poolLastIP >= $lastIP)) {
+                        $context->addViolation('pool.ips.invalid.range', ['%name%' => $pool->getName()]);
+                    }
+                }
+            }
         }
     }
 

+ 1 - 0
src/IPv4Bundle/Resources/translations/validators.es.yml

@@ -2,3 +2,4 @@ pool.lastip.error: La última ip debe ser mayor a la primera ip
 pool.ips.outrange: La primera ip y la última ip deben pertenecer a la subred
 subnet.address.error: La dirección no posee el formato adecuado
 You must specify at least one relay IP address: Debe especificar al menos un relay IP address
+pool.ips.invalid.range: Rango inválido. Se superpone al pool "%name%"