|
@@ -8,6 +8,11 @@ use KeaBundle\Interfaces\KeaConfigInterface;
|
|
|
class BaseKea implements KeaConfigInterface
|
|
|
{
|
|
|
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ private $shared_networks = [];
|
|
|
+
|
|
|
/**
|
|
|
* @var array
|
|
|
*/
|
|
@@ -72,6 +77,11 @@ class BaseKea implements KeaConfigInterface
|
|
|
*/
|
|
|
public function getConfig($data = array(), $logging = false)
|
|
|
{
|
|
|
+ $this->classes = [];
|
|
|
+ if (isset($data['shared-networks'])) {
|
|
|
+ $this->sharedNetworksConfig($data['shared-networks'], $data['reservations']);
|
|
|
+ }
|
|
|
+
|
|
|
if (isset($data['subnets'])) {
|
|
|
$this->subnetConfig($data['subnets'], $data['reservations']);
|
|
|
}
|
|
@@ -90,6 +100,7 @@ class BaseKea implements KeaConfigInterface
|
|
|
'lease-database' => $this->leaseDatabaseConfig($data),
|
|
|
'hosts-database' => $this->leaseDatabaseConfig($data),
|
|
|
'client-classes' => $this->client_classes,
|
|
|
+ 'shared-networks' => $this->shared_networks,
|
|
|
'subnet4' => $this->subnet4,
|
|
|
'hooks-libraries' => $this->hooks_libraries,
|
|
|
'interfaces-config' => $this->getInterfacesConfig(),
|
|
@@ -98,13 +109,137 @@ class BaseKea implements KeaConfigInterface
|
|
|
))], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $subnets
|
|
|
+ */
|
|
|
+ private function sharedNetworksConfig($subnets, $reservations)
|
|
|
+ {
|
|
|
+ $sharedNetwork = [
|
|
|
+ 'name' => 'shared-network-',
|
|
|
+ 'option-data' => [],
|
|
|
+ 'subnet4' => [],
|
|
|
+ ];
|
|
|
+ $hostType = $netGroup = $status = null;
|
|
|
+ if (isset($subnets[0])) {
|
|
|
+ $hostType = $subnets[0]->getAllowedHostType();
|
|
|
+ $netGroup = $subnets[0]->getNetGroup();
|
|
|
+ $status = $subnets[0]->getStatus();
|
|
|
+ $sharedNetworkTmp = $sharedNetwork;
|
|
|
+ $sharedNetworkTmp['name'] = $sharedNetworkTmp['name'] . 1;
|
|
|
+ $sharedNetworkTmp['relay'] = $this->getOptionDataSharedNetwork($subnets[0]);
|
|
|
+ $sharedNetworkTmp['subnet4'][] = $this->getSubnetSharedNetwork($subnets[0], $reservations);
|
|
|
+ unset($subnets[0]);
|
|
|
+ }
|
|
|
+ foreach ($subnets as $subnet) {
|
|
|
+ if ($subnet->getAllowedHostType() != $hostType &&
|
|
|
+ $subnet->getNetGroup() != $netGroup &&
|
|
|
+ $subnet->getStatus() != $status) {
|
|
|
+
|
|
|
+ $this->shared_networks[] = $sharedNetworkTmp;
|
|
|
+
|
|
|
+ $hostType = $subnet->getAllowedHostType();
|
|
|
+ $netGroup = $subnet->getNetGroup();
|
|
|
+ $status = $subnet->getStatus();
|
|
|
+
|
|
|
+ $sharedNetworkTmp = $sharedNetwork;
|
|
|
+ $sharedNetworkTmp['name'] = $sharedNetworkTmp['name'] . count($this->shared_networks) + 1;
|
|
|
+ $sharedNetworkTmp['relay'] = $this->getOptionDataSharedNetwork($subnet);
|
|
|
+ }
|
|
|
+ $sharedNetworkTmp['subnet4'][] = $this->getSubnetSharedNetwork($subnet, $reservations);
|
|
|
+ }
|
|
|
+ $this->shared_networks[] = $sharedNetworkTmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param SubNet $subnet
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getOptionDataSharedNetwork($subnet)
|
|
|
+ {
|
|
|
+ $netgroup = $subnet->getNetGroup();
|
|
|
+ if ($netgroup && count($netgroup->getRelay())) {
|
|
|
+ $relay = [];
|
|
|
+ foreach ($netgroup->getRelay() as $ip) {
|
|
|
+ $relay[] = $ip;
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'ip-addresses' => $relay,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param SubNet $subnet
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getSubnetSharedNetwork($subnet, $reservations)
|
|
|
+ {
|
|
|
+ $pools = [];
|
|
|
+ foreach ($subnet->getIpPool() as $pool) {
|
|
|
+ // only add non static pools
|
|
|
+ if ($pool->getIsStatic() == false) {
|
|
|
+ $pools[] = [
|
|
|
+ 'pool' => $pool->getFirstIp() . ' - ' . $pool->getLastIp(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $hostType = $subnet->getAllowedHostType();
|
|
|
+ $client_class = 'cm';
|
|
|
+ if ($hostType != 'Cablemodem') {
|
|
|
+ $client_class = $hostType->getShortname();
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($subnet->getStatus() as $status) {
|
|
|
+ if ($status != HostStatus::STATE_NONE) {
|
|
|
+ $client_class .= '-' . $status;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $subnetConf = [
|
|
|
+ 'subnet' => $subnet->getAddress(),
|
|
|
+ 'pools' => $pools,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(isset($reservations[$subnet->getId()])) {
|
|
|
+ $subnetConf['reservations'] = $reservations[$subnet->getId()];
|
|
|
+ }
|
|
|
+
|
|
|
+ $nextServer = $subnet->getNextServer();
|
|
|
+ if ($nextServer != '') {
|
|
|
+ $subnetConf['next-server'] = $nextServer;
|
|
|
+ }
|
|
|
+
|
|
|
+ $filename = $subnet->getFilename();
|
|
|
+ if ($filename != '') {
|
|
|
+ $subnetConf['boot-file-name'] = $filename;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($client_class != '') {
|
|
|
+ $subnetConf['client-class'] = $client_class;
|
|
|
+ if (!in_array($client_class, $this->classes)) {
|
|
|
+ $this->classes[] = $client_class;
|
|
|
+ $this->client_classes[] = [
|
|
|
+ 'name' => $client_class,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setOptionData($subnet, $subnetConf);
|
|
|
+
|
|
|
+ return $subnetConf;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param array $subnets
|
|
|
* @param array $reservations
|
|
|
*/
|
|
|
private function subnetConfig($subnets, $reservations)
|
|
|
{
|
|
|
- $classes = [];
|
|
|
foreach ($subnets as $subnet) {
|
|
|
$pools = [];
|
|
|
foreach ($subnet->getIpPool() as $pool) {
|
|
@@ -122,11 +257,10 @@ class BaseKea implements KeaConfigInterface
|
|
|
$client_class = $hostType->getShortname();
|
|
|
}
|
|
|
|
|
|
- if ($subnet->getStatus() != HostStatus::STATE_NONE && $subnet->getStatus() != '') {
|
|
|
- if ($client_class != '') {
|
|
|
- $client_class .= '-';
|
|
|
+ foreach ($subnet->getStatus() as $status) {
|
|
|
+ if ($status != HostStatus::STATE_NONE) {
|
|
|
+ $client_class .= '-' . $status;
|
|
|
}
|
|
|
- $client_class .= $subnet->getStatus();
|
|
|
}
|
|
|
|
|
|
$subnetConf = [
|
|
@@ -150,8 +284,8 @@ class BaseKea implements KeaConfigInterface
|
|
|
|
|
|
if ($client_class != '') {
|
|
|
$subnetConf['client-class'] = $client_class;
|
|
|
- if (!in_array($client_class, $classes)) {
|
|
|
- $classes[] = $client_class;
|
|
|
+ if (!in_array($client_class, $this->classes)) {
|
|
|
+ $this->classes[] = $client_class;
|
|
|
$this->client_classes[] = [
|
|
|
'name' => $client_class,
|
|
|
];
|