#include <vector>
#include <fcntl.h>
#include <cassert>
+#include <linux/if_link.h>
using namespace std;
return out;
}
+enum macvlan_mode macvlanFromString(const std::string& mode) {
+ if (mode == "private") {
+ return MACVLAN_MODE_PRIVATE;
+ }
+ if (mode == "vepa") {
+ return MACVLAN_MODE_VEPA;
+ }
+ if (mode == "bridge") {
+ return MACVLAN_MODE_BRIDGE;
+ }
+ if (mode == "passthru") {
+ return MACVLAN_MODE_PASSTHRU;
+ }
+ throw runtime_error("Unsupported macvlan mode");
+}
+
} // namespace
void CommandLineInterface::printUsage(std::ostream& out) const
one_shot(bind(vsm_revoke_device, _1, argv[pos + 1], argv[pos + 2]));
}
+void create_netdev_veth(int pos, int argc, const char** argv)
+{
+ using namespace std::placeholders;
+
+ if (argc <= pos + 3) {
+ throw runtime_error("Not enough parameters");
+ }
+ one_shot(bind(vsm_create_netdev_veth,
+ _1,
+ argv[pos + 1],
+ argv[pos + 2],
+ argv[pos + 3]));
+}
+
+void create_netdev_macvlan(int pos, int argc, const char** argv)
+{
+ using namespace std::placeholders;
+
+ if (argc <= pos + 4) {
+ throw runtime_error("Not enough parameters");
+ }
+ one_shot(bind(vsm_create_netdev_macvlan,
+ _1,
+ argv[pos + 1],
+ argv[pos + 2],
+ argv[pos + 3],
+ macvlanFromString(argv[pos + 4])));
+}
+
+void create_netdev_phys(int pos, int argc, const char** argv)
+{
+ using namespace std::placeholders;
+
+ if (argc <= pos + 2) {
+ throw runtime_error("Not enough parameters");
+ }
+ one_shot(bind(vsm_create_netdev_phys,
+ _1,
+ argv[pos + 1],
+ argv[pos + 2]));
+}
+
} // namespace cli
} // namespace vasum
*/
void revoke_device(int pos, int argc, const char** argv);
+/**
+ * Parses command line arguments and call vsm_create_netdev_veth
+ *
+ * @see vsm_create_netdev_veth
+ */
+void create_netdev_veth(int pos, int argc, const char** argv);
+
+/**
+ * Parses command line arguments and call vsm_create_netdev_macvlan
+ *
+ * @see vsm_create_netdev_macvlan
+ */
+void create_netdev_macvlan(int pos, int argc, const char** argv);
+
+/**
+ * Parses command line arguments and call vsm_create_netdev_phys
+ *
+ * @see vsm_create_netdev_phys
+ */
+void create_netdev_phys(int pos, int argc, const char** argv);
} // namespace cli
} // namespace vasum
{{"zone_id", "id zone name"},
{"device_name", " device name"}}
}
+ },
+ {
+ "create_netdev_veth", {
+ create_netdev_veth,
+ "create_netdev_veth zone_id zoneDev hostDev",
+ "Create netdev in zone",
+ {{"zone_id", "id zone name"},
+ {"zoneDev", "network device id"},
+ {"hostDev", "host bridge id"}}
+ }
+ },
+ {
+ "create_netdev_macvlan", {
+ create_netdev_macvlan,
+ "create_netdev_macvlan zone_id zoneDev hostDev mode",
+ "Create netdev in zone",
+ {{"zone_id", "id zone name"},
+ {"zoneDev", "network device id"},
+ {"hostDev", "host bridge id"},
+ {"mode", "macvlan mode (private, vepa, bridge, passthru)"}}
+ }
+ },
+ {
+ "create_netdev_phys", {
+ create_netdev_phys,
+ "create_netdev_phys zone_id devId",
+ "Create/move netdev to zone",
+ {{"zone_id", "id zone name"},
+ {"devId", "network device id"}}
+ }
}
};
*scArray = ids;
}
-VsmStatus toStatus(const std::exception& ex)
+VsmStatus toStatus(const exception& ex)
{
if (typeid(DbusCustomException) == typeid(ex)) {
return VSMCLIENT_CUSTOM_ERROR;
return VSMCLIENT_OTHER_ERROR;
}
-bool readFirstLineOfFile(const std::string& path, std::string& ret)
+bool readFirstLineOfFile(const string& path, string& ret)
{
- std::ifstream file(path);
+ ifstream file(path);
if (!file) {
return false;
}
- std::getline(file, ret);
+ getline(file, ret);
return true;
}
{
}
-Client::Status::Status(VsmStatus status, const std::string& msg)
+Client::Status::Status(VsmStatus status, const string& msg)
: mVsmStatus(status), mMsg(msg)
{
}
SignalCallback signalCallback,
VsmSubscriptionId* subscriptionId)
{
- auto onSignal = [=](const std::string& /*senderBusName*/,
- const std::string & objectPath,
- const std::string & interface,
- const std::string & signalName,
+ auto onSignal = [=](const string& /*senderBusName*/,
+ const string & objectPath,
+ const string & interface,
+ const string & signalName,
GVariant * parameters) {
if (objectPath == info.objectPath &&
interface == info.interface &&
*subscriptionId = id;
}
mStatus = Status();
- } catch (const std::exception& ex) {
+ } catch (const exception& ex) {
mStatus = Status(toStatus(ex), ex.what());
}
return vsm_get_status();
try {
mConnection->signalUnsubscribe(id);
mStatus = Status();
- } catch (const std::exception& ex) {
+ } catch (const exception& ex) {
mStatus = Status(toStatus(ex), ex.what());
}
return vsm_get_status();
{
assert(id);
- const std::string path = "/proc/" + std::to_string(pid) + "/cpuset";
+ const string path = "/proc/" + to_string(pid) + "/cpuset";
- std::string cpuset;
+ string cpuset;
if (!readFirstLineOfFile(path, cpuset)) {
mStatus = Status(VSMCLIENT_INVALID_ARGUMENT, "Process not found");
return vsm_get_status();
}
- std::string zoneId;
+ string zoneId;
if (!parseZoneIdFromCpuSet(cpuset, zoneId)) {
mStatus = Status(VSMCLIENT_OTHER_ERROR, "unknown format of cpuset");
return vsm_get_status();
return vsm_get_status();
}
-VsmStatus Client::vsm_create_netdev(const char*, VsmNetdevType, const char*, const char*) noexcept
+VsmStatus Client::vsm_create_netdev_veth(const char* zone,
+ const char* zoneDev,
+ const char* hostDev) noexcept
{
- mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
- return vsm_get_status();
+ GVariant* args_in = g_variant_new("(sss)", zone, zoneDev, hostDev);
+ return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_VETH, args_in);
}
-VsmStatus Client::vsm_destroy_netdev(const char*, const char*) noexcept
+VsmStatus Client::vsm_create_netdev_macvlan(const char* zone,
+ const char* zoneDev,
+ const char* hostDev,
+ enum macvlan_mode mode) noexcept
+{
+ GVariant* args_in = g_variant_new("(sssu)", zone, zoneDev, hostDev, mode);
+ return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_MACVLAN, args_in);
+}
+
+VsmStatus Client::vsm_create_netdev_phys(const char* zone, const char* devId) noexcept
+{
+ GVariant* args_in = g_variant_new("(ss)", zone, devId);
+ return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_PHYS, args_in);
+}
+
+VsmStatus Client::vsm_lookup_netdev_by_name(const char*, const char*, VsmNetdev*) noexcept
{
mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
return vsm_get_status();
}
-VsmStatus Client::vsm_lookup_netdev_by_name(const char*, const char*, VsmNetdev*) noexcept
+VsmStatus Client::vsm_destroy_netdev(const char*, const char*) noexcept
{
mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
return vsm_get_status();
#include "vasum-client.h"
#include <dbus/connection.hpp>
#include <exception>
+#include <linux/if_link.h>
/**
* Structure which defines the dbus interface.
int prefix) noexcept;
/**
- * @see ::vsm_create_netdev
+ * @see ::vsm_create_netdev_veth
*/
- VsmStatus vsm_create_netdev(const char* zone,
- VsmNetdevType netdevType,
- const char* target,
- const char* netdevId) noexcept;
+ VsmStatus vsm_create_netdev_veth(const char* zone,
+ const char* zoneDev,
+ const char* hostDev) noexcept;
/**
- * @see ::vsm_destroy_netdev
+ * @see ::vsm_create_netdev_macvlan
+ */
+ VsmStatus vsm_create_netdev_macvlan(const char* zone,
+ const char* zoneDev,
+ const char* hostDev,
+ enum macvlan_mode mode) noexcept;
+
+ /**
+ * @see ::vsm_create_netdev_phys
*/
- VsmStatus vsm_destroy_netdev(const char* zone, const char* netdevId) noexcept;
+ VsmStatus vsm_create_netdev_phys(const char* zone, const char* devId) noexcept;
/**
* @see ::vsm_lookup_netdev_by_name
VsmNetdev* netdev) noexcept;
/**
+ * @see ::vsm_destroy_netdev
+ */
+ VsmStatus vsm_destroy_netdev(const char* zone, const char* devId) noexcept;
+
+ /**
* @see ::vsm_declare_file
*/
VsmStatus vsm_declare_file(const char* zone,
return getClient(client).vsm_netdev_set_ipv6_addr(zone, netdevId, addr, prefix);
}
-API VsmStatus vsm_create_netdev(VsmClient client,
- const char* zone,
- VsmNetdevType netdevType,
- const char* target,
- const char* netdevId)
+API VsmStatus vsm_create_netdev_veth(VsmClient client,
+ const char* zone,
+ const char* zoneDev,
+ const char* hostDev)
+{
+ return getClient(client).vsm_create_netdev_veth(zone, zoneDev, hostDev);
+}
+
+API VsmStatus vsm_create_netdev_macvlan(VsmClient client,
+ const char* zone,
+ const char* zoneDev,
+ const char* hostDev,
+ enum macvlan_mode mode)
{
- return getClient(client).vsm_create_netdev(zone, netdevType, target, netdevId);
+ return getClient(client).vsm_create_netdev_macvlan(zone, zoneDev, hostDev, mode);
}
-API VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* netdevId)
+API VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId)
{
- return getClient(client).vsm_destroy_netdev(zone, netdevId);
+ return getClient(client).vsm_create_netdev_phys(zone, devId);
}
API VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
return getClient(client).vsm_lookup_netdev_by_name(zone, netdevId, netdev);
}
+API VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId)
+{
+ return getClient(client).vsm_destroy_netdev(zone, devId);
+}
+
API VsmStatus vsm_declare_file(VsmClient client,
const char* zone,
VsmFileType type,
#include <stdint.h>
#include <sys/stat.h>
#include <netinet/ip.h>
+#include <linux/if_link.h>
#ifdef __cplusplus
extern "C"
int prefix);
/**
- * Create netdev in zone
+ * Create veth netdev in zone
*
* @param[in] client vasum-server's client
* @param[in] zone zone name
- * @param[in] netdevType netdev type
- * @param[in] target TODO: this is taken form zone-control
- * @param[in] netdevId network device id
+ * @param[in] zoneDev in host network device id
+ * @param[in] hostDev in zone network device id
* @return status of this function call
*/
-VsmStatus vsm_create_netdev(VsmClient client,
- const char* zone,
- VsmNetdevType netdevType,
- const char* target,
- const char* netdevId);
-
+VsmStatus vsm_create_netdev_veth(VsmClient client,
+ const char* zone,
+ const char* zoneDev,
+ const char* hostDev);
/**
- * Remove netdev from zone
+ * Create macvlab in zone
*
* @param[in] client vasum-server's client
* @param[in] zone zone name
- * @param[in] netdevId network device id
+ * @param[in] zoneDev in host network device id
+ * @param[in] hostDev in zone network device id
+ * @return status of this function call
+ */
+VsmStatus vsm_create_netdev_macvlan(VsmClient client,
+ const char* zone,
+ const char* zoneDev,
+ const char* hostDev,
+ enum macvlan_mode mode);
+/**
+ * Create/move phys netdev in/to zone
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone name
+ * @param[in] devId network device id
* @return status of this function call
*/
-VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* netdevId);
+VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
/**
* Get netdev informations
VsmNetdev* netdev);
/**
+ * Remove netdev from zone
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone name
+ * @param[in] devId network device id
+ * @return status of this function call
+ */
+VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
+
+/**
* Create file, directory or pipe in zone
*
* Declare file, directory or pipe that will be created while zone startup
std::string getSystemErrorMessage()
{
+ return getSystemErrorMessage(errno);
+}
+
+std::string getSystemErrorMessage(int err)
+{
char buf[ERROR_MESSAGE_BUFFER_CAPACITY];
- return strerror_r(errno, buf, sizeof(buf));
+ return strerror_r(err, buf, sizeof(buf));
}
} // namespace vasum
* it is wrapper for strerror_r
*/
std::string getSystemErrorMessage();
+std::string getSystemErrorMessage(int err);
} // namespace vasum
mGetZoneInfoCallback = callback;
}
+void HostConnection::setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback)
+{
+ mCreateNetdevVethCallback = callback;
+}
+
+void HostConnection::setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback)
+{
+ mCreateNetdevMacvlanCallback = callback;
+}
+
+void HostConnection::setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback)
+{
+ mCreateNetdevPhysCallback = callback;
+}
+
void HostConnection::setDeclareFileCallback(const DeclareFileCallback& callback)
{
mDeclareFileCallback = callback;
return;
}
+ if (methodName == api::host::METHOD_CREATE_NETDEV_VETH) {
+ const gchar* id = NULL;
+ const gchar* zoneDev = NULL;
+ const gchar* hostDev = NULL;
+ g_variant_get(parameters, "(&s&s&s)", &id, &zoneDev, &hostDev);
+ if (mCreateNetdevVethCallback) {
+ mCreateNetdevVethCallback(id, zoneDev, hostDev, result);
+ }
+ return;
+ }
+
+ if (methodName == api::host::METHOD_CREATE_NETDEV_MACVLAN) {
+ const gchar* id = NULL;
+ const gchar* zoneDev = NULL;
+ const gchar* hostDev = NULL;
+ guint32 mode;
+ g_variant_get(parameters, "(&s&s&su)", &id, &zoneDev, &hostDev, &mode);
+ if (mCreateNetdevMacvlanCallback) {
+ mCreateNetdevMacvlanCallback(id, zoneDev, hostDev, mode, result);
+ }
+ }
+
+ if (methodName == api::host::METHOD_CREATE_NETDEV_PHYS) {
+ const gchar* id = NULL;
+ const gchar* devId = NULL;
+ g_variant_get(parameters, "(&s&s)", &id, &devId);
+ if (mCreateNetdevPhysCallback) {
+ mCreateNetdevPhysCallback(id, devId, result);
+ }
+ }
+
if (methodName == api::host::METHOD_DECLARE_FILE) {
const gchar* zone;
int32_t type;
typedef std::function<void(const std::string& id,
dbus::MethodResultBuilder::Pointer result
)> GetZoneInfoCallback;
+ typedef std::function<void(const std::string& id,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ dbus::MethodResultBuilder::Pointer result
+ )> CreateNetdevVethCallback;
+ typedef std::function<void(const std::string& id,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode,
+ dbus::MethodResultBuilder::Pointer result
+ )> CreateNetdevMacvlanCallback;
+ typedef std::function<void(const std::string& id,
+ const std::string& devId,
+ dbus::MethodResultBuilder::Pointer result
+ )> CreateNetdevPhysCallback;
typedef std::function<void(const std::string& zone,
const int32_t& type,
const std::string& path,
void setGetZoneInfoCallback(const GetZoneInfoCallback& callback);
/**
+ * Register a callback called to create veth
+ */
+ void setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback);
+
+ /**
+ * Register a callback called to create macvlan
+ */
+ void setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback);
+
+ /**
+ * Register a callback called to create/move phys
+ */
+ void setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback);
+
+ /**
* Register a callback called to declare file
*/
void setDeclareFileCallback(const DeclareFileCallback& callback);
GetZoneIdsCallback mGetZoneIdsCallback;
GetActiveZoneIdCallback mGetActiveZoneIdCallback;
GetZoneInfoCallback mGetZoneInfoCallback;
+ CreateNetdevVethCallback mCreateNetdevVethCallback;
+ CreateNetdevMacvlanCallback mCreateNetdevMacvlanCallback;
+ CreateNetdevPhysCallback mCreateNetdevPhysCallback;
DeclareFileCallback mDeclareFileCallback;
DeclareMountCallback mDeclareMountCallback;
DeclareLinkCallback mDeclareLinkCallback;
namespace api {
namespace host {
-const std::string BUS_NAME = "org.tizen.vasum.host";
-const std::string OBJECT_PATH = "/org/tizen/vasum/host";
-const std::string INTERFACE = "org.tizen.vasum.host.manager";
+const std::string BUS_NAME = "org.tizen.vasum.host";
+const std::string OBJECT_PATH = "/org/tizen/vasum/host";
+const std::string INTERFACE = "org.tizen.vasum.host.manager";
-const std::string ERROR_ZONE_NOT_RUNNING = "org.tizen.vasum.host.Error.ZonesNotRunning";
+const std::string ERROR_ZONE_NOT_RUNNING = "org.tizen.vasum.host.Error.ZonesNotRunning";
-const std::string METHOD_GET_ZONE_DBUSES = "GetZoneDbuses";
-const std::string METHOD_GET_ZONE_ID_LIST = "GetZoneIds";
-const std::string METHOD_GET_ACTIVE_ZONE_ID = "GetActiveZoneId";
-const std::string METHOD_GET_ZONE_INFO = "GetZoneInfo";
-const std::string METHOD_DECLARE_FILE = "DeclareFile";
-const std::string METHOD_DECLARE_MOUNT = "DeclareMount";
-const std::string METHOD_DECLARE_LINK = "DeclareLink";
-const std::string METHOD_GET_DECLARATIONS = "GetDeclarations";
-const std::string METHOD_REMOVE_DECLARATION = "RemoveDeclaration";
-const std::string METHOD_SET_ACTIVE_ZONE = "SetActiveZone";
-const std::string METHOD_CREATE_ZONE = "CreateZone";
-const std::string METHOD_DESTROY_ZONE = "DestroyZone";
-const std::string METHOD_SHUTDOWN_ZONE = "ShutdownZone";
-const std::string METHOD_START_ZONE = "StartZone";
-const std::string METHOD_LOCK_ZONE = "LockZone";
-const std::string METHOD_UNLOCK_ZONE = "UnlockZone";
-const std::string METHOD_GRANT_DEVICE = "GrantDevice";
-const std::string METHOD_REVOKE_DEVICE = "RevokeDevice";
+const std::string METHOD_GET_ZONE_DBUSES = "GetZoneDbuses";
+const std::string METHOD_GET_ZONE_ID_LIST = "GetZoneIds";
+const std::string METHOD_GET_ACTIVE_ZONE_ID = "GetActiveZoneId";
+const std::string METHOD_GET_ZONE_INFO = "GetZoneInfo";
+const std::string METHOD_CREATE_NETDEV_VETH = "CreateNetdevVeth";
+const std::string METHOD_CREATE_NETDEV_MACVLAN = "CreateNetdevMacvlan";
+const std::string METHOD_CREATE_NETDEV_PHYS = "CreateNetdevPhys";
+const std::string METHOD_DECLARE_FILE = "DeclareFile";
+const std::string METHOD_DECLARE_MOUNT = "DeclareMount";
+const std::string METHOD_DECLARE_LINK = "DeclareLink";
+const std::string METHOD_GET_DECLARATIONS = "GetDeclarations";
+const std::string METHOD_REMOVE_DECLARATION = "RemoveDeclaration";
+const std::string METHOD_SET_ACTIVE_ZONE = "SetActiveZone";
+const std::string METHOD_CREATE_ZONE = "CreateZone";
+const std::string METHOD_DESTROY_ZONE = "DestroyZone";
+const std::string METHOD_SHUTDOWN_ZONE = "ShutdownZone";
+const std::string METHOD_START_ZONE = "StartZone";
+const std::string METHOD_LOCK_ZONE = "LockZone";
+const std::string METHOD_UNLOCK_ZONE = "UnlockZone";
+const std::string METHOD_GRANT_DEVICE = "GrantDevice";
+const std::string METHOD_REVOKE_DEVICE = "RevokeDevice";
-const std::string SIGNAL_ZONE_DBUS_STATE = "ZoneDbusState";
+const std::string SIGNAL_ZONE_DBUS_STATE = "ZoneDbusState";
const std::string DEFINITION =
" <arg type='s' name='id' direction='in'/>"
" <arg type='(siss)' name='result' direction='out'/>"
" </method>"
+ " <method name='" + METHOD_CREATE_NETDEV_VETH + "'>"
+ " <arg type='s' name='id' direction='in'/>"
+ " <arg type='s' name='zoneDev' direction='in'/>"
+ " <arg type='s' name='hostDev' direction='in'/>"
+ " </method>"
+ " <method name='" + METHOD_CREATE_NETDEV_MACVLAN + "'>"
+ " <arg type='s' name='id' direction='in'/>"
+ " <arg type='s' name='zoneDev' direction='in'/>"
+ " <arg type='s' name='hostDev' direction='in'/>"
+ " <arg type='u' name='mode' direction='in'/>"
+ " </method>"
+ " <method name='" + METHOD_CREATE_NETDEV_PHYS + "'>"
+ " <arg type='s' name='id' direction='in'/>"
+ " <arg type='s' name='devId' direction='in'/>"
+ " </method>"
" <method name='" + METHOD_DECLARE_FILE + "'>"
" <arg type='s' name='zone' direction='in'/>"
" <arg type='i' name='type' direction='in'/>"
return 0;
}
+void ZoneAdmin::createNetdevVeth(const std::string& /* zoneDev */,
+ const std::string& /* hostDev */)
+{
+ throw ZoneOperationException("Not implemented");
+}
+
+void ZoneAdmin::createNetdevMacvlan(const std::string& /* zoneDev */,
+ const std::string& /* hostDev */,
+ const uint32_t& /* mode */)
+{
+ throw ZoneOperationException("Not implemented");
+}
+
+void ZoneAdmin::moveNetdev(const std::string& /* devId */)
+{
+ throw ZoneOperationException("Not implemented");
+}
} // namespace vasum
*/
std::int64_t getSchedulerQuota();
+ /**
+ * Create veth network device
+ */
+ void createNetdevVeth(const std::string& zoneDev,
+ const std::string& hostDev);
+
+ /**
+ * Create macvlan network device
+ */
+ void createNetdevMacvlan(const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode);
+
+ /**
+ * Move network device to zone
+ */
+ void moveNetdev(const std::string& devId);
+
private:
const ZoneConfig& mConfig;
lxc::LxcZone mZone;
return true;
}
+void Zone::createNetdevVeth(const std::string& zoneDev,
+ const std::string& hostDev)
+{
+ Lock lock(mReconnectMutex);
+ mAdmin->createNetdevVeth(zoneDev, hostDev);
+}
+
+void Zone::createNetdevMacvlan(const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode)
+{
+ Lock lock(mReconnectMutex);
+ mAdmin->createNetdevMacvlan(zoneDev, hostDev, mode);
+}
+
+void Zone::moveNetdev(const std::string& devId)
+{
+ Lock lock(mReconnectMutex);
+ mAdmin->moveNetdev(devId);
+}
+
void Zone::goForeground()
{
Lock lock(mReconnectMutex);
*/
std::string getRootPath() const;
+ /**
+ * Create veth network device
+ */
+ void createNetdevVeth(const std::string& zoneDev,
+ const std::string& hostDev);
+
+ /**
+ * Create macvlan network device
+ */
+ void createNetdevMacvlan(const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode);
+
+ /**
+ * Move network device to zone
+ */
+ void moveNetdev(const std::string& devId);
+
private:
utils::Worker::Pointer mWorker;
ZoneConfig mConfig;
mHostConnection.setGetZoneInfoCallback(bind(&ZonesManager::handleGetZoneInfoCall,
this, _1, _2));
+ mHostConnection.setCreateNetdevVethCallback(bind(&ZonesManager::handleCreateNetdevVethCall,
+ this, _1, _2, _3, _4));
+
+ mHostConnection.setCreateNetdevMacvlanCallback(bind(&ZonesManager::handleCreateNetdevMacvlanCall,
+ this, _1, _2, _3, _4, _5));
+
+ mHostConnection.setCreateNetdevPhysCallback(bind(&ZonesManager::handleCreateNetdevPhysCall,
+ this, _1, _2, _3));
+
mHostConnection.setDeclareFileCallback(bind(&ZonesManager::handleDeclareFileCall,
this, _1, _2, _3, _4, _5, _6));
zone.getRootPath().c_str()));
}
+void ZonesManager::handleCreateNetdevVethCall(const std::string& zone,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ dbus::MethodResultBuilder::Pointer result)
+{
+ LOGI("CreateNetdevVeth call");
+ try {
+ Lock lock(mMutex);
+
+ getZone(zone).createNetdevVeth(zoneDev, hostDev);
+ result->setVoid();
+ } catch (const std::out_of_range&) {
+ LOGE("No zone with id=" << zone);
+ result->setError(api::ERROR_INVALID_ID, "No such zone id");
+ } catch (const VasumException& ex) {
+ LOGE("Can't create veth: " << ex.what());
+ result->setError(api::ERROR_INTERNAL, ex.what());
+ }
+}
+
+void ZonesManager::handleCreateNetdevMacvlanCall(const std::string& zone,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode,
+ dbus::MethodResultBuilder::Pointer result)
+{
+ LOGI("CreateNetdevMacvlan call");
+ try {
+ Lock lock(mMutex);
+
+ getZone(zone).createNetdevMacvlan(zoneDev, hostDev, mode);
+ result->setVoid();
+ } catch (const std::out_of_range&) {
+ LOGE("No zone with id=" << zone);
+ result->setError(api::ERROR_INVALID_ID, "No such zone id");
+ } catch (const VasumException& ex) {
+ LOGE("Can't create macvlan: " << ex.what());
+ result->setError(api::ERROR_INTERNAL, ex.what());
+ }
+}
+
+void ZonesManager::handleCreateNetdevPhysCall(const std::string& zone,
+ const std::string& devId,
+ dbus::MethodResultBuilder::Pointer result)
+{
+ LOGI("CreateNetdevPhys call");
+ try {
+ Lock lock(mMutex);
+
+ getZone(zone).moveNetdev(devId);
+ result->setVoid();
+ } catch (const std::out_of_range&) {
+ LOGE("No zone with id=" << zone);
+ result->setError(api::ERROR_INVALID_ID, "No such zone id");
+ } catch (const VasumException& ex) {
+ LOGE("Can't create netdev: " << ex.what());
+ result->setError(api::ERROR_INTERNAL, ex.what());
+ }
+}
+
void ZonesManager::handleDeclareFileCall(const std::string& zone,
const int32_t& type,
const std::string& path,
void handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result);
void handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result);
void handleGetZoneInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result);
+ void handleCreateNetdevVethCall(const std::string& zone,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ dbus::MethodResultBuilder::Pointer result);
+ void handleCreateNetdevMacvlanCall(const std::string& zone,
+ const std::string& zoneDev,
+ const std::string& hostDev,
+ const uint32_t& mode,
+ dbus::MethodResultBuilder::Pointer result);
+ void handleCreateNetdevPhysCall(const std::string& zone,
+ const std::string& devId,
+ dbus::MethodResultBuilder::Pointer result);
void handleDeclareFileCall(const std::string& zone,
const int32_t& type,
const std::string& path,