KEA dhcp Mysql后端

时间:2015-07-22 08:58:21

标签: mysql dhcp

我在MySQL后端遇到了新的ISC DHCP,KEA问题。 我想在我的数据库中存储租约,它可以工作,但不存储一些信息。

我在我的数据库中获得了这种条目:

+------------+--------+-----------+----------------+---------------------+-----------+----------+----------+----------+                
| address    | hwaddr | client_id | valid_lifetime | expire              | subnet_id | fqdn_fwd | fqdn_rev | hostname |              
+------------+--------+-----------+----------------+---------------------+-----------+----------+----------+----------+
| 3232236052 | '°     | NULL      |           4000 | 2015-07-22 08:54:32 |         1 |        0 |        0 |          │                 
+------------+--------+-----------+----------------+---------------------+-----------+----------+----------+----------+   

地址字段是十进制的IP地址,我检查过它是好的。 我没有找到如何将IP地址更改为IPv4格式以及如何在KEA文档中的hwaddr字段中存储mac地址。

如果有人知道怎么做,我将非常感激!

谢谢!

2 个答案:

答案 0 :(得分:2)

根据KEA文档hwaddr字段为VARBINARY。您应该能够使用以下命令查看值IP地址和hwaddr:

SELECT INET_NTOA(address), HEX(hwaddr), lease4.* FROM lease4;

答案 1 :(得分:0)

我有类似的需要创建KEA主机预留并将MAC和IP地址填充为常规字符串,同时仍然具有KEA在INSERT或UPDATE上自动更新的字段。

我最终做的是创建两个包含这些字符串值的新字段('hosts.dhcp_identifier_str'和'hosts.ipv4_address_str'):

ALTER TABLE `hosts` ADD `dhcp_identifier_str` VARCHAR(12) NOT NULL AFTER `dhcp_identifier`;
ALTER TABLE `hosts` ADD `ipv4_address_str` VARCHAR(15) NULL DEFAULT NULL AFTER `ipv4_address`;

然后,我使用BEFORE INSERT / UPDATE MySQL触发器保持KEA使用的相应字段('hosts.dhcp_identifier'和'hosts.ipv4_address')为最新版本:

DELIMITER //
DROP TRIGGER IF EXISTS `host_BINS`//
CREATE TRIGGER `host_BINS` BEFORE INSERT ON `hosts`
 FOR EACH ROW BEGIN

IF (NEW.dhcp_identifier = '' AND NEW.dhcp_identifier_str != '') THEN
          SET NEW.dhcp_identifier = UNHEX(UPPER(NEW.dhcp_identifier_str));
ELSEIF (NEW.dhcp_identifier_str = '' AND NEW.dhcp_identifier != '') THEN
          SET NEW.dhcp_identifier_str = LOWER(HEX(NEW.dhcp_identifier));
END IF;

IF (NEW.ipv4_address IS NULL AND NEW.ipv4_address_str IS NOT NULL) THEN
          SET NEW.ipv4_address = INET_ATON(NEW.ipv4_address_str);
ELSEIF (NEW.ipv4_address_str IS NULL AND NEW.ipv4_address IS NOT NULL) THEN
          SET NEW.ipv4_address_str = CAST(INET_NTOA(NEW.ipv4_address) AS CHAR);
END IF;
END
//

DROP TRIGGER IF EXISTS `host_BUPD`//
CREATE TRIGGER `host_BUPD` BEFORE UPDATE ON `hosts`
 FOR EACH ROW BEGIN

IF (NEW.dhcp_identifier_str != '' AND OLD.dhcp_identifier != UNHEX(UPPER(NEW.dhcp_identifier_str))) THEN
          SET NEW.dhcp_identifier = UNHEX(UPPER(NEW.dhcp_identifier_str));
ELSEIF (NEW.dhcp_identifier != '' AND OLD.dhcp_identifier_str != LOWER(HEX(NEW.dhcp_identifier))) THEN
          SET NEW.dhcp_identifier_str = LOWER(HEX(NEW.dhcp_identifier));
END IF;

IF (NEW.ipv4_address_str IS NOT NULL AND OLD.ipv4_address != INET_ATON(NEW.ipv4_address_str)) THEN
          SET NEW.ipv4_address = INET_ATON(NEW.ipv4_address_str);
ELSEIF (NEW.ipv4_address IS NOT NULL AND OLD.ipv4_address_str != CAST(INET_NTOA(NEW.ipv4_address) AS CHAR)) THEN
          SET NEW.ipv4_address_str = CAST(INET_NTOA(NEW.ipv4_address) AS CHAR);
END IF;
END
//

无论是使用dhcp_identifier / ipv4_address还是使用dhcp_identifier_str / ipv4_address_str对INSERT / UPDATE条目,这都有效。

我确信你可以为'lease4'表使用相同的触发器。

希望有所帮助。