Services: Kea DHCP [new]: Kea DHCPv4 - add optional automatic firewall rules for dhcpv4 access. closes https://github.com/opnsense/core/issues/7188

This commit is contained in:
Ad Schellevis 2024-02-01 14:05:12 +01:00
parent 46e0bc67bb
commit b1685d8e46
4 changed files with 61 additions and 1 deletions

View File

@ -54,6 +54,45 @@ function kea_syslog()
}
function kea_firewall($fw)
{
global $config;
$keav4 = new \OPNsense\Kea\KeaDhcpv4();
if ($keav4->fwrulesEnabled()) {
// automatic (IPv4) rules enabled
foreach (explode(',', $keav4->general->interfaces) as $intf) {
$fw->registerFilterRule(
1,
[
'protocol' => 'udp',
'direction' => 'in',
'from_port' => 68,
'to' => '255.255.255.255',
'#ref' => 'ui/kea/dhcp/v4',
'to_port' => 67,
'interface' => $intf,
'descr' => 'allow access to DHCP server',
'log' => !isset($config['syslog']['nologdefaultpass'])
]
);
$fw->registerFilterRule(
1,
[
'protocol' => 'udp',
'direction' => 'in',
'from_port' => 68,
'to' => '(self)',
'#ref' => 'ui/kea/dhcp/v4',
'to_port' => 67,
'interface' => $intf,
'descr' => 'allow access to DHCP server',
'log' => !isset($config['syslog']['nologdefaultpass'])
]
);
}
}
}
function kea_xmlrpc_sync()
{
$result = [];

View File

@ -21,6 +21,12 @@
<type>text</type>
<help>Defines how long the addresses (leases) given out by the server are valid (in seconds)</help>
</field>
<field>
<id>dhcpv4.general.fwrules</id>
<label>Firewall rules</label>
<type>checkbox</type>
<help>Automatically add a basic set of firewall rules to allow dhcp traffic, more fine grained controls can be offered manually when disabling this option.</help>
</field>
<field>
<type>header</type>
<label>High Availability</label>

View File

@ -65,4 +65,15 @@ class KeaDhcpv4 extends BaseModel
}
return parent::setNodes($data);
}
/**
* should filter rules be enabled
* @return bool
*/
public function fwrulesEnabled()
{
return (string)$this->general->enabled == '1' &&
(string)$this->general->fwrules == '1' &&
!empty((string)(string)$this->general->interfaces);
}
}

View File

@ -1,6 +1,6 @@
<model>
<mount>//OPNsense/Kea/dhcp4</mount>
<version>0.0.1</version>
<version>1.0.0</version>
<description>Kea DHCPv4 configuration</description>
<items>
<general>
@ -15,6 +15,10 @@
<Default>4000</Default>
<Required>Y</Required>
</valid_lifetime>
<fwrules type="BooleanField">
<Required>Y</Required>
<Default>1</Default>
</fwrules>
</general>
<ha>
<enabled type="BooleanField">