From 8806c357ddacd6184c9d35c071e58416d191d0b7 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Thu, 1 Sep 2022 23:41:33 +0800 Subject: [PATCH] feat: dhcp basic config --- cmd/config/decode.go | 10 ++++++++++ cmd/config/main.go | 3 +++ cmd/dhcp/main.go | 11 +++++++++++ cmd/process/daemon.go | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 cmd/dhcp/main.go diff --git a/cmd/config/decode.go b/cmd/config/decode.go index af0f602..4510053 100644 --- a/cmd/config/decode.go +++ b/cmd/config/decode.go @@ -4,6 +4,7 @@ import ( "XProxy/cmd/asset" "XProxy/cmd/common" "XProxy/cmd/custom" + "XProxy/cmd/dhcp" "XProxy/cmd/proxy" "XProxy/cmd/radvd" "encoding/json" @@ -20,6 +21,7 @@ type NetConfig struct { type RawConfig struct { Asset asset.Config `yaml:"asset" json:"asset"` Radvd radvd.Config `yaml:"radvd" json:"radvd"` + DHCP dhcp.Config `yaml:"dhcp" json:"dhcp"` Proxy proxy.Config `yaml:"proxy" json:"proxy"` Custom custom.Config `yaml:"custom" json:"custom"` Network struct { @@ -163,6 +165,14 @@ func decodeRadvd(rawConfig *RawConfig, config *Config) { log.Debugf("Radvd DNSSL -> %v", config.Radvd.DNSSL) } +func decodeDhcp(rawConfig *RawConfig, config *Config) { + config.DHCP = rawConfig.DHCP + log.Debugf("DHCPv4 enable -> %t", config.DHCP.IPv4.Enable) + log.Debugf("DHCPv4 config -> \n%s", config.DHCP.IPv4.Configure) + log.Debugf("DHCPv6 enable -> %t", config.DHCP.IPv6.Enable) + log.Debugf("DHCPv6 config -> \n%s", config.DHCP.IPv6.Configure) +} + func decodeUpdate(rawConfig *RawConfig, config *Config) { config.Asset = rawConfig.Asset if config.Asset.Update.Proxy != "" { diff --git a/cmd/config/main.go b/cmd/config/main.go index 449ed59..f670a37 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -4,6 +4,7 @@ import ( "XProxy/cmd/asset" "XProxy/cmd/common" "XProxy/cmd/custom" + "XProxy/cmd/dhcp" "XProxy/cmd/network" "XProxy/cmd/proxy" "XProxy/cmd/radvd" @@ -21,6 +22,7 @@ type Config struct { Asset asset.Config Radvd radvd.Config Custom custom.Config + DHCP dhcp.Config } func Load(configFile string, config *Config) { @@ -43,4 +45,5 @@ func Load(configFile string, config *Config) { decodeUpdate(&rawConfig, config) decodeCustom(&rawConfig, config) decodeRadvd(&rawConfig, config) + decodeDhcp(&rawConfig, config) } diff --git a/cmd/dhcp/main.go b/cmd/dhcp/main.go new file mode 100644 index 0000000..24874a6 --- /dev/null +++ b/cmd/dhcp/main.go @@ -0,0 +1,11 @@ +package dhcp + +type dhcpConfig struct { + Enable bool `yaml:"enable" json:"enable"` + Configure string `yaml:"config" json:"config"` +} + +type Config struct { + IPv4 dhcpConfig `yaml:"ipv4" json:"ipv4"` + IPv6 dhcpConfig `yaml:"ipv6" json:"ipv6"` +} diff --git a/cmd/process/daemon.go b/cmd/process/daemon.go index 5721368..d1275f1 100644 --- a/cmd/process/daemon.go +++ b/cmd/process/daemon.go @@ -10,7 +10,7 @@ func daemonSub(sub *Process) { sub.Wait() } log.Warningf("Catch process %s exit", sub.name) - time.Sleep(3 * time.Second) // delay 3s -> try to restart + time.Sleep(5 * time.Second) // delay 3s -> try to restart if !exitFlag { sub.Run(true, sub.env) log.Infof("Process %s restart success", sub.name)