Browse Source

feat: dhcp basic config

v1.x.x
dnomd343 2 years ago
parent
commit
8806c357dd
  1. 10
      cmd/config/decode.go
  2. 3
      cmd/config/main.go
  3. 11
      cmd/dhcp/main.go
  4. 2
      cmd/process/daemon.go

10
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 != "" {

3
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)
}

11
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"`
}

2
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)

Loading…
Cancel
Save