summaryrefslogtreecommitdiffstats
path: root/utils.cpp
diff options
context:
space:
mode:
authorRatan Gupta <ratagupt@in.ibm.com>2017-07-30 10:39:22 +0530
committerRatan Gupta <ratagupt@in.ibm.com>2017-08-13 22:26:01 +0530
commit533d03b5f923e6c59ca1ffb16b6a5eb14e3f96c6 (patch)
tree54b2119d2fbc24774d214f48a5e0ff327d23bf0e /utils.cpp
parentb8e9955db5216a0b170a2fb99125d1f22bb9d1c0 (diff)
downloadphosphor-host-ipmid-533d03b5f923e6c59ca1ffb16b6a5eb14e3f96c6.tar.gz
phosphor-host-ipmid-533d03b5f923e6c59ca1ffb16b6a5eb14e3f96c6.zip
Add support for vlan(set lan command)
Resolves openbmc/openbmc#1899 Change-Id: I3c436045676bc96e5d91fd9420509bc991549a13 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
Diffstat (limited to 'utils.cpp')
-rw-r--r--utils.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/utils.cpp b/utils.cpp
index 11dc2d4..2e6c5e7 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -339,6 +339,32 @@ void createIP(sdbusplus::bus::bus& bus,
}
+void createVLAN(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& objPath,
+ const std::string& interfaceName,
+ uint32_t vlanID)
+{
+ auto busMethod = bus.new_method_call(
+ service.c_str(),
+ objPath.c_str(),
+ VLAN_CREATE_INTERFACE,
+ "VLAN");
+
+ busMethod.append(interfaceName, vlanID);
+
+ auto reply = bus.call(busMethod);
+
+ if (reply.is_method_error())
+ {
+ log<level::ERR>("Failed to excute method",
+ entry("METHOD=%s", "VLAN"),
+ entry("PATH=%s", objPath.c_str()));
+ elog<InternalFailure>();
+ }
+
+}
+
uint8_t toPrefix(int addressFamily, const std::string& subnetMask)
{
if (addressFamily == AF_INET6)
@@ -370,7 +396,34 @@ uint8_t toPrefix(int addressFamily, const std::string& subnetMask)
}
}
-} // namespace network
-} // namespace ipmi
+uint32_t getVLAN(const std::string& path)
+{
+ // Path would be look like
+ // /xyz/openbmc_project/network/eth0_443/ipv4
+
+ uint32_t vlanID = 0;
+ try
+ {
+ auto intfObjectPath = path.substr(0,
+ path.find(IP_TYPE) - 1);
+
+ auto intfName = intfObjectPath.substr(intfObjectPath.rfind("/") + 1);
+ auto index = intfName.find("_");
+ if (index != std::string::npos)
+ {
+ auto str = intfName.substr(index + 1);
+ vlanID = std::stoul(str);
+ }
+ }
+ catch (std::exception & e)
+ {
+ log<level::ERR>("Exception occured during getVLAN",
+ entry("PATH=%s",path.c_str()),
+ entry("EXCEPTIOn=%s", e.what()));
+ }
+ return vlanID;
+}
+} // namespace network
+} // namespace ipmi
OpenPOWER on IntegriCloud