Skip to content

Commit

Permalink
wizard: as we're changing to dnsmasq as default, we need to make sure…
Browse files Browse the repository at this point in the history
… the console setup configures the same (#8352)

Fix some small php arnings in the process, but further than that just rewrite the dhcpd console handling to use dnsmasq instead of isc.
Eventually we will need to rewrite the console tools as well, but let's try to keep this compatible with minimal impact.
  • Loading branch information
AdSchellevis committed Mar 3, 2025
1 parent 0a23495 commit 8ad840b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
20 changes: 16 additions & 4 deletions src/etc/inc/console.inc
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,22 @@ EOD;
$config['interfaces']['lan']['subnetv6'] = '64';
}

config_read_array('dhcpd', 'lan', 'range');
$config['dhcpd']['lan']['enable'] = true;
$config['dhcpd']['lan']['range']['from'] = '192.168.1.100';
$config['dhcpd']['lan']['range']['to'] = '192.168.1.199';
if (isset($config['dhcpd']['lan'])) {
unset($config['dhcpd']['lan']);
}

config_read_array('dnsmasq', 'dhcp_ranges');
foreach ($config['dnsmasq']['dhcp_ranges'] as $idx => $range) {
if ($range['interface'] == 'lan') {
unset($config['dnsmasq']['dhcp_ranges'][$idx]);
}
}
$config['dnsmasq']['enable'] = '1';
$config['dnsmasq']['dhcp_ranges'][] = [
'interface' => 'lan',
'start_addr' => '192.168.1.100',
'end_addr' => '192.168.1.200'
];

config_read_array('nat', 'outbound');
$config['nat']['outbound']['mode'] = 'automatic';
Expand Down
1 change: 1 addition & 0 deletions src/etc/inc/xmlparse.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function listtags()
'user',
'vip', 'virtual_server', 'vlan',
'winsserver', 'wolentry', 'widget',
'dhcp_ranges'
);

return array_flip($ret);
Expand Down
52 changes: 39 additions & 13 deletions src/opnsense/scripts/shell/setaddr.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function get_interface_config_description($iface)
$if = $c['if'];
$result = $if;
$result2 = array();
$ipaddr = $c['ipaddr'];
$ipaddrv6 = $c['ipaddrv6'];
$ipaddr = $c['ipaddr'] ?? '';
$ipaddrv6 = $c['ipaddrv6'] ?? '';
if (is_ipaddr($ipaddr)) {
$result2[] = 'static';
} elseif (!empty($ipaddr)) {
Expand Down Expand Up @@ -301,6 +301,11 @@ function console_configure_ip_address($version)
{
global $config, $interface, $restart_dhcpd, $ifaceassigned, $fp;

$isintdhcp = false;
$restart_dhcpd = false;
$gwname = null;
$nameserver = null;
$intbits = '';
$label_IPvX = ($version === 6) ? 'IPv6' : 'IPv4';
$maxbits = ($version === 6) ? 128 : 32;
$label_DHCP = ($version === 6) ? 'DHCP6' : 'DHCP';
Expand Down Expand Up @@ -329,7 +334,6 @@ function console_configure_ip_address($version)
$ifaceassigned = $ifppp;
}
$intip = ($version === 6) ? 'dhcp6' : 'dhcp';
$intbits = '';
$isintdhcp = true;
$restart_dhcpd = true;
echo "\n";
Expand Down Expand Up @@ -475,6 +479,15 @@ function console_configure_dhcpd($version = 4)
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd";

if ($version === 4) {
config_read_array('dnsmasq', 'dhcp_ranges');
foreach ($config['dnsmasq']['dhcp_ranges'] as $idx => $range) {
if ($range['interface'] == $interface) {
unset($config['dnsmasq']['dhcp_ranges'][$idx]);
}
}
}

if (prompt_for_enable_dhcp_server($version)) {
$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
Expand Down Expand Up @@ -512,13 +525,25 @@ function console_configure_dhcpd($version = 4)
} while (!$is_ipaddr || !$is_inrange);
} while ($not_inorder);
$restart_dhcpd = true;
$config[$dhcpd][$interface]['enable'] = true;
$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
$config[$dhcpd][$interface]['range']['to'] = $dhcpendip;
if ($version === 4) {
$config['dnsmasq']['enable'] = '1';
$config['dnsmasq']['dhcp_ranges'][] = [
'interface' => $interface,
'start_addr' => $dhcpstartip,
'end_addr' => $dhcpendip
];
} else {
$config['dhcpdv6'][$interface]['enable'] = true;
$config['dhcpdv6'][$interface]['range']['from'] = $dhcpstartip;
$config['dhcpdv6'][$interface]['range']['to'] = $dhcpendip;
}
echo "\n";
} else {
if (isset($config[$dhcpd][$interface]['enable'])) {
unset($config[$dhcpd][$interface]['enable']);
if ($version === 6 && isset($config['dhcpdv6'][$interface]['enable'])) {
unset($config['dhcpdv6'][$interface]['enable']);
$restart_dhcpd = true;
} elseif ($version === 4) {
/* XXX: not disabling dnsmasq as there might be other consumers */
$restart_dhcpd = true;
}
}
Expand Down Expand Up @@ -552,14 +577,14 @@ function console_configure_dhcpd($version = 4)
}
}

if ($config['interfaces']['lan']) {
if ($config['dhcpd']) {
if ($config['dhcpd']['wan']) {
if (!empty($config['interfaces']['lan'])) {
if (isset($config['dhcpd'])) {
if (isset($config['dhcpd']['wan'])) {
unset($config['dhcpd']['wan']);
}
}
if ($config['dhcpdv6']) {
if ($config['dhcpdv6']['wan']) {
if (isset($config['dhcpdv6'])) {
if (isset($config['dhcpdv6']['wan'])) {
unset($config['dhcpdv6']['wan']);
}
}
Expand Down Expand Up @@ -590,6 +615,7 @@ interface_configure(true, $interface, true);

if ($restart_dhcpd) {
plugins_configure('dhcp', true);
plugins_configure('dns', true); /* dnsmasq dhcp */
}

if ($restart_webgui) {
Expand Down

0 comments on commit 8ad840b

Please sign in to comment.