iptables now being set by client

This commit is contained in:
afeiszli
2021-04-15 09:48:14 -04:00
parent 77914d22b0
commit e2ec093eaf
9 changed files with 78 additions and 13 deletions

View File

@@ -678,12 +678,41 @@ func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig
Stderr: os.Stdout,
}
err = cmdIPLinkDown.Run()
err = cmdIPLinkUp.Run()
if err != nil {
if nodecfg.PostDown != "" {
runcmds := strings.Split(nodecfg.PostDown, "; ")
err = runCmds(runcmds)
if err != nil {
fmt.Println("Error encountered running PostDown: " + err.Error())
}
}
err = cmdIPLinkUp.Run()
if nodecfg.PostUp != "" {
runcmds := strings.Split(nodecfg.PostUp, "; ")
err = runCmds(runcmds)
if err != nil {
fmt.Println("Error encountered running PostUp: " + err.Error())
}
}
if err != nil {
return err
}
return err
}
func runCmds(commands []string) error {
var err error
for _, command := range commands {
fmt.Println("Running command: " + command)
args := strings.Fields(command)
out, err := exec.Command(args[0], args[1:]...).Output()
fmt.Println(string(out))
if err != nil {
return err
}
}
return err
}
func setWGKeyConfig(network string, serveraddr string) error {
@@ -959,7 +988,7 @@ func CheckIn(network string) error {
if ifaceupdate {
fmt.Println("Interface update: " + currentiface +
" >>>> " + newinterface)
err := DeleteInterface(currentiface)
err := DeleteInterface(currentiface, nodecfg.PostDown)
if err != nil {
fmt.Println("ERROR DELETING INTERFACE: " + currentiface)
}
@@ -1206,12 +1235,19 @@ func WipeLocal(network string) error{
if err != nil {
fmt.Println(err)
}
if nodecfg.PostDown != "" {
runcmds := strings.Split(nodecfg.PostDown, "; ")
err = runCmds(runcmds)
if err != nil {
fmt.Println("Error encountered running PostDown: " + err.Error())
}
}
}
return err
}
func DeleteInterface(ifacename string) error{
func DeleteInterface(ifacename string, postdown string) error{
ipExec, err := exec.LookPath("ip")
cmdIPLinkDel := &exec.Cmd {
@@ -1224,6 +1260,13 @@ func DeleteInterface(ifacename string) error{
if err != nil {
fmt.Println(err)
}
if postdown != "" {
runcmds := strings.Split(postdown, "; ")
err = runCmds(runcmds)
if err != nil {
fmt.Println("Error encountered running PostDown: " + err.Error())
}
}
return err
}