blob: 6fa3b84ab138e3b667774a2318403f4d6c01ec92 [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
24VlanInterface::VlanInterface(sdbusplus::bus::bus& bus,
Gunnar Mills57d9c502018-09-14 14:42:34 -050025 const std::string& objPath, bool dhcpEnabled,
Manojkiran Edaca8b91b2020-05-28 09:28:42 +053026 bool nICEnabled, uint32_t vlanID,
27 EthernetInterface& intf, Manager& parent) :
28 VlanIface(bus, objPath.c_str()),
29 DeleteIface(bus, objPath.c_str()),
30 EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
31 parentInterface(intf)
32{
33 id(vlanID);
34 EthernetInterfaceIntf::nICEnabled(nICEnabled);
35 VlanIface::interfaceName(EthernetInterface::interfaceName());
36 MacAddressIntf::mACAddress(parentInterface.mACAddress());
37
38 emit_object_added();
39}
40
41VlanInterface::VlanInterface(sdbusplus::bus::bus& bus,
42 const std::string& objPath, bool dhcpEnabled,
Gunnar Mills57d9c502018-09-14 14:42:34 -050043 uint32_t vlanID, EthernetInterface& intf,
44 Manager& parent) :
45 VlanIface(bus, objPath.c_str()),
46 DeleteIface(bus, objPath.c_str()),
47 EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
48 parentInterface(intf)
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053049{
50 id(vlanID);
51 VlanIface::interfaceName(EthernetInterface::interfaceName());
Ratan Guptabd303b12017-08-18 17:10:07 +053052 MacAddressIntf::mACAddress(parentInterface.mACAddress());
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053053
Ratan Gupta26e87a02017-08-18 01:08:40 +053054 emit_object_added();
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053055}
56
William A. Kennington IIIa2145bf2019-04-19 13:15:56 -070057std::string VlanInterface::mACAddress(std::string)
58{
59 log<level::ERR>("Tried to set MAC address on VLAN");
60 elog<InternalFailure>();
61}
62
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053063void VlanInterface::writeDeviceFile()
64{
65 using namespace std::string_literals;
66 fs::path confPath = manager.getConfDir();
67 std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
68 confPath /= fileName;
69 std::fstream stream;
70 try
71 {
72 stream.open(confPath.c_str(), std::fstream::out);
73 }
74 catch (std::ios_base::failure& e)
75 {
76 log<level::ERR>("Unable to open the VLAN device file",
Gunnar Mills57d9c502018-09-14 14:42:34 -050077 entry("FILE=%s", confPath.c_str()),
78 entry("ERROR=%s", e.what()));
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053079 elog<InternalFailure>();
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053080 }
81
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040082 stream << "[NetDev]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053083 stream << "Name=" << EthernetInterface::interfaceName() << "\n";
Ratan K Gupta1a054ae2018-09-15 00:49:51 -040084 stream << "Kind=vlan\n";
85 stream << "[VLAN]\n";
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053086 stream << "Id=" << id() << "\n";
87 stream.close();
88}
89
Ratan Guptabc886292017-07-25 18:29:57 +053090void VlanInterface::delete_()
91{
92 parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
93}
94
Gunnar Mills57d9c502018-09-14 14:42:34 -050095} // namespace network
96} // namespace phosphor