iptools: reorganizing and continuing pool work
This commit is contained in:
@@ -9,6 +9,7 @@ go_library(
|
||||
importpath = "git.wntrmute.dev/kyle/kdhcp/config",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//iptools",
|
||||
"//log",
|
||||
"@in_gopkg_yaml_v2//:yaml_v2",
|
||||
],
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
|
||||
"git.wntrmute.dev/kyle/kdhcp/iptools"
|
||||
"git.wntrmute.dev/kyle/kdhcp/log"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -23,23 +24,6 @@ func ensureV4(ip net.IP) (net.IP, error) {
|
||||
return ip4, nil
|
||||
}
|
||||
|
||||
type IPRange struct {
|
||||
Start net.IP
|
||||
End net.IP
|
||||
}
|
||||
|
||||
func (r *IPRange) ensureV4() (err error) {
|
||||
if r.Start, err = ensureV4(r.Start); err != nil {
|
||||
return fmt.Errorf("config: range start address %w", err)
|
||||
}
|
||||
|
||||
if r.End, err = ensureV4(r.End); err != nil {
|
||||
return fmt.Errorf("config: range end address %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
IP net.IP `yaml:"address"`
|
||||
Gateway net.IP `yaml:"gateway"`
|
||||
@@ -85,14 +69,14 @@ type ConfigFile struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Version int `yaml:"version"`
|
||||
Interface string `yaml:"interface"`
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
LeaseFile string `yaml:"lease_file"`
|
||||
Network *Network `yaml:"network"`
|
||||
Pools map[string]*IPRange `yaml:"pools"`
|
||||
Statics map[string]net.IP `yaml:"statics"`
|
||||
Version int `yaml:"version"`
|
||||
Interface string `yaml:"interface"`
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
LeaseFile string `yaml:"lease_file"`
|
||||
Network *Network `yaml:"network"`
|
||||
Pools map[string]*iptools.Range `yaml:"pools"`
|
||||
Statics map[string]net.IP `yaml:"statics"`
|
||||
}
|
||||
|
||||
func (cfg *Config) process() (err error) {
|
||||
@@ -114,7 +98,7 @@ func (cfg *Config) process() (err error) {
|
||||
}
|
||||
|
||||
for k, v := range cfg.Pools {
|
||||
if err = v.ensureV4(); err != nil {
|
||||
if err = v.Validate(); err != nil {
|
||||
return fmt.Errorf("config: pool %s %w", k, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user