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> |
Manojkiran Eda | a879baa | 2020-06-13 14:39:08 +0530 | [diff] [blame] | 9 | #include <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, |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 26 | 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 | |
| 41 | VlanInterface::VlanInterface(sdbusplus::bus::bus& bus, |
| 42 | const std::string& objPath, bool dhcpEnabled, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 43 | 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 Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 49 | { |
| 50 | id(vlanID); |
| 51 | VlanIface::interfaceName(EthernetInterface::interfaceName()); |
Ratan Gupta | bd303b1 | 2017-08-18 17:10:07 +0530 | [diff] [blame] | 52 | MacAddressIntf::mACAddress(parentInterface.mACAddress()); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 53 | |
Ratan Gupta | 26e87a0 | 2017-08-18 01:08:40 +0530 | [diff] [blame] | 54 | emit_object_added(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 55 | } |
| 56 | |
William A. Kennington III | a2145bf | 2019-04-19 13:15:56 -0700 | [diff] [blame] | 57 | std::string VlanInterface::mACAddress(std::string) |
| 58 | { |
| 59 | log<level::ERR>("Tried to set MAC address on VLAN"); |
| 60 | elog<InternalFailure>(); |
| 61 | } |
| 62 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 63 | void 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 Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 77 | entry("FILE=%s", confPath.c_str()), |
| 78 | entry("ERROR=%s", e.what())); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 79 | elog<InternalFailure>(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 80 | } |
| 81 | |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 82 | stream << "[NetDev]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 83 | stream << "Name=" << EthernetInterface::interfaceName() << "\n"; |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 84 | stream << "Kind=vlan\n"; |
| 85 | stream << "[VLAN]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 86 | stream << "Id=" << id() << "\n"; |
| 87 | stream.close(); |
| 88 | } |
| 89 | |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 90 | void VlanInterface::delete_() |
| 91 | { |
| 92 | parentInterface.deleteVLANObject(EthernetInterface::interfaceName()); |
| 93 | } |
| 94 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 95 | } // namespace network |
| 96 | } // namespace phosphor |