Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 3 | #include "vlan_interface.hpp" |
| 4 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 5 | #include "ethernet_interface.hpp" |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 6 | #include "network_manager.hpp" |
| 7 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 8 | #include <algorithm> |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 9 | #include <experimental/filesystem> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 10 | #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 Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
| 20 | |
| 21 | using namespace phosphor::logging; |
| 22 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 23 | |
| 24 | VlanInterface::VlanInterface(sdbusplus::bus::bus& bus, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 25 | const std::string& objPath, bool dhcpEnabled, |
| 26 | uint32_t vlanID, EthernetInterface& intf, |
| 27 | Manager& parent) : |
| 28 | VlanIface(bus, objPath.c_str()), |
| 29 | DeleteIface(bus, objPath.c_str()), |
| 30 | EthernetInterface(bus, objPath, dhcpEnabled, parent, false), |
| 31 | parentInterface(intf) |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 32 | { |
| 33 | id(vlanID); |
| 34 | VlanIface::interfaceName(EthernetInterface::interfaceName()); |
Ratan Gupta | bd303b1 | 2017-08-18 17:10:07 +0530 | [diff] [blame] | 35 | MacAddressIntf::mACAddress(parentInterface.mACAddress()); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 36 | |
Ratan Gupta | 26e87a0 | 2017-08-18 01:08:40 +0530 | [diff] [blame] | 37 | emit_object_added(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 38 | } |
| 39 | |
William A. Kennington III | a2145bf | 2019-04-19 13:15:56 -0700 | [diff] [blame] | 40 | std::string VlanInterface::mACAddress(std::string) |
| 41 | { |
| 42 | log<level::ERR>("Tried to set MAC address on VLAN"); |
| 43 | elog<InternalFailure>(); |
| 44 | } |
| 45 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 46 | void 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 | } |
| 57 | catch (std::ios_base::failure& e) |
| 58 | { |
| 59 | log<level::ERR>("Unable to open the VLAN device file", |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 60 | entry("FILE=%s", confPath.c_str()), |
| 61 | entry("ERROR=%s", e.what())); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 62 | elog<InternalFailure>(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 63 | } |
| 64 | |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 65 | stream << "[NetDev]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 66 | stream << "Name=" << EthernetInterface::interfaceName() << "\n"; |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 67 | stream << "Kind=vlan\n"; |
| 68 | stream << "[VLAN]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 69 | stream << "Id=" << id() << "\n"; |
| 70 | stream.close(); |
| 71 | } |
| 72 | |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 73 | void VlanInterface::delete_() |
| 74 | { |
| 75 | parentInterface.deleteVLANObject(EthernetInterface::interfaceName()); |
| 76 | } |
| 77 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 78 | } // namespace network |
| 79 | } // namespace phosphor |