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 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 24 | VlanInterface::VlanInterface(sdbusplus::bus_t& bus, const std::string& objPath, |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 25 | const config::Parser& config, DHCPConf dhcpEnabled, |
| 26 | bool nicEnabled, uint32_t vlanID, |
| 27 | EthernetInterface& intf, Manager& parent) : |
Manojkiran Eda | ca8b91b | 2020-05-28 09:28:42 +0530 | [diff] [blame] | 28 | VlanIface(bus, objPath.c_str()), |
| 29 | DeleteIface(bus, objPath.c_str()), |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 30 | EthernetInterface(bus, objPath, config, dhcpEnabled, parent, true, |
| 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 | { |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 49 | auto confPath = config::pathForIntfDev(manager.getConfDir(), |
| 50 | EthernetInterface::interfaceName()); |
| 51 | std::fstream stream(confPath.c_str(), std::fstream::out); |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 52 | |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 53 | stream << "[NetDev]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 54 | stream << "Name=" << EthernetInterface::interfaceName() << "\n"; |
Ratan K Gupta | 1a054ae | 2018-09-15 00:49:51 -0400 | [diff] [blame] | 55 | stream << "Kind=vlan\n"; |
| 56 | stream << "[VLAN]\n"; |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 57 | stream << "Id=" << id() << "\n"; |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 58 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 59 | stream.close(); |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 60 | |
| 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 Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 67 | } |
| 68 | |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 69 | void VlanInterface::delete_() |
| 70 | { |
| 71 | parentInterface.deleteVLANObject(EthernetInterface::interfaceName()); |
| 72 | } |
| 73 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 74 | } // namespace network |
| 75 | } // namespace phosphor |