Skip to content

Commit

Permalink
Services: Kea DHCP [new]: Kea DHCPv4 - add optional automatic firewal…
Browse files Browse the repository at this point in the history
…l rules for dhcpv4 access. closes #7188
  • Loading branch information
AdSchellevis committed Feb 1, 2024
1 parent 46e0bc6 commit b1685d8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/etc/inc/plugins.inc.d/kea.inc
Expand Up @@ -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 = [];
Expand Down
Expand Up @@ -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>
Expand Down
11 changes: 11 additions & 0 deletions src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php
Expand Up @@ -65,4 +65,15 @@ public function setNodes($data)
}
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);
}
}
6 changes: 5 additions & 1 deletion src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml
@@ -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>
Expand All @@ -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">
Expand Down

0 comments on commit b1685d8

Please sign in to comment.