-
Notifications
You must be signed in to change notification settings - Fork 4
Make lease times configurable #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,12 @@ The IP address to lease shall be passed as a string in `bluefield_config.yaml` g | |
| ```yaml | ||
| bluefieldIP: 2001:db8::1 | ||
| ``` | ||
| The leased address preferred and valid lifetimes default to 24 hours and are optionally configurable: | ||
| ```yaml | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h | ||
| ``` | ||
|
|
||
|
|
||
| ### Notes | ||
|
|
@@ -111,6 +117,12 @@ Providing the length in `onmetal_config.yaml` goes as follows: | |
| prefixDelegation: | ||
| length: 64 | ||
| ``` | ||
| The leased address preferred and valid lifetimes default to 24 hours and are optionally configurable: | ||
| ```yaml | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h | ||
| ``` | ||
| ### Notes | ||
| - supports only IPv6 | ||
| - IPv6 relays are mandatory | ||
|
|
@@ -131,6 +143,12 @@ subnetLabels: | |
| - key: foo | ||
| value: bar | ||
| ``` | ||
| The leased address preferred and valid lifetimes default to 24 hours and are optionally configurable: | ||
| ```yaml | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h | ||
| ``` | ||
| ### Notes | ||
| - supports both IPv4 and IPv6 | ||
| - IPv6 relays are supported, IPv4 are not | ||
|
|
@@ -258,7 +276,13 @@ The Stateless plugin derives deterministic IPv6 addresses from DHCPv6 relay mess | |
|
|
||
| For example, given a link address of `2001:db8:1111:2222:3333::` and a MAC of `aa:bb:cc:dd:ee:ff`, the resulting address is `2001:db8:1111:2222:3333:aabb:ccdd:eeff`. | ||
|
|
||
| Addresses are leased as [non temporary IPv6 addresses](https://datatracker.ietf.org/doc/html/rfc8415#section-6.2) with a 24-hour lifetime. | ||
| Addresses are leased as [non temporary IPv6 addresses](https://datatracker.ietf.org/doc/html/rfc8415#section-6.2). The preferred and valid lifetimes default to 24 hours and are configurable via an optional config file (`stateless_config.yaml`): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use “non-temporary” in the Stateless description. Replace “non temporary IPv6 addresses” with “non-temporary IPv6 addresses”. 🧰 Tools🪛 LanguageTool[grammar] ~279-~279: Use a hyphen to join words. (QB_NEW_EN_HYPHEN) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| ```yaml | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h | ||
| ``` | ||
| When no config file is provided, the defaults (24h) are used. | ||
|
|
||
| ### Notes | ||
| - supports IPv6 only | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| bluefieldIP: 2001:db8::1 | ||
| bluefieldIP: 2001:db8::1 | ||
| # leaseTimes is optional; both default to 24h when omitted. | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| prefixDelegation: | ||
| length: 64 | ||
| length: 64 | ||
| # leaseTimes is optional; both default to 24h when omitted. | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Lease times are optional; both default to 24h when omitted. | ||
| leaseTimes: | ||
| preferredLifetime: 24h | ||
| validLifetime: 24h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package api | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // DefaultLeaseTime is the default preferred and valid lifetime for DHCP leases. | ||
| const DefaultLeaseTime = 24 * time.Hour | ||
|
|
||
| // LeaseTimes holds the DHCPv6 preferred and valid lifetimes. Both are optional; | ||
| // when unset they default to DefaultLeaseTime (24h). | ||
| type LeaseTimes struct { | ||
| // PreferredLifetime is the time.Duration an address remains preferred. | ||
| // +optional | ||
| PreferredLifetime time.Duration `yaml:"preferredLifetime"` | ||
| // ValidLifetime is the time.Duration an address remains valid. | ||
| // +optional | ||
| ValidLifetime time.Duration `yaml:"validLifetime"` | ||
| } | ||
|
|
||
| // Resolve returns the preferred and valid lifetimes, defaulting any zero value | ||
| // to DefaultLeaseTime. | ||
| func (l LeaseTimes) Resolve() (preferred, valid time.Duration) { | ||
| preferred = l.PreferredLifetime | ||
| if preferred == 0 { | ||
| preferred = DefaultLeaseTime | ||
| } | ||
| valid = l.ValidLifetime | ||
| if valid == 0 { | ||
| valid = DefaultLeaseTime | ||
| } | ||
| return preferred, valid | ||
| } | ||
|
|
||
| // Validate checks the resolved lifetimes. Both must be positive, and per | ||
| // RFC 8415 the preferred lifetime must not exceed the valid lifetime. | ||
| func (l LeaseTimes) Validate() error { | ||
| preferred, valid := l.Resolve() | ||
| switch { | ||
| case preferred <= 0: | ||
| return fmt.Errorf("preferredLifetime must be positive, got %s", preferred) | ||
| case valid <= 0: | ||
| return fmt.Errorf("validLifetime must be positive, got %s", valid) | ||
| case preferred > valid: | ||
| return fmt.Errorf("preferredLifetime (%s) must not exceed validLifetime (%s)", preferred, valid) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package api | ||
|
|
||
| // StatelessConfig holds the configuration for the stateless plugin. | ||
| type StatelessConfig struct { | ||
| LeaseTimes LeaseTimes `yaml:"leaseTimes"` | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Update the OnMetal configuration description.
Line 114 still says that the configuration contains only the prefix delegation length. The new
leaseTimessettings make that statement incorrect. Update the description to mention both settings.Proposed wording
🤖 Prompt for AI Agents