BUGFIX setupVnetInterfaceJailSide

This commit is contained in:
yo 2023-08-06 14:50:32 +02:00
parent 14984f417c
commit 549d517cf9

View File

@ -899,7 +899,7 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
return epairs, nil
}
func setupVnetInterfaceJailSide(jail *Jail) error {
func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
var jsmac []byte
var err error
@ -919,7 +919,7 @@ func setupVnetInterfaceJailSide(jail *Jail) error {
}
// Loop through configured interfaces
for _, nicCnf := range strings.Split(jail.Config.Interfaces, ",") {
for i, nicCnf := range strings.Split(jail.Config.Interfaces, ",") {
v := strings.Split(nicCnf, ":")
if len(v) != 2 {
return fmt.Errorf("Invalid value for Interfaces: %s\n", nicCnf)
@ -930,6 +930,8 @@ func setupVnetInterfaceJailSide(jail *Jail) error {
// inside jail final nic name
jnic := strings.Replace(v[0], "vnet", "epair", 1)
jnic = jnic + "b"
// host side associated jail nic name
jsepair := fmt.Sprintf("%sb", strings.TrimSuffix(hostepairs[i], "a"))
// Get jail side MAC
pname := fmt.Sprintf("Config.%s_mac", nic)
@ -948,7 +950,7 @@ func setupVnetInterfaceJailSide(jail *Jail) error {
jsmac = val.Bytes()
}
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jnic, jail.InternalName)
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jsepair, jail.InternalName)
_, err := executeCommand(cmd)
if err != nil {
return fmt.Errorf("Error linking interface to jail: %v\n", err)
@ -960,14 +962,14 @@ func setupVnetInterfaceJailSide(jail *Jail) error {
return fmt.Errorf("Error getting bridge %s mtu: %v\n", bridge, err)
}
cmd = fmt.Sprintf("/usr/sbin/jexec %d ifconfig %s mtu %d", jail.JID, jnic, mtu)
cmd = fmt.Sprintf("/usr/sbin/jexec %d ifconfig %s mtu %d", jail.JID, jsepair, mtu)
_, err = executeCommand(cmd)
if err != nil {
return fmt.Errorf("Error setting mtu: %v\n", err)
}
// rename epairXXb to epair0b (or opair1b, ...)
cmd = fmt.Sprintf("/usr/sbin/setfib %s jexec %d ifconfig %s name %s", jail.Config.Exec_fib, jail.JID, jnic, jnic)
cmd = fmt.Sprintf("/usr/sbin/setfib %s jexec %d ifconfig %s name %s", jail.Config.Exec_fib, jail.JID, jsepair, jnic)
_, err = executeCommand(cmd)
if err != nil {
return fmt.Errorf("Error linking interface to jail: %v\n", err)
@ -1070,9 +1072,9 @@ func StartJailsAtBoot() {
var curThNb int
var curPri int
// Get boot enabled jails
// Get boot enabled non-template jails
for _, j := range gJails {
if j.Config.Boot > 0 {
if j.Config.Boot > 0 && !strings.EqualFold(j.Config.Jailtype, "template") {
startList = append(startList, j)
}
}
@ -1166,7 +1168,7 @@ func StartJail(args []string) {
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, []string{"jail"}, gJails)
cj, err = getJailFromArray(a, []string{"basejail", "jail"}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue
@ -1366,7 +1368,7 @@ func StartJail(args []string) {
}
// Synchronize jail config to disk
writeConfigToDisk(cj, false)
cj.WriteConfigToDisk(false)
start_cmd := fmt.Sprintf("/usr/sbin/jail -f /var/run/jail.%s.conf -c", cj.InternalName)
@ -1416,13 +1418,13 @@ func StartJail(args []string) {
}
fmt.Printf(" > Setup VNet network:\n")
_, err = setupVnetInterfaceHostSide(cj);
hsepairs, err := setupVnetInterfaceHostSide(cj);
if err != nil {
fmt.Printf("Error setting VNet interface host side: %v\n", err)
return
}
if err = setupVnetInterfaceJailSide(cj); err != nil {
if err = setupVnetInterfaceJailSide(cj, hsepairs); err != nil {
fmt.Printf("Error setting VNet interface jail side: %v\n", err)
return
}
@ -1519,7 +1521,6 @@ func StartJail(args []string) {
cj.Config.Last_started = curDate
writeConfigToDisk(cj, false)
/*
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
if err == nil && len(out) > 0 {