|
@ -28,12 +28,12 @@ type yamlConfig struct { |
|
|
AddOn []interface{} `yaml:"addon"` |
|
|
AddOn []interface{} `yaml:"addon"` |
|
|
} `yaml:"proxy"` |
|
|
} `yaml:"proxy"` |
|
|
Network struct { |
|
|
Network struct { |
|
|
DNS []string `yaml:"dns"` // system dns server
|
|
|
DNS []string `yaml:"dns" json:"dns"` |
|
|
ByPass []string `yaml:"bypass"` // cidr bypass list
|
|
|
ByPass []string `yaml:"bypass" json:"bypass"` |
|
|
IPv4 yamlNetConfig `yaml:"ipv4"` // ipv4 network configure
|
|
|
IPv4 yamlNetConfig `yaml:"ipv4" json:"ipv4"` |
|
|
IPv6 yamlNetConfig `yaml:"ipv6"` // ipv6 network configure
|
|
|
IPv6 yamlNetConfig `yaml:"ipv6" json:"ipv6"` |
|
|
} `yaml:"network"` |
|
|
} `yaml:"network" json:"network"` |
|
|
Radvd radvd.Config `yaml:"radvd"` |
|
|
Radvd radvd.Config `yaml:"radvd" json:"radvd"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func yamlDecode(raw []byte) yamlConfig { |
|
|
func yamlDecode(raw []byte) yamlConfig { |
|
@ -46,59 +46,53 @@ func yamlDecode(raw []byte) yamlConfig { |
|
|
return config |
|
|
return config |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func decodeDns(rawConfig *yamlConfig) []string { |
|
|
func decodeDns(rawConfig *yamlConfig, config *Config) { |
|
|
var dns []string |
|
|
|
|
|
for _, address := range rawConfig.Network.DNS { // dns options
|
|
|
for _, address := range rawConfig.Network.DNS { // dns options
|
|
|
if common.IsIPv4(address, false) || common.IsIPv6(address, false) { |
|
|
if common.IsIPv4(address, false) || common.IsIPv6(address, false) { |
|
|
dns = append(dns, address) |
|
|
config.DNS = append(config.DNS, address) |
|
|
} else { |
|
|
} else { |
|
|
log.Panicf("Invalid DNS server -> %s", address) |
|
|
log.Panicf("Invalid DNS server -> %s", address) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
log.Debugf("DNS server -> %v", dns) |
|
|
log.Debugf("DNS server -> %v", config.DNS) |
|
|
return dns |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func decodeBypass(rawConfig *yamlConfig) ([]string, []string) { |
|
|
func decodeBypass(rawConfig *yamlConfig, config *Config) { |
|
|
var v4Bypass, v6Bypass []string |
|
|
|
|
|
for _, address := range rawConfig.Network.ByPass { // bypass options
|
|
|
for _, address := range rawConfig.Network.ByPass { // bypass options
|
|
|
if common.IsIPv4(address, true) { |
|
|
if common.IsIPv4(address, true) { |
|
|
v4Bypass = append(v4Bypass, address) |
|
|
config.IPv4.Bypass = append(config.IPv4.Bypass, address) |
|
|
} else if common.IsIPv6(address, true) { |
|
|
} else if common.IsIPv6(address, true) { |
|
|
v6Bypass = append(v6Bypass, address) |
|
|
config.IPv6.Bypass = append(config.IPv6.Bypass, address) |
|
|
} else { |
|
|
} else { |
|
|
log.Panicf("Invalid bypass CIDR -> %s", address) |
|
|
log.Panicf("Invalid bypass CIDR -> %s", address) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
log.Debugf("IPv4 bypass CIDR -> %s", v4Bypass) |
|
|
log.Debugf("IPv4 bypass CIDR -> %s", config.IPv4.Bypass) |
|
|
log.Debugf("IPv6 bypass CIDR -> %s", v6Bypass) |
|
|
log.Debugf("IPv6 bypass CIDR -> %s", config.IPv6.Bypass) |
|
|
return v4Bypass, v6Bypass |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func decodeIPv4(rawConfig *yamlConfig) (string, string) { |
|
|
func decodeIPv4(rawConfig *yamlConfig, config *Config) { |
|
|
v4Address := rawConfig.Network.IPv4.Address |
|
|
config.IPv4.Address = rawConfig.Network.IPv4.Address |
|
|
v4Gateway := rawConfig.Network.IPv4.Gateway |
|
|
config.IPv4.Gateway = rawConfig.Network.IPv4.Gateway |
|
|
if v4Address != "" && !common.IsIPv4(v4Address, true) { |
|
|
if config.IPv4.Address != "" && !common.IsIPv4(config.IPv4.Address, true) { |
|
|
log.Panicf("Invalid IPv4 address -> %s", v4Address) |
|
|
log.Panicf("Invalid IPv4 address (CIDR) -> %s", config.IPv4.Address) |
|
|
} |
|
|
} |
|
|
if v4Gateway != "" && !common.IsIPv4(v4Gateway, false) { |
|
|
if config.IPv4.Gateway != "" && !common.IsIPv4(config.IPv4.Gateway, false) { |
|
|
log.Panicf("Invalid IPv4 gateway -> %s", v4Gateway) |
|
|
log.Panicf("Invalid IPv4 gateway -> %s", config.IPv4.Gateway) |
|
|
} |
|
|
} |
|
|
log.Debugf("IPv4 -> address = %s | gateway = %s", v4Address, v4Gateway) |
|
|
log.Debugf("IPv4 -> address = %s | gateway = %s", config.IPv4.Address, config.IPv4.Gateway) |
|
|
return v4Address, v4Gateway |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func decodeIPv6(rawConfig *yamlConfig) (string, string) { |
|
|
func decodeIPv6(rawConfig *yamlConfig, config *Config) { |
|
|
v6Address := rawConfig.Network.IPv6.Address |
|
|
config.IPv6.Address = rawConfig.Network.IPv6.Address |
|
|
v6Gateway := rawConfig.Network.IPv6.Gateway |
|
|
config.IPv6.Gateway = rawConfig.Network.IPv6.Gateway |
|
|
if v6Address != "" && !common.IsIPv6(v6Address, true) { |
|
|
if config.IPv6.Address != "" && !common.IsIPv6(config.IPv6.Address, true) { |
|
|
log.Panicf("Invalid IPv6 address -> %s", v6Address) |
|
|
log.Panicf("Invalid IPv6 address (CIDR) -> %s", config.IPv6.Address) |
|
|
} |
|
|
} |
|
|
if v6Gateway != "" && !common.IsIPv6(v6Gateway, false) { |
|
|
if config.IPv6.Gateway != "" && !common.IsIPv6(config.IPv6.Gateway, false) { |
|
|
log.Panicf("Invalid IPv6 gateway -> %s", v6Gateway) |
|
|
log.Panicf("Invalid IPv6 gateway -> %s", config.IPv6.Gateway) |
|
|
} |
|
|
} |
|
|
log.Debugf("IPv6 -> address = %s | gateway = %s", v6Address, v6Gateway) |
|
|
log.Debugf("IPv6 -> address = %s | gateway = %s", config.IPv6.Address, config.IPv6.Gateway) |
|
|
return v6Address, v6Gateway |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func decodeProxy(rawConfig *yamlConfig, config *Config) { |
|
|
func decodeProxy(rawConfig *yamlConfig, config *Config) { |
|
@ -142,10 +136,10 @@ func decodeCustom(rawConfig *yamlConfig) []string { |
|
|
func decode(rawConfig yamlConfig) Config { |
|
|
func decode(rawConfig yamlConfig) Config { |
|
|
var config Config |
|
|
var config Config |
|
|
config.LogLevel = rawConfig.Proxy.Log |
|
|
config.LogLevel = rawConfig.Proxy.Log |
|
|
config.DNS = decodeDns(&rawConfig) |
|
|
decodeDns(&rawConfig, &config) |
|
|
config.V4Bypass, config.V6Bypass = decodeBypass(&rawConfig) |
|
|
decodeBypass(&rawConfig, &config) |
|
|
config.V4Address, config.V4Gateway = decodeIPv4(&rawConfig) |
|
|
decodeIPv4(&rawConfig, &config) |
|
|
config.V6Address, config.V6Gateway = decodeIPv6(&rawConfig) |
|
|
decodeIPv6(&rawConfig, &config) |
|
|
decodeProxy(&rawConfig, &config) |
|
|
decodeProxy(&rawConfig, &config) |
|
|
decodeUpdate(&rawConfig, &config) |
|
|
decodeUpdate(&rawConfig, &config) |
|
|
config.Script = decodeCustom(&rawConfig) |
|
|
config.Script = decodeCustom(&rawConfig) |
|
|