Browse Source

feat: ipv4 and ipv6 network settings

v1.x.x
dnomd343 2 years ago
parent
commit
ca86beae80
  1. 27
      src/config.go
  2. 8
      src/main.go
  3. 2
      test.yml

27
src/config.go

@ -11,6 +11,14 @@ var v4Bypass []string
var v6Bypass []string var v6Bypass []string
var dnsServer []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 { 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
@ -81,5 +89,22 @@ func loadConfig(rawConfig []byte) {
panic("Invalid bypass CIDR -> " + address) 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
} }

8
src/main.go

@ -15,4 +15,12 @@ func main() {
fmt.Println("DNS ->", dnsServer) fmt.Println("DNS ->", dnsServer)
fmt.Println("v4Bypass ->", v4Bypass) fmt.Println("v4Bypass ->", v4Bypass)
fmt.Println("v6Bypass ->", v6Bypass) 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)
} }

2
test.yml

@ -6,7 +6,7 @@ network:
ipv4: ipv4:
gateway: 192.168.2.1 gateway: 192.168.2.1
address: 192.168.2.2/24 address: 192.168.2.2/24
forward: false forward: true
ipv6: null ipv6: null
bypass: bypass:
- 169.254.0.0/16 - 169.254.0.0/16

Loading…
Cancel
Save