Skip to content

Commit d14e54f

Browse files
refactor!: require explicit creation of DHCPServer objects
Previously, anytime a DHCPServer object was constructed it would automatically initialize empty configurations for eligible interfaces. This caused some issues with some backend DHCPServer functions built into pfSense 2.8.0+. Now DHCPServers that don't already exist in the config must be created via POST request first. This will result in more consistent behavior.
1 parent d6a6d50 commit d14e54f

2 files changed

Lines changed: 1 addition & 25 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Endpoints/ServicesDHCPServerEndpoint.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ServicesDHCPServerEndpoint extends Endpoint {
1515
# Set Endpoint attributes
1616
$this->url = '/api/v2/services/dhcp_server';
1717
$this->model_name = 'DHCPServer';
18-
$this->request_method_options = ['GET', 'PATCH'];
18+
$this->request_method_options = ['GET', 'POST', 'PATCH', 'DELETE'];
1919

2020
# Construct the parent Endpoint object
2121
parent::__construct();

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServer.inc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,9 @@ class DHCPServer extends Model {
245245
help_text: 'Static mappings applied to this DHCP server.',
246246
);
247247

248-
# Ensure all interfaces have DHCP server objects initialized
249-
$this->init_interfaces();
250-
251248
parent::__construct($id, $parent_id, $data, ...$options);
252249
}
253250

254-
/**
255-
* Initializes configuration objects for defined interface that have not yet configured the DHCP server
256-
*/
257-
private function init_interfaces(): void {
258-
# Variables
259-
$ifs_using_dhcp_server = array_keys($this->get_config(path: $this->config_path, default: []));
260-
261-
# Loop through each defined interface
262-
foreach ($this->get_config('interfaces', []) as $if_id => $if) {
263-
# Skip this interface if it is not a static interface or the subnet value is greater than or equal to 31
264-
if (empty($if['ipaddr']) or !is_ipaddrv4($if['ipaddr']) or $if->subnet->value >= 31) {
265-
continue;
266-
}
267-
268-
# Otherwise, make this interface eligible for a DHCP server
269-
if (!in_array($if_id, $ifs_using_dhcp_server)) {
270-
$this->set_config(path: "$this->config_path/$if_id", value: ['range' => ['from' => '', 'to' => '']]);
271-
}
272-
}
273-
}
274-
275251
/**
276252
* Obtains the internal `interface` field value since it is not stored in the config.
277253
* @return string The internal interface ID of the DHCPServer.

0 commit comments

Comments
 (0)