Browse Source

Merged in FD3-638 (pull request #24)

FD3-638 se agregan más opciones en la config de kea
Guillermo Espinoza 7 years ago
parent
commit
54d3b2753a

+ 6 - 1
src/IPv4Bundle/Admin/NetGroupAdmin.php

@@ -47,7 +47,11 @@ class NetGroupAdmin extends BaseAdmin
         $formMapper
             ->add('name')
             ->add('opcode')
-        ;
+            ->add('relay', 'collection', [
+                'allow_add' => true, 
+                'allow_delete' => true,
+                'required'  => false,
+            ]);
     }
 
     /**
@@ -58,6 +62,7 @@ class NetGroupAdmin extends BaseAdmin
         $showMapper
             ->add('name')
             ->add('opcode')
+            ->add('relay')
         ;
     }
 }

+ 32 - 0
src/IPv4Bundle/Entity/NetGroup.php

@@ -52,6 +52,18 @@ class NetGroup implements TenancyIdTraitInterface, PreRemoveInterface
      * @ORM\OneToMany(targetEntity="SubNet", mappedBy="netGroup")
      */
     protected $subNets;
+    
+    /**
+     * @var array
+     *
+     * @ORM\Column(type="array", nullable=true)
+     *
+     * @Assert\All({
+     *     @Assert\NotBlank,
+     *     @Assert\Ip
+     * })
+     */
+    protected $relay = array();
 
 
     /**
@@ -122,5 +134,25 @@ class NetGroup implements TenancyIdTraitInterface, PreRemoveInterface
 
         return $entities;
     }
+    
+    /**
+     * @return array
+     */
+    public function getRelay()
+    {
+        return $this->relay;
+    }
+    
+    /**
+     * @param array $relay
+     *
+     * @return NetGroup
+     */
+    public function setRelay($relay)
+    {
+        $this->relay = $relay;
+        
+        return $this;
+    }
 
 }

+ 8 - 0
src/IPv4Bundle/Resources/translations/IPv4Bundle.es.yml

@@ -42,6 +42,8 @@ form:
     label_log_servers: Log Servers
     label_time_servers: Time Servers
     label_status: Estado
+    label_opcode: Opcode
+    label_relay: Relay - IP addresses
 
 list:
     label_mac: Mac
@@ -62,6 +64,8 @@ list:
     label_state: Estado
     label_extra_data: Extra Data
     label_status: Estado
+    label_opcode: Opcode
+    label_relay: Relay - IP addresses
 
 show:
     label_mac: Mac
@@ -99,6 +103,8 @@ show:
     label_log_servers: Log Servers
     label_time_servers: Time Servers
     label_status: Estado
+    label_opcode: Opcode
+    label_relay: Relay - IP addresses
 
 filter:
     label_mac: Mac
@@ -114,6 +120,8 @@ filter:
     label_extra_data: Extra Data
     label_allowed_host_type: Tipo de Host permitido
     label_status: Estado
+    label_opcode: Opcode
+    label_relay: Relay - IP addresses
 
 breadcrumb:
     link_host_list: Listado Host

+ 143 - 8
src/KeaBundle/Services/BaseKea.php

@@ -14,17 +14,61 @@ class BaseKea implements KeaConfigInterface
     private $subnet4 = [];
 
     /**
-    * @var array
-    */
-    private $hooks_libraries = [[
-        'library' => '/opt/hooks/amqp/kea-hook-flowdat3.so',
-        'parameters' => '',
-        ]];
+     * @var array
+     */
+    private $hooks_libraries = [
+        [
+            'library' => '/opt/hooks/mysql/kea-hook-flowdat3-mysql.so',
+            'parameters' => '',
+        ],
+        [
+            'library' => '/opt/hooks/amqp/kea-hook-flowdat3.so',
+            'parameters' => '',
+        ],
+    ];
 
     /**
-    * @var array
-    */
+     * @var array
+     */
     private $interfaces_config = [];
+    
+    /**
+     * @var boolean
+     */
+    private $echo_client_id = false;
+    
+    /**
+     * @var array
+     */
+    private $option_def = [
+        [
+            "name" => "subopt1", 
+            "code" => 3, 
+            "space" => "pcc", 
+            "type" => "binary", 
+            "record-types" => "", 
+            "array" => false, 
+            "encapsulate"  => "",
+        ],
+        [
+            "name" => "subopt2", 
+            "code" => 6, 
+            "space" => "pcc", 
+            "type" => "binary", 
+            "record-types" => "", 
+            "array" => false, 
+            "encapsulate" => "",
+        ],
+        [
+            "name" =>"clabs", 
+            "code" => 122, 
+            "space" => "dhcp4", 
+            "type" => "empty", 
+            "array" => false, 
+            "record-types" => "", 
+            "encapsulate" => "pcc",
+        ],
+    ];
 
 
     /**
@@ -47,6 +91,8 @@ class BaseKea implements KeaConfigInterface
                 array(
                 'arguments' => array(
                     'Dhcp4' => [
+                        'echo-client-id' => $this->echo_client_id,
+                        'option-def' => $this->option_def,
                         'control-socket' => $this->controlSocketConfig(),
                         'lease-database' => $this->leaseDatabaseConfig($data),
                         'hosts-database' => $this->leaseDatabaseConfig($data),
@@ -93,9 +139,28 @@ class BaseKea implements KeaConfigInterface
                 $subnetConf['next-server'] = $nextServer;
             }
             
+            $filename = $subnet->getFilename();
+            if ($filename != '') {
+                $subnetConf['boot-file-name'] = $filename;
+            }
+            
             if ($client_class != '') {
                 $subnetConf['client-class'] = $client_class;
             }
+            
+            $netgroup = $subnet->getNetGroup();
+            if ($netgroup && count($netgroup->getRelay())) {
+                $relay = [];
+                foreach ($netgroup->getRelay() as $ip) {
+                    $relay[] = $ip;
+                }
+                $subnetConf['relay'] = [
+                    'ip-addresses' => $relay,
+                ];
+            }
+            
+            $this->setOptionData($subnet, $subnetConf);
+            
             $this->subnet4[] = $subnetConf;
         }
     }
@@ -215,5 +280,75 @@ class BaseKea implements KeaConfigInterface
     {
         return ['interfaces' => ['*']];
     }
+    
+    /**
+     * @param Subnet $subnet
+     *
+     * @return array
+     */
+    private function setOptionData($subnet, &$subnetConf)
+    {
+        $option_data = [];
+        $fields = [
+            "routers", 
+            "time-servers" => ["always-send" => true],
+            "log-servers",
+            "time-offset",
+            "broadcast-address" => ["always-send" => true],
+            "domain-name-servers",
+        ];
+        
+        foreach ($fields as $key => $options) {
+            $name = is_array($options) ? $key : $options;
+            $field = implode('', array_map(function ($piece) {
+                return ucfirst($piece);
+            }, explode('-', $name)));
+            $method = "get{$field}";
+            $value = $subnet->$method();
+            if ($value) {
+                $data = [
+                    'name' => $name,
+                    'data' => $subnet->$method(),
+                ];
+                if (is_array($options)) {
+                    $data = array_merge($data, $options);
+                }
+                $option_data[] = $data;
+            }
+        }
+        
+        $option_122_data = [];
+        if ($subnet->getOption122ProvisioningServer() && $subnet->getOption122ProvisioningType()) {
+            $option_122_data = [
+                [
+                    "name" => "subopt1",
+                    "space" => "pcc",
+                    "code" => 3,
+                    "csv-format" => true,
+                    "data" => bin2hex($subnet->getOption122ProvisioningServer()),
+                ],
+                [
+                    "name" => "subopt2",
+                    "space" => "pcc",
+                    "code" => 6,
+                    "csv-format" => true,
+                    "data" => bin2hex($subnet->getOption122ProvisioningType()),
+                ],
+                [
+                    "name" => "clabs",
+                    "space" => "dhcp4",
+                    "code" => 122,
+                    "csv-format" => false,
+                    "data" => "",
+                ],
+            ];
+        }
+        
+        $option_data = array_merge($option_data, $option_122_data);
+        
+        $subnetConf['option-data'] = $option_data;
+                
+        return $option_data;
+    }
 
 }