Skip to content

Fixes #39429 - Add KEA DHCP provider#949

Open
archanaserver wants to merge 2 commits into
theforeman:developfrom
archanaserver:dhcp-kea
Open

Fixes #39429 - Add KEA DHCP provider#949
archanaserver wants to merge 2 commits into
theforeman:developfrom
archanaserver:dhcp-kea

Conversation

@archanaserver

Copy link
Copy Markdown
Contributor

Ref: theforeman/foremanctl#531 (comment)

KEA DHCP integration for Smart Proxy as we're transitioning away from ISC DHCP (which reached EOL in 2022) to KEA now.

Adds Smart Proxy DHCP provider for ISC KEA DHCP server using the KEA Control Agent API, providing a migration path for users currently using the deprecated dhcp_isc provider.

Note: Based on the smart_proxy_dhcp_kea_api gem by Sam McCarthy, to integrate into Smart Proxy core. https://gitlab.surrey.ac.uk/sm0049/smart-proxy-dhcp-kea-api/-/issues/3

Fixes: https://redhat.atlassian.net/browse/SAT-27739

Comment thread modules/dhcp_kea/dhcp_kea_main.rb Outdated
Comment on lines +127 to +132
network, prefix = cidr.split('/')
prefix = prefix.to_i

mask = (0xffffffff << (32 - prefix)) & 0xffffffff

[mask].pack('N').unpack('C4').join('.')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPAddr has this built in:

Suggested change
network, prefix = cidr.split('/')
prefix = prefix.to_i
mask = (0xffffffff << (32 - prefix)) & 0xffffffff
[mask].pack('N').unpack('C4').join('.')
cidr.netmask

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, this is Ruby 3.1+ only :/

@ekohl ekohl Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly the Ruby's API docs didn't mention that :(

Comment thread bundler.d/dhcp_kea.rb Outdated
Comment thread config/settings.d/dhcp.yml.example Outdated
Comment thread config/settings.d/dhcp_kea.yml.example Outdated
@evgeni

evgeni commented Jun 16, 2026

Copy link
Copy Markdown
Member

Given this is an import of an previously external provider, I'd vote for "make CI green and merge it", with any further cleanup in a separate PR.

@archanaserver archanaserver marked this pull request as ready for review June 16, 2026 20:57
@archanaserver archanaserver force-pushed the dhcp-kea branch 2 times, most recently from 1c98bff to 5e48025 Compare June 16, 2026 21:03
@archanaserver archanaserver changed the title Add KEA DHCP provider Fixes #39429 - Add KEA DHCP provider Jun 16, 2026
Comment thread config/settings.d/dhcp.yml.example Outdated
Comment on lines +11 to +12
# NOTE: ISC DHCP reached end-of-life in October 2022. ISC recommends
# migrating to KEA DHCP. Use `dhcp_kea` for new deployments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# NOTE: ISC DHCP reached end-of-life in October 2022. ISC recommends
# migrating to KEA DHCP. Use `dhcp_kea` for new deployments.

stejskalleos
stejskalleos previously approved these changes Jun 17, 2026
Comment thread modules/dhcp_kea/dhcp_kea.rb Outdated
Comment on lines +2 to +3
require 'dhcp_kea/plugin_configuration'
require 'dhcp_kea/dhcp_kea_plugin'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a plugin? IMO it's not.

Suggested change
require 'dhcp_kea/plugin_configuration'
require 'dhcp_kea/dhcp_kea_plugin'
require 'dhcp_kea/configuration'
require 'dhcp_kea/dhcp_kea'

@archanaserver archanaserver Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept dhcp_kea_plugin because we already have dhcp_kea as the entry point. Renaming the plugin file to dhcp_kea.rb would create confusion, so let's stay with this?

#:dhcp_kea_verify_ssl: true

# Timeout for lease operations in seconds
#:dhcp_kea_lease_timeout: 60

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: 60 seconds is quite generous, and I don't know how it will work with all those queue steps and JS actions in the create host UI form.

IMO, we should lower this to <30 seconds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is that used anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently it is only passed into the KEA provider and stored as @lease_timeout, but it is not actually used in the lease/reservation operation calls yet.

soeither wire this into the KEA API client timeout handling, or remove the config option for now if we don’t think we need it here. that's my thought on this

Comment thread modules/dhcp_kea/dhcp_kea_plugin.rb Outdated
Comment on lines +16 to +18
load_classes ::Proxy::DHCP::Kea::PluginConfiguration
load_programmable_settings ::Proxy::DHCP::Kea::PluginConfiguration
load_dependency_injection_wirings ::Proxy::DHCP::Kea::PluginConfiguration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that all of these are optional. If they're empty, you can leave them out. You can also use a block. For example:

load_programmable_settings do |settings|
settings[:http_port] = ::Proxy::Settings::Plugin.http_enabled?(settings[:enabled]) ? Proxy::SETTINGS.http_port : nil
settings[:https_port] = ::Proxy::Settings::Plugin.https_enabled?(settings[:enabled]) ? Proxy::SETTINGS.https_port : nil
settings
end

I'm fine either way, but I want to point out the option since it may be easier to understand to have fewer files.

The trade off is that it's harder to test. For load_classes that's not a concern since we don't test that anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that make sense, Thanks for pointing this out!

@archanaserver

Copy link
Copy Markdown
Contributor Author

One test changes and now it's failing completely, FYI this is in-progress right now.

@archanaserver archanaserver marked this pull request as draft June 22, 2026 15:34
@archanaserver

Copy link
Copy Markdown
Contributor Author

@evgeni @stejskalleos can you help how it keep failing here workflow? i'm not sure what i'm missing

@archanaserver archanaserver marked this pull request as ready for review June 23, 2026 10:13
Comment thread test/dhcp_kea/dhcp_kea_main_test.rb Outdated
'test.example.com',
'172.16.0.50',
'aa:bb:cc:dd:ee:ff',
Proxy::DHCP::Subnet.new('172.16.0.0/24', '255.255.255.0')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Proxy::DHCP::Subnet.new('172.16.0.0/24', '255.255.255.0')
Proxy::DHCP::Subnet.new('172.16.0.0', '255.255.255.0')

Subnet.new wants an IP and a netmask, separately

Comment thread modules/dhcp_kea/dhcp_kea_main.rb Outdated
end

if record.is_a?(::Proxy::DHCP::Reservation)
service.delete_host(subnet.network, record)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete_host only expects one parameter: a record. you're passing two, and thus it fails.

if record.is_a?(::Proxy::DHCP::Reservation)
service.delete_host(subnet.network, record)
elsif record.is_a?(::Proxy::DHCP::Lease)
service.delete_lease(subnet.network, record)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete_lease also expects just one parameter, seems there is no test for this case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, for this to work, we should have issued lease4-del, not reservation-del as done by delete_reservation_by_ip, right?

@evgeni

evgeni commented Jun 24, 2026

Copy link
Copy Markdown
Member

Which version (commit) of https://gitlab.surrey.ac.uk/sm0049/smart-proxy-dhcp-kea-api/ was this based on? I have a hard time comparing the code and the issues :(

@ekohl

ekohl commented Jun 24, 2026

Copy link
Copy Markdown
Member

Which version (commit) of https://gitlab.surrey.ac.uk/sm0049/smart-proxy-dhcp-kea-api/ was this based on? I have a hard time comparing the code and the issues :(

Perhaps you can write 2 commits: 1 doing a verbatim import with proper ownership (git commit --author '...') and then another with the changes that you made to it. I strongly feel that proper attribution of the original owner is very important in open source. There may be some legal reasons (since there still is a license), but IMHO also ethical. Someone took the effort to write it and we should acknowledge that.

You can use Refs #39429 - ... on the first commit so make the Redmine checker happy.

Imported from smart-proxy-dhcp-kea-api.

This is a verbatim import of the original KEA DHCP provider code.
Adapt the imported smart_proxy_dhcp_kea_api code for Smart Proxy core integration.

- Rename classes to match Smart Proxy conventions
- Update test structure and fix test issues
- Add configuration template
- Integrate with Smart Proxy module system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants