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 package main
import ( import (
"fmt"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"net" "net"
"strconv" "strconv"
"strings" "strings"
) )
var v4Bypass []string
var v6Bypass []string
var dnsServer []string
type netConfig struct { type netConfig struct {
Gateway string `yaml:"gateway"` // network gateway Gateway string `yaml:"gateway"` // network gateway
Address string `yaml:"address"` // network address Address string `yaml:"address"` // network address
@ -62,5 +65,21 @@ func loadConfig(rawConfig []byte) {
if err != nil { if err != nil {
panic(err) 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 ( import (
"fmt" "fmt"
"os"
) )
func main() { func main() {
fmt.Println("XProxy start") fmt.Println("XProxy start")
content, err := os.ReadFile("test.yml")
yamlContent := []byte(` if err != nil {
network: panic(err)
dns: # system's dns server }
- 223.5.5.5 loadConfig(content)
- 119.29.29.29 fmt.Println("DNS ->", dnsServer)
# - fesdc.fardf.afa fmt.Println("v4Bypass ->", v4Bypass)
ipv4: # ipv4 network configure fmt.Println("v6Bypass ->", v6Bypass)
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)
} }

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