diff --git a/src/config.go b/src/config.go index d36dd81..67a32da 100644 --- a/src/config.go +++ b/src/config.go @@ -1,13 +1,16 @@ package main import ( - "fmt" "gopkg.in/yaml.v3" "net" "strconv" "strings" ) +var v4Bypass []string +var v6Bypass []string +var dnsServer []string + type netConfig struct { Gateway string `yaml:"gateway"` // network gateway Address string `yaml:"address"` // network address @@ -62,5 +65,21 @@ func loadConfig(rawConfig []byte) { if err != nil { panic(err) } - fmt.Println(config) + for _, address := range config.Network.DNS { // load dns configure + if isIPv4(address, false, false) || isIPv6(address, false, false) { + dnsServer = append(dnsServer, address) + } else { + panic("Invalid DNS server -> " + address) + } + } + for _, address := range config.Network.ByPass { // load bypass configure + if isIPv4(address, true, false) { + v4Bypass = append(v4Bypass, address) + } else if isIPv6(address, true, false) { + v6Bypass = append(v6Bypass, address) + } else { + panic("Invalid bypass CIDR -> " + address) + } + } + //fmt.Println(config) } diff --git a/src/main.go b/src/main.go index e27dedb..dec4e30 100644 --- a/src/main.go +++ b/src/main.go @@ -2,27 +2,17 @@ package main import ( "fmt" + "os" ) func main() { fmt.Println("XProxy start") - - yamlContent := []byte(` -network: - dns: # system's dns server - - 223.5.5.5 - - 119.29.29.29 -# - fesdc.fardf.afa - ipv4: # ipv4 network configure - gateway: 192.168.2.1 - address: 192.168.2.2/24 - forward: false - ipv6: null - bypass: - - 169.254.0.0/16 - - fc00::/7 - - 224.0.0.0/3 -`) - - loadConfig(yamlContent) + content, err := os.ReadFile("test.yml") + if err != nil { + panic(err) + } + loadConfig(content) + fmt.Println("DNS ->", dnsServer) + fmt.Println("v4Bypass ->", v4Bypass) + fmt.Println("v6Bypass ->", v6Bypass) } diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..cdf904c --- /dev/null +++ b/test.yml @@ -0,0 +1,14 @@ +network: + dns: + - 223.5.5.5 + - 119.29.29.29 +# - fesdc.fardf.afa + ipv4: + gateway: 192.168.2.1 + address: 192.168.2.2/24 + forward: false + ipv6: null + bypass: + - 169.254.0.0/16 + - fc00::/7 + - 224.0.0.0/3