Exemple #1
0
func PrepareSandboxNetwork(htn *HostNetwork, log *logging.Logger) (*SandboxNetwork, error) {
	stn := new(SandboxNetwork)

	stn.VethHost = tenus.MakeNetInterfaceName(ozDefaultInterfacePrefix)
	stn.VethGuest = stn.VethHost + "1"

	stn.Gateway = htn.Gateway
	stn.Class = htn.Class

	// Allocate a new IP address
	stn.Ip = getFreshIP(htn.Min, htn.Max, log)
	if stn.Ip == "" {
		return nil, errors.New("Unable to acquire random IP")
	}

	return stn, nil
}
Exemple #2
0
func PrepareSandboxNetwork(stn *SandboxNetwork, htn *HostNetwork, staticByte uint, log *logging.Logger) (*SandboxNetwork, error) {
	if stn == nil {
		stn = new(SandboxNetwork)
		stn.VethHost = tenus.MakeNetInterfaceName(ozDefaultInterfacePrefix)
		stn.VethGuest = stn.VethHost + "1"
	}

	stn.Gateway = htn.Gateway
	stn.Class = htn.Class

	if staticByte > 1 {
		stn.Ip = inet_ntoa(htn.Min - 2 + uint64(staticByte)).String()
	} else {
		// Allocate a new IP address
		stn.Ip = getFreshIP(htn.Min, htn.Max, htn.IpBytes, log)
		if stn.Ip == "" {
			return nil, errors.New("Unable to acquire random IP")
		}
	}

	return stn, nil
}