Fix: fallback by seeding default values for interface

This commit is contained in:
billz
2025-09-11 08:56:09 -07:00
parent 23103c8c4b
commit 8bb18b43f8
2 changed files with 31 additions and 2 deletions

View File

@@ -41,7 +41,7 @@ class DhcpcdManager
{
// determine static IP, routers, DNS
$jsonData = $this->getInterfaceConfig($ap_iface);
//error_log("DhcpcdManager::buildConfig() jsonData =" . print_r($jsonData, true));
$ip_address = empty($jsonData['StaticIP'])
? getDefaultNetValue('dhcp', $ap_iface, 'static ip_address')
: $jsonData['StaticIP'];
@@ -485,6 +485,21 @@ class DhcpcdManager
}
}
}
} else {
// fallback to defaults
$rangeRaw = getDefaultNetValue('dnsmasq', $iface, 'dhcp-range');
if ($rangeRaw) {
$result['DHCPEnabled'] = true;
$rangeParts = explode(',', $rangeRaw);
$result['RangeStart'] = $rangeParts[0] ?? null;
$result['RangeEnd'] = $rangeParts[1] ?? null;
$result['RangeMask'] = $rangeParts[2] ?? null;
$leaseSpec = $rangeParts[3] ?? null;
if ($leaseSpec && preg_match('/^(\d+)([smhd])?$/i', $leaseSpec, $m)) {
$result['leaseTime'] = $m[1];
$result['leaseTimeInterval'] = $m[2] ?? 'h';
}
}
}
// dhcpcd
@@ -513,6 +528,11 @@ class DhcpcdManager
$result['FallbackEnabled'] = (bool) preg_match('/fallback\s+static_' . preg_quote($iface, '/') . '/i', $block);
$result['DefaultRoute'] = (bool) preg_match('/\bgateway\b/', $block);
$result['NoHookWPASupplicant'] = (bool) preg_match('/nohook\s+wpa_supplicant/i', $block);
} else {
$result['StaticIP'] = getDefaultNetValue('dhcp', $iface, 'static ip_address');
$result['SubnetMask'] = getDefaultNetValue('dhcp', $iface, 'subnetmask');
$result['StaticRouters'] = getDefaultNetValue('dhcp', $iface, 'static routers');
$result['StaticDNS'] = getDefaultNetValue('dhcp', $iface, 'static domain_name_server');
}
}
return $result;

View File

@@ -61,8 +61,17 @@ class DnsmasqManager
* @return array $config
* @throws \RuntimeException
*/
public function buildConfig(array $syscfg, string $iface, bool $wifiAPEnable, bool $bridgedEnable): array
public function buildConfig(?array $syscfg, string $iface, bool $wifiAPEnable, bool $bridgedEnable): array
{
// fallback: if no syscfg for interface seed with defaults
if ($syscfg === null) {
$syscfg = [];
$dhcp_range = getDefaultNetValue('dnsmasq', $iface, 'dhcp-range');
if ($dhcp_range !== false) {
$syscfg['dhcp-range'] = $dhcp_range;
}
}
if ($wifiAPEnable == 1) {
// Enable uap0 configuration for ap-sta mode
// Set dhcp-range from system config, fallback to default if undefined