Browse Source

feat: dns and bypass config

v1.x.x
dnomd343 2 years ago
parent
commit
657ae22d12
  1. 23
      src/config.go
  2. 28
      src/main.go
  3. 14
      test.yml

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

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

14
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
Loading…
Cancel
Save