Browse Source

feat: setting up ip configure

v1.x.x
dnomd343 2 years ago
parent
commit
9559445ef8
  1. 6
      src/load.go
  2. 6
      src/main.go
  3. 26
      src/network.go
  4. 4
      test.yml

6
src/load.go

@ -67,6 +67,12 @@ type inboundsSettings struct {
Inbounds []interface{} `json:"inbounds"` Inbounds []interface{} `json:"inbounds"`
} }
func runCommand(command []string) bool {
log.Debugf("Running system command -> %v", command)
// TODO: run system command
return true
}
func isFileExist(filePath string) bool { func isFileExist(filePath string) bool {
s, err := os.Stat(filePath) s, err := os.Stat(filePath)
if err != nil { // file or folder not exist if err != nil { // file or folder not exist

6
src/main.go

@ -25,5 +25,9 @@ func main() {
} }
loadConfig(content) loadConfig(content)
//loadProxy("/etc/xproxy/config", "/xproxy") //loadProxy("/etc/xproxy/config", "/xproxy")
loadDns()
// TODO: load geo assets
//loadDns()
loadNetwork()
} }

26
src/network.go

@ -21,3 +21,29 @@ func loadDns() {
panic("Setting up DNS failed") panic("Setting up DNS failed")
} }
} }
func loadNetwork() {
log.Info("Enabled IP forward")
runCommand([]string{"sysctl", "-w", "net.ipv4.ip_forward=1"})
runCommand([]string{"sysctl", "-w", "net.ipv6.conf.all.forwarding=1"})
log.Info("Flush system IP configure")
runCommand([]string{"ip", "link", "set", "eth0", "down"})
runCommand([]string{"ip", "-4", "addr", "flush", "dev", "eth0"})
runCommand([]string{"ip", "-6", "addr", "flush", "dev", "eth0"})
runCommand([]string{"ip", "link", "set", "eth0", "down"})
log.Info("Setting up system IP configure")
if v4Address != "" {
runCommand([]string{"ip", "-4", "addr", "add", v4Address, "dev", "eth0"})
}
if v4Gateway != "" {
runCommand([]string{"ip", "-4", "route", "add", "default", "via", v4Gateway})
}
if v6Address != "" {
runCommand([]string{"ip", "-6", "addr", "add", v6Address, "dev", "eth0"})
}
if v6Gateway != "" {
runCommand([]string{"ip", "-6", "route", "add", "default", "via", v6Gateway})
}
}

4
test.yml

@ -22,7 +22,9 @@ 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
ipv6: null ipv6:
gateway: null
address: fc00::2/64
bypass: bypass:
- 169.254.0.0/16 - 169.254.0.0/16
- fc00::/7 - fc00::/7

Loading…
Cancel
Save