blob: 4f8583f651943cdf9f4a8a36394a50b846f0b582 [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,
William A. Kennington IIIa520a392022-08-08 12:17:34 -070025 const config::Parser& config, DHCPConf dhcpEnabled,
26 bool nicEnabled, uint32_t vlanID,
27 EthernetInterface& intf, Manager& parent) :
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053028 VlanIface(bus, objPath.c_str()),
29 DeleteIface(bus, objPath.c_str()),
William A. Kennington IIIa520a392022-08-08 12:17:34 -070030 EthernetInterface(bus, objPath, config, dhcpEnabled, parent, true,
31 nicEnabled),
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053032 parentInterface(intf)
33{
34 id(vlanID);
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053035 VlanIface::interfaceName(EthernetInterface::interfaceName());
Patrick Williams6aef7692021-05-01 06:39:41 -050036 MacAddressIntf::macAddress(parentInterface.macAddress());
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053037
38 emit_object_added();
39}
40
Patrick Williams6aef7692021-05-01 06:39:41 -050041std::string VlanInterface::macAddress(std::string)
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070042{
43 log<level::ERR>("Tried to set MAC address on VLAN");
44 elog<InternalFailure>();
45}
46
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053047void VlanInterface::writeDeviceFile()
48{
William A. Kennington IIIa520a392022-08-08 12:17:34 -070049 auto confPath = config::pathForIntfDev(manager.getConfDir(),
50 EthernetInterface::interfaceName());
51 std::fstream stream(confPath.c_str(), std::fstream::out);
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053052
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040053 stream << "[NetDev]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053054 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040055 stream << "Kind=vlan\n";
56 stream << "[VLAN]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053057 stream << "Id=" << id() << "\n";
William A. Kennington IIIa520a392022-08-08 12:17:34 -070058
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053059 stream.close();
William A. Kennington IIIa520a392022-08-08 12:17:34 -070060
61 if (!stream.good())
62 {
63 log<level::ERR>("Unable to write the VLAN device file",
64 entry("FILE=%s", confPath.c_str()));
65 elog<InternalFailure>();
66 }
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053067}
68
Ratan Guptabc886292017-07-25 18:29:57 +053069void VlanInterface::delete_()
70{
71 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
72}
73
Gunnar Mills57d9c502018-09-14 14:42:34 -050074} // namespace network
75} // namespace phosphor