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