blob: 6e37283f254e28e6520c0a2fb4485d29252c905f [file] [log] [blame]
Gunnar Mills57d9c502018-09-14 14:42:34 -05001#include "config.h"
2
Patrick Venture189d44e2018-07-09 12:30:59 -07003#include "vlan_interface.hpp"
4
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05305#include "ethernet_interface.hpp"
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05306#include "network_manager.hpp"
7
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +05308#include <algorithm>
Manojkiran Edaa879baa2020-06-13 14:39:08 +05309#include <filesystem>
Patrick Venture189d44e2018-07-09 12:30:59 -070010#include <fstream>
11#include <phosphor-logging/elog-errors.hpp>
12#include <phosphor-logging/log.hpp>
13#include <string>
14#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053015
16namespace phosphor
17{
18namespace network
19{
20
21using namespace phosphor::logging;
22using namespace sdbusplus::xyz::openbmc_project::Common::Error;
23
Patrick Williamsc38b0712022-07-22 19:26:54 -050024VlanInterface::VlanInterface(sdbusplus::bus_t& bus, const std::string& objPath,
25 DHCPConf dhcpEnabled, bool nicEnabled,
26 uint32_t vlanID, EthernetInterface& intf,
27 Manager& parent) :
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053028 VlanIface(bus, objPath.c_str()),
29 DeleteIface(bus, objPath.c_str()),
George Liu9ba857f2022-05-09 16:28:47 +080030 EthernetInterface(bus, objPath, dhcpEnabled, parent, true, nicEnabled),
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053031 parentInterface(intf)
32{
33 id(vlanID);
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053034 VlanIface::interfaceName(EthernetInterface::interfaceName());
Patrick Williams6aef7692021-05-01 06:39:41 -050035 MacAddressIntf::macAddress(parentInterface.macAddress());
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053036
37 emit_object_added();
38}
39
Patrick Williams6aef7692021-05-01 06:39:41 -050040std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070041{
42 log<level::ERR>("Tried to set MAC address on VLAN");
43 elog<InternalFailure>();
44}
45
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053046void VlanInterface::writeDeviceFile()
47{
48 using namespace std::string_literals;
49 fs::path confPath = manager.getConfDir();
50 std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
51 confPath /= fileName;
52 std::fstream stream;
53 try
54 {
55 stream.open(confPath.c_str(), std::fstream::out);
56 }
Patrick Williams5758db32021-10-06 12:29:22 -050057 catch (const std::ios_base::failure& e)
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053058 {
59 log<level::ERR>("Unable to open the VLAN device file",
Gunnar Mills57d9c502018-09-14 14:42:34 -050060 entry("FILE=%s", confPath.c_str()),
61 entry("ERROR=%s", e.what()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053062 elog<InternalFailure>();
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053063 }
64
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040065 stream << "[NetDev]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053066 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040067 stream << "Kind=vlan\n";
68 stream << "[VLAN]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053069 stream << "Id=" << id() << "\n";
70 stream.close();
71}
72
Ratan Guptabc886292017-07-25 18:29:57 +053073void VlanInterface::delete_()
74{
75 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
76}
77
Gunnar Mills57d9c502018-09-14 14:42:34 -050078} // namespace network
79} // namespace phosphor