Skip to content
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

Implement new configuration strategy for Bluefield plugin #239

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ Leases a single IP address to a single client as a [non temporary IPv6 address](

Meant to be used in 1:1 client-server connection scenarios, for example a smartnic (Bluefield) leasing a single address to the host.
### Configuration
The IP address to lease shall be passed as a string.
The IP address to lease shall be passed as a string in `bulefield_config.yaml` goes as follows:

```yaml
bulefieldIP: 2001:db8::1
```


### Notes
- supports IPv6 addresses only
- IPv6 relays are supported
Expand Down
1 change: 1 addition & 0 deletions example/bluefield_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bulefieldIP: 2001:db8::1
2 changes: 1 addition & 1 deletion example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ server6:
# mandatory for RFC compliance
- server_id: LL 00:de:ad:be:ef:00
# always provide the same IP address, no matter who's asking:
# - bluefield: 2001:db8::1
# - bluefield: bluefield_config.yaml
# implement HTTPBoot
- httpboot: http://[2001:db8::1]/image.uki
# add leased IPs to ironcore's IPAM
Expand Down
8 changes: 8 additions & 0 deletions internal/api/bluefield_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: MIT

package api

type BluefieldConfig struct {
BulefieldIP string `yaml:"bulefieldIP"`
}
38 changes: 34 additions & 4 deletions plugins/bluefield/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ package bluefield
import (
"fmt"
"net"
"os"
"time"

"github.com/coredhcp/coredhcp/handler"
"github.com/coredhcp/coredhcp/logger"
"github.com/coredhcp/coredhcp/plugins"
"github.com/insomniacslk/dhcp/dhcpv6"
"github.com/insomniacslk/dhcp/iana"
"github.com/ironcore-dev/fedhcp/internal/api"
"gopkg.in/yaml.v2"
)

var log = logger.GetLogger("plugins/bluefield")
Expand All @@ -23,12 +26,39 @@ var Plugin = plugins.Plugin{
}
var ipaddr net.IP

// setupPlugin initializes the plugin with given arguments.
// args[0] = path to config file
func parseArgs(args ...string) (string, error) {
if len(args) != 1 {
return "", fmt.Errorf("exactly one argument must be passed to the bluefield plugin, got %d", len(args))
}
return args[0], nil
}

func loadConfig(args ...string) (*api.BluefieldConfig, error) {
path, err := parseArgs(args...)
if err != nil {
return nil, fmt.Errorf("invalid configuration: %v", err)
}

log.Debugf("Reading bluefield config file %s", path)
configData, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %v", err)
}
config := &api.BluefieldConfig{}
if err = yaml.Unmarshal(configData, config); err != nil {
return nil, fmt.Errorf("failed to parse config file: %v", err)
}
return config, nil
}

// setupPlugin initializes the plugin with given bluefield config.
func setupPlugin(args ...string) (handler.Handler6, error) {
if len(args) < 1 {
return nil, fmt.Errorf("plugin bluefield requires at least one argument (static IPv6 address)")
bluefieldIPConfig, err := loadConfig(args...)
if err != nil {
return nil, err
}
ipaddr = net.ParseIP(args[0])
ipaddr = net.ParseIP(bluefieldIPConfig.BulefieldIP)
if ipaddr == nil {
return nil, fmt.Errorf("invalid IPv6 address: %s", args[0])
}
Expand Down
Loading