Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 6de47c7

Browse files
committed
feat: Add next-server and filename instructions to dhcpdd
1 parent 7aa67a3 commit 6de47c7

File tree

5 files changed

+74
-38
lines changed

5 files changed

+74
-38
lines changed

cmd/dhcpdctl/cmd/apply.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/ghodss/yaml"
78
constants "github.com/pojntfx/go-isc-dhcp/cmd"
89
goISCDHCP "github.com/pojntfx/go-isc-dhcp/pkg/proto/generated"
@@ -74,6 +75,8 @@ func init() {
7475
{
7576
"netmask": "255.255.255.0",
7677
"network": "192.168.1.0",
78+
"nextServer": "192.168.1.1",
79+
"filename": "undionly.kpxe",
7780
"range": {
7881
"start": "192.168.1.10",
7982
"end": "192.168.1.100"

pkg/proto/dhcpd.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ message DHCPD {
1818
message Subnet {
1919
string Network = 1;
2020
string Netmask = 2;
21-
Range Range = 3;
21+
string NextServer = 3;
22+
string Filename = 4;
23+
Range Range = 5;
2224
}
2325

2426
message Range {

pkg/proto/generated/dhcpd.pb.go

Lines changed: 42 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/svc/dhcpd/dhcpd.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ func (m *DHCPDManager) getReplyDHCPDManagerFromDHCPDManaged(id string, DHCPD *wo
2727
var subnetsForReply []*goISCDHCP.Subnet
2828
for _, subnet := range DHCPD.Subnets {
2929
subnetForReply := &goISCDHCP.Subnet{
30-
Network: subnet.Network,
31-
Netmask: subnet.Netmask,
30+
Network: subnet.Network,
31+
Netmask: subnet.Netmask,
32+
NextServer: subnet.NextServer,
33+
Filename: subnet.Filename,
3234
Range: &goISCDHCP.Range{
3335
Start: subnet.Range.Start,
3436
End: subnet.Range.End,
@@ -53,8 +55,10 @@ func (m *DHCPDManager) Create(_ context.Context, args *goISCDHCP.DHCPD) (*goISCD
5355
var subnetsForWorker []workers.Subnet
5456
for _, subnet := range subnets {
5557
subnetsForWorker = append(subnetsForWorker, workers.Subnet{
56-
Network: subnet.GetNetwork(),
57-
Netmask: subnet.GetNetmask(),
58+
Network: subnet.GetNetwork(),
59+
Netmask: subnet.GetNetmask(),
60+
NextServer: subnet.GetNextServer(),
61+
Filename: subnet.GetFilename(),
5862
Range: workers.Range{
5963
Start: subnet.GetRange().GetStart(),
6064
End: subnet.GetRange().GetEnd(),

pkg/workers/dhcpd.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package workers
22

33
import (
44
"fmt"
5-
"github.com/pojntfx/go-isc-dhcp/pkg/utils"
65
"os"
76
"os/exec"
87
"path/filepath"
98
"syscall"
9+
10+
"github.com/pojntfx/go-isc-dhcp/pkg/utils"
1011
)
1112

1213
// DHCPD is a dhcp server.
@@ -23,9 +24,11 @@ type DHCPD struct {
2324

2425
// Subnet is a dhcp subnet.
2526
type Subnet struct {
26-
Network string
27-
Netmask string
28-
Range Range
27+
Network string
28+
Netmask string
29+
NextServer string
30+
Filename string
31+
Range Range
2932
}
3033

3134
// Range is a range in which IP address should be given out.
@@ -36,15 +39,21 @@ type Range struct {
3639

3740
// Configure configures the dhcp server.
3841
func (d *DHCPD) Configure() error {
39-
var configFileContent string
42+
configFileContent := ""
4043
for _, subnet := range d.Subnets {
41-
header := fmt.Sprintf("subnet %s netmask %s {", subnet.Network, subnet.Netmask)
44+
configFileContent += fmt.Sprintf("subnet %s netmask %s {\n", subnet.Network, subnet.Netmask)
45+
46+
configFileContent += fmt.Sprintf("\trange %s %s;\n", subnet.Range.Start, subnet.Range.End)
4247

43-
ranges := fmt.Sprintf("range %s %s;", subnet.Range.Start, subnet.Range.End)
48+
if subnet.NextServer != "" {
49+
configFileContent += fmt.Sprintf("\tnext-server %s;\n", subnet.NextServer)
50+
}
4451

45-
footer := "}"
52+
if subnet.Filename != "" {
53+
configFileContent += fmt.Sprintf("\tfilename \"%s\";\n", subnet.Filename)
54+
}
4655

47-
configFileContent += fmt.Sprintf("%s\n\t%s\n%s\n", header, ranges, footer)
56+
configFileContent += "}\n"
4857
}
4958
if err := os.MkdirAll(d.StateDir, os.ModePerm); err != nil {
5059
return err

0 commit comments

Comments
 (0)