Add DHCP Server Definitions

This commit is contained in:
Samuel Lorch 2023-04-13 17:56:14 +02:00
parent 72bf96295d
commit 43495f5507
6 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,21 @@
package service
import (
"time"
)
type DHCPv4 struct {
Interface string
Pool []string
DefaultLeaseTime time.Duration
MaxLeaseTime time.Duration
GatewayMode Mode
Gateway *string
DNSServerMode Mode
DNSServer *[]string
NTPServerMode Mode
NTPServer *[]string
Reservations []Reservation
}

View file

@ -0,0 +1,19 @@
package service
import "time"
type DHCPv6 struct {
Interface string
Pool []string
DefaultLeaseTime time.Duration
MaxLeaseTime time.Duration
GatewayMode Mode
Gateway *string
DNSServerMode Mode
DNSServer *[]string
NTPServerMode Mode
NTPServer *[]string
Reservations []Reservation
}

View file

@ -0,0 +1,37 @@
package service
import "encoding/json"
type Mode int
const (
None Mode = iota
Interface
Specify
)
func (t Mode) String() string {
return [...]string{"none", "interface", "specify"}[t]
}
func (t *Mode) FromString(input string) Mode {
return map[string]Mode{
"none": None,
"interface": Interface,
"specify": Specify,
}[input]
}
func (t Mode) MarshalJSON() ([]byte, error) {
return json.Marshal(t.String())
}
func (t *Mode) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*t = t.FromString(s)
return nil
}

View file

@ -0,0 +1,12 @@
package service
import (
"net/netip"
"nfsense.net/nfsense/internal/definitions/common"
)
type Reservation struct {
HardwareAddress common.HardwareAddress
IPAddress netip.Addr
}

View file

@ -0,0 +1,6 @@
package service
type Service struct {
DHCPv4 []DHCPv4 `json:"dhcp_v4" validate:"required,dive"`
DHCPv6 []DHCPv6 `json:"dhcp_v6" validate:"required,dive"`
}