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, |
Johnathan Mantey | 817012a | 2020-01-30 15:07:39 -0800 | [diff] [blame] | 25 | const std::string& objPath, DHCPConf dhcpEnabled, |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 26 | bool nicEnabled, uint32_t vlanID, |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 27 | EthernetInterface& intf, Manager& parent) : |
| 28 | VlanIface(bus, objPath.c_str()), |
| 29 | DeleteIface(bus, objPath.c_str()), |
William A. Kennington III | 26275a3 | 2021-07-13 20:32:42 -0700 | [diff] [blame] | 30 | EthernetInterface(bus, objPath, dhcpEnabled, parent, /*emitSignal=*/false, |
| 31 | nicEnabled), |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 32 | parentInterface(intf) |
| 33 | { |
| 34 | id(vlanID); |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 35 | VlanIface::interfaceName(EthernetInterface::interfaceName()); |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 36 | MacAddressIntf::macAddress(parentInterface.macAddress()); |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 37 | |
| 38 | emit_object_added(); |
| 39 | } |
| 40 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 41 | std::string VlanInterface::macAddress(std::string) |
William A. Kennington III | a2145bf | 2019-04-19 13:15:56 -0700 | [diff] [blame] | 42 | { |
| 43 | log<level::ERR>("Tried to set MAC address on VLAN"); |
| 44 | elog<InternalFailure>(); |
| 45 | } |
| 46 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 47 | void VlanInterface::writeDeviceFile() |
| 48 | { |
| 49 | using namespace std::string_literals; |
| 50 | fs::path confPath = manager.getConfDir(); |
| 51 | std::string fileName = EthernetInterface::interfaceName() + ".netdev"s; |
| 52 | confPath /= fileName; |
| 53 | std::fstream stream; |
| 54 | try |
| 55 | { |
| 56 | stream.open(confPath.c_str(), std::fstream::out); |
| 57 | } |
Patrick Williams | 5758db3 | 2021-10-06 12:29:22 -0500 | [diff] [blame] | 58 | catch (const std::ios_base::failure& e) |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 59 | { |
| 60 | log<level::ERR>("Unable to open the VLAN device file", |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 61 | entry("FILE=%s", confPath.c_str()), |
| 62 | entry("ERROR=%s", e.what())); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 63 | elog<InternalFailure>(); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 64 | } |
| 65 | |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 66 | stream << "[NetDev]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 67 | stream << "Name=" << EthernetInterface::interfaceName() << "\n"; |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 68 | stream << "Kind=vlan\n"; |
| 69 | stream << "[VLAN]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 70 | stream << "Id=" << id() << "\n"; |
| 71 | stream.close(); |
| 72 | } |
| 73 | |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 74 | void VlanInterface::delete_() |
| 75 | { |
| 76 | parentInterface.deleteVLANObject(EthernetInterface::interfaceName()); |
| 77 | } |
| 78 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 79 | } // namespace network |
| 80 | } // namespace phosphor |