BUGFIX stopJail: Destroy interfaces once, whatever the current configuration
This commit is contained in:
parent
199b3b1f7f
commit
7ca633d946
39
cmd/stop.go
39
cmd/stop.go
@ -7,8 +7,8 @@ import (
|
||||
"sync"
|
||||
"errors"
|
||||
"regexp"
|
||||
"slices"
|
||||
"os/exec"
|
||||
//"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -83,26 +83,39 @@ func umountAndUnjailZFS(jail *Jail) error {
|
||||
}
|
||||
|
||||
func destroyVNetInterfaces(jail *Jail) error {
|
||||
if !strings.EqualFold(jail.Config.Ip4_addr, "none") {
|
||||
// Wherever ipv6/ipv4 is enabled, if interface exist we destroy it
|
||||
var vnetnames []string
|
||||
for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
|
||||
if len(strings.Split(i, "|")) == 2 {
|
||||
iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
|
||||
fmt.Printf("%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("OK\n")
|
||||
if !slices.Contains(vnetnames, iname) {
|
||||
vnetnames = append(vnetnames, iname)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !strings.EqualFold(jail.Config.Ip6_addr, "none") {
|
||||
for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
|
||||
if len(strings.Split(i, "|")) == 2 {
|
||||
iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
|
||||
fmt.Printf("%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
|
||||
if !slices.Contains(vnetnames, iname) {
|
||||
vnetnames = append(vnetnames, iname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, iname := range vnetnames {
|
||||
fmt.Printf(" >%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s", iname))
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "does not exist") {
|
||||
fmt.Printf("OK\n")
|
||||
} else {
|
||||
fmt.Printf("ERR: %v\n", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
if err != nil {
|
||||
fmt.Printf("ERR: %v\n", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("OK\n")
|
||||
|
Loading…
Reference in New Issue
Block a user