From ca86beae800d9b62acde3a87765849babadc6588 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 15 Aug 2022 14:45:02 +0800 Subject: [PATCH] feat: ipv4 and ipv6 network settings --- src/config.go | 27 ++++++++++++++++++++++++++- src/main.go | 8 ++++++++ test.yml | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/config.go b/src/config.go index 67a32da..797ecb7 100644 --- a/src/config.go +++ b/src/config.go @@ -11,6 +11,14 @@ var v4Bypass []string var v6Bypass []string var dnsServer []string +var v4Gateway string +var v4Address string +var v4Forward bool + +var v6Gateway string +var v6Address string +var v6Forward bool + type netConfig struct { Gateway string `yaml:"gateway"` // network gateway Address string `yaml:"address"` // network address @@ -81,5 +89,22 @@ func loadConfig(rawConfig []byte) { panic("Invalid bypass CIDR -> " + address) } } - //fmt.Println(config) + v4Address = config.Network.IPv4.Address // ipv4 address + if !isIPv4(v4Address, true, true) { + panic("Invalid IPv4 address -> " + v4Address) + } + v4Gateway = config.Network.IPv4.Gateway // ipv4 gateway + if !isIPv4(v4Gateway, false, true) { + panic("Invalid IPv4 gateway -> " + v4Gateway) + } + v6Address = config.Network.IPv6.Address // ipv6 address + if !isIPv6(v6Address, true, true) { + panic("Invalid IPv6 address -> " + v6Address) + } + v6Gateway = config.Network.IPv6.Gateway // ipv6 gateway + if !isIPv6(v6Gateway, false, true) { + panic("Invalid IPv6 gateway -> " + v6Gateway) + } + v4Forward = config.Network.IPv4.Forward // forward options + v6Forward = config.Network.IPv6.Forward } diff --git a/src/main.go b/src/main.go index dec4e30..9425297 100644 --- a/src/main.go +++ b/src/main.go @@ -15,4 +15,12 @@ func main() { fmt.Println("DNS ->", dnsServer) fmt.Println("v4Bypass ->", v4Bypass) fmt.Println("v6Bypass ->", v6Bypass) + + fmt.Println("v4Gateway ->", v4Gateway) + fmt.Println("v4Address ->", v4Address) + fmt.Println("v6Gateway ->", v6Gateway) + fmt.Println("v6Address ->", v6Address) + + fmt.Println("v4Forward ->", v4Forward) + fmt.Println("v6Forward ->", v6Forward) } diff --git a/test.yml b/test.yml index cdf904c..68127ee 100644 --- a/test.yml +++ b/test.yml @@ -6,7 +6,7 @@ network: ipv4: gateway: 192.168.2.1 address: 192.168.2.2/24 - forward: false + forward: true ipv6: null bypass: - 169.254.0.0/16