BUGFIXes on dhcp & multi net handling
This commit is contained in:
parent
fe4192da2d
commit
534deb371c
81
cmd/start.go
81
cmd/start.go
@ -330,8 +330,10 @@ func configureDhcpOrAcceptRtadv(jail *Jail, ipproto int, enable bool) error {
|
||||
|
||||
for _, n := range nics {
|
||||
// vnet0 is epair0b inside jail
|
||||
if strings.Contains(n, "vnet") {
|
||||
n = fmt.Sprintf("%sb", strings.Replace(n, "vnet", "epair", 1))
|
||||
//if strings.Contains(n, "vnet") {
|
||||
if strings.HasPrefix(n, "vnet") {
|
||||
splitd := strings.Split(n, "|")
|
||||
n = fmt.Sprintf("%sb", strings.Replace(splitd[0], "vnet", "epair", 1))
|
||||
}
|
||||
key := fmt.Sprintf("ifconfig_%s", n)
|
||||
value := "SYNCDHCP"
|
||||
@ -342,12 +344,12 @@ func configureDhcpOrAcceptRtadv(jail *Jail, ipproto int, enable bool) error {
|
||||
}
|
||||
|
||||
if enable == true {
|
||||
err := enableRcKeyValue(jail.ConfigPath, key, value)
|
||||
err := enableRcKeyValue(fmt.Sprintf("%s/etc/rc.conf", jail.RootPath), key, value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ERROR setting %s=%s with sysrc for jail %s: %s\n", key, value, jail.Name, err)
|
||||
}
|
||||
} else {
|
||||
err := disableRcKey(jail.ConfigPath, key)
|
||||
err := disableRcKey(fmt.Sprintf("%s/etc/rc.conf", jail.RootPath), key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ERROR deleting %s with sysrc for jail %s: %v\n", key, jail.Name, err)
|
||||
}
|
||||
@ -508,7 +510,7 @@ func buildDevfsRuleSet(jail *Jail, m *sync.Mutex) (error, int) {
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug("buildDevfsRuleSet: Build ruleset %d\n", ruleset)
|
||||
log.Debugf("buildDevfsRuleSet: Build ruleset %d\n", ruleset)
|
||||
|
||||
// Get default devfs_ruleset for the datastore
|
||||
// UPDATE: We don't need this as every jail have a default Devfs_ruleset value
|
||||
@ -893,11 +895,11 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
|
||||
}
|
||||
epairs = append(epairs, hsepair)
|
||||
}
|
||||
|
||||
log.Debugf("setupVnetInterfaceHostSide: returning %v\n", epairs)
|
||||
return epairs, nil
|
||||
}
|
||||
|
||||
func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
||||
func setupVnetInterfaceJailSide(jail *Jail) error {
|
||||
var jsmac []byte
|
||||
var err error
|
||||
|
||||
@ -928,7 +930,7 @@ func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
||||
// inside jail final nic name
|
||||
jnic := strings.Replace(v[0], "vnet", "epair", 1)
|
||||
jnic = jnic + "b"
|
||||
|
||||
|
||||
// Get jail side MAC
|
||||
pname := fmt.Sprintf("Config.%s_mac", nic)
|
||||
var val *reflect.Value
|
||||
@ -945,42 +947,39 @@ func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
||||
} else {
|
||||
jsmac = val.Bytes()
|
||||
}
|
||||
|
||||
lasta := strings.LastIndex(hsepair, "a")
|
||||
jsepair := hsepair[:lasta] + strings.Replace(hsepair[lasta:], "a", "b", 1)
|
||||
|
||||
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jsepair, jail.InternalName)
|
||||
|
||||
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jnic, jail.InternalName)
|
||||
_, err := executeCommand(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error linking interface to jail: %v\n", err)
|
||||
}
|
||||
|
||||
|
||||
// Get bridge MTU
|
||||
mtu, err := gJailHost.GetBridgeMTU(bridge)
|
||||
if err != nil {
|
||||
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, jsepair, mtu)
|
||||
|
||||
cmd = fmt.Sprintf("/usr/sbin/jexec %d ifconfig %s mtu %d", jail.JID, jnic, 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, jsepair, jnic)
|
||||
cmd = fmt.Sprintf("/usr/sbin/setfib %s jexec %d ifconfig %s name %s", jail.Config.Exec_fib, jail.JID, jnic, jnic)
|
||||
_, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error linking interface to jail: %v\n", err)
|
||||
}
|
||||
|
||||
|
||||
cmd = fmt.Sprintf("/usr/sbin/setfib %s jexec %d ifconfig %s link %s", jail.Config.Exec_fib,
|
||||
jail.JID, jnic, hex.EncodeToString(jsmac))
|
||||
_, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error setting mac: %v\n", err)
|
||||
}
|
||||
|
||||
|
||||
// TODO: Move outside of this function
|
||||
// add interface to bridge
|
||||
if jail.Config.Nat == 0 {
|
||||
@ -990,16 +989,16 @@ func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
||||
return fmt.Errorf("Error adding member %s to %s: %v: %s\n", nic, bridge, err, out)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check we have an IP for the nic, and set it into jail
|
||||
if len(ip4s[nic]) > 0 {
|
||||
err = setJailVnetIp(jail, jnic, ip4s[nic])
|
||||
}
|
||||
|
||||
|
||||
if len(ip6s[nic]) > 0 {
|
||||
err = setJailVnetIp(jail, jnic, ip6s[nic])
|
||||
}
|
||||
|
||||
|
||||
// finally up interface
|
||||
if jail.Config.Nat == 0 {
|
||||
cmd := fmt.Sprintf("/sbin/ifconfig %s.%d up", nic, jail.JID)
|
||||
@ -1009,7 +1008,9 @@ func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.Debugf("setupVnetInterfaceJailSide: return with success\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1165,7 +1166,7 @@ func StartJail(args []string) {
|
||||
|
||||
for _, a := range args {
|
||||
// Check if jail exist and is distinctly named
|
||||
cj, err = getJailFromArray(a, gJails)
|
||||
cj, err = getJailFromArray(a, []string{"jail"}, gJails)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting jail: %s\n", err)
|
||||
continue
|
||||
@ -1415,28 +1416,28 @@ func StartJail(args []string) {
|
||||
}
|
||||
|
||||
fmt.Printf(" > Setup VNet network:\n")
|
||||
hsepairs, err := setupVnetInterfaceHostSide(cj);
|
||||
_, err = setupVnetInterfaceHostSide(cj);
|
||||
if err != nil {
|
||||
fmt.Printf("Error setting VNet interface host side: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, ep := range hsepairs {
|
||||
if err = setupVnetInterfaceJailSide(cj, ep); err != nil {
|
||||
fmt.Printf("Error setting VNet interface jail side: %v\n", err)
|
||||
return
|
||||
}
|
||||
if err = setupVnetInterfaceJailSide(cj); err != nil {
|
||||
fmt.Printf("Error setting VNet interface jail side: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf(" > Setup VNet network: OK\n")
|
||||
|
||||
// TODO: Handle DHCP
|
||||
fmt.Printf(" > Setup default ipv4 gateway:\n")
|
||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter)
|
||||
out, err := executeCommand(cmd)
|
||||
if err != nil && len(out) > 0 {
|
||||
fmt.Printf("Error: %v: %s\n", err, out)
|
||||
} else {
|
||||
fmt.Printf(" > Setup default ipv4 gateway: OK\n")
|
||||
// Set default route, unless main network is dhcp
|
||||
if ! cj.isFirstNetDhcp() {
|
||||
fmt.Printf(" > Setup default ipv4 gateway:\n")
|
||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter)
|
||||
out, err := executeCommand(cmd)
|
||||
if err != nil && len(out) > 0 {
|
||||
fmt.Printf("Error: %v: %s\n", err, out)
|
||||
} else {
|
||||
fmt.Printf(" > Setup default ipv4 gateway: OK\n")
|
||||
}
|
||||
}
|
||||
|
||||
if cj.Config.Ip6_addr != "none" {
|
||||
@ -1477,7 +1478,7 @@ func StartJail(args []string) {
|
||||
fmt.Printf(" > Start services:\n")
|
||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d %s", cj.Config.Exec_fib, cj.JID, cj.Config.Exec_start)
|
||||
err := executeCommandNonBlocking(cmd)
|
||||
if err != nil && len(out) > 0 {
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf(" > Start services: OK\n")
|
||||
|
Loading…
Reference in New Issue
Block a user