mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 01:24:38 +00:00
dhcp: last round of changes; closes #4642
o Move the IPv6 recompress to dhcpd_staticmap() o Add DHCPv4 leases page as consumer of dhcpd_staticmap() o Emit the MAC address in IPv4 case in dhcpd_staticmap() o Let dhcpd_staticmap() emit valid entries with an IP address o Check for required hostname in Dnsmasq and Unbound integration
This commit is contained in:
parent
84b9a75920
commit
e963f315eb
@ -1905,14 +1905,21 @@ function dhcpd_staticmap($domain_fallback = 'not.found', $ifconfig_details = nul
|
||||
interfaces_primary_address6($dhcpif, null, $ifconfig_details) : [null];
|
||||
|
||||
foreach ($dhcpifconf['staticmap'] as $host) {
|
||||
if (empty($host[$ipaddr]) || empty($host['hostname'])) {
|
||||
if (empty($host[$ipaddr])) {
|
||||
/* we only return proper entries with an IP address */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($ipaddrv6)) {
|
||||
/* expand IPv6 suffix address */
|
||||
$host['ipaddrv6'] = make_ipv6_64_address($ipaddrv6, $host['ipaddrv6']);
|
||||
}
|
||||
|
||||
if (!empty($host['ipaddrv6'])) {
|
||||
/* avoid sloppy input by recompressing the address correctly */
|
||||
$host['ipaddrv6'] = Net_IPv6::compress(Net_IPv6::uncompress($host['ipaddrv6']));
|
||||
}
|
||||
|
||||
// XXX: dhcpdv6 domain entries have been superseded by domainsearchlist,
|
||||
// for backward compatibilty support both here.
|
||||
if (!empty($ipaddrv6) && !empty($host['domainsearchlist'])) {
|
||||
@ -1938,8 +1945,10 @@ function dhcpd_staticmap($domain_fallback = 'not.found', $ifconfig_details = nul
|
||||
$ipaddr => $host[$ipaddr],
|
||||
];
|
||||
|
||||
if (isset($host['duid'])) {
|
||||
$entry['duid'] = $host['duid'];
|
||||
foreach (['mac', 'duid'] as $property) {
|
||||
if (isset($host[$property])) {
|
||||
$entry[$property] = $host[$property];
|
||||
}
|
||||
}
|
||||
|
||||
$staticmap[] = $entry;
|
||||
|
||||
@ -233,6 +233,10 @@ function _dnsmasq_add_host_entries()
|
||||
}
|
||||
|
||||
foreach (dhcpd_staticmap($domain, legacy_interfaces_details()) as $host) {
|
||||
if (empty($host['hostname'])) {
|
||||
/* cannot register without a hostname */
|
||||
continue;
|
||||
}
|
||||
if (isset($host['ipaddr'])) {
|
||||
$dhosts .= "{$host['ipaddr']}\t{$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
|
||||
} else {
|
||||
|
||||
@ -655,6 +655,10 @@ function unbound_add_host_entries($ifconfig_details = null)
|
||||
require_once 'plugins.inc.d/dhcpd.inc'; /* XXX */
|
||||
|
||||
foreach (dhcpd_staticmap($config['system']['domain'], $ifconfig_details) as $host) {
|
||||
if (empty($host['hostname'])) {
|
||||
/* cannot register without a hostname */
|
||||
continue;
|
||||
}
|
||||
if (isset($host['ipaddr'])) {
|
||||
$unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['hostname']}.{$host['domain']}\"\n";
|
||||
$unbound_entries .= "local-data: \"{$host['hostname']}.{$host['domain']} IN A {$host['ipaddr']}\"\n";
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2016 Deciso B.V.
|
||||
* Copyright (C) 2014-2021 Deciso B.V.
|
||||
* Copyright (C) 2004-2009 Scott Ullrich <sullrich@gmail.com>
|
||||
* Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
|
||||
* All rights reserved.
|
||||
@ -201,7 +201,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
/* remove the old array */
|
||||
unset($lease_content);
|
||||
|
||||
/* remove duplicate items by mac address */
|
||||
if (count($leases) > 0) {
|
||||
$leases = remove_duplicate($leases,"ip");
|
||||
}
|
||||
@ -217,30 +216,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$macs[$this_lease['mac']] = $i;
|
||||
}
|
||||
}
|
||||
foreach ($interfaces as $ifname => $ifarr) {
|
||||
if (isset($config['dhcpd'][$ifname]['staticmap'])) {
|
||||
foreach($config['dhcpd'][$ifname]['staticmap'] as $static) {
|
||||
$slease = array();
|
||||
$slease['ip'] = $static['ipaddr'];
|
||||
$slease['type'] = "static";
|
||||
$slease['mac'] = $static['mac'];
|
||||
$slease['start'] = '';
|
||||
$slease['end'] = '';
|
||||
$slease['hostname'] = $static['hostname'];
|
||||
$slease['descr'] = $static['descr'];
|
||||
$slease['act'] = "static";
|
||||
$slease['online'] = in_array(strtolower($slease['mac']), $arpdata_mac) ? 'online' : 'offline';
|
||||
if (isset($macs[$slease['mac']])) {
|
||||
// update lease with static data
|
||||
foreach ($slease as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
$leases[$macs[$slease['mac']]][$key] = $slease[$key];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$leases[] = $slease;
|
||||
|
||||
foreach (dhcpd_staticmap() as $static) {
|
||||
if (!isset($static['ipaddr'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$slease = array();
|
||||
$slease['ip'] = $static['ipaddr'];
|
||||
$slease['type'] = 'static';
|
||||
$slease['mac'] = $static['mac'];
|
||||
$slease['start'] = '';
|
||||
$slease['end'] = '';
|
||||
$slease['hostname'] = $static['hostname'];
|
||||
$slease['descr'] = $static['descr'];
|
||||
$slease['act'] = 'static';
|
||||
$slease['online'] = in_array(strtolower($slease['mac']), $arpdata_mac) ? 'online' : 'offline';
|
||||
|
||||
if (isset($macs[$slease['mac']])) {
|
||||
/* update lease with static data */
|
||||
foreach ($slease as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
$leases[$macs[$slease['mac']]][$key] = $slease[$key];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$leases[] = $slease;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2016 Deciso B.V.
|
||||
* Copyright (C) 2014-2021 Deciso B.V.
|
||||
* Copyright (C) 2004-2009 Scott Ullrich <sullrich@gmail.com>
|
||||
* Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
|
||||
* Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
|
||||
@ -301,7 +301,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
}
|
||||
|
||||
$slease = [];
|
||||
$slease['ip'] = Net_IPv6::compress($static['ipaddrv6']);
|
||||
$slease['ip'] = $static['ipaddrv6'];
|
||||
$slease['if'] = $static['interface'];
|
||||
$slease['type'] = 'static';
|
||||
$slease['duid'] = $static['duid'];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user