blob: a93940f4d1a313538d12df2e0c3fa6ed8c3897a3 [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
Patrick Venture189d44e2018-07-09 12:30:59 -07003#include "dhcp_configuration.hpp"
Ratan Gupta05eb1092017-04-14 16:33:53 +05304#include "ethernet_interface.hpp"
William A. Kennington IIIe0564842021-10-23 16:02:22 -07005#include "routing_table.hpp"
Ratan Guptaef85eb92017-06-15 08:57:54 +05306#include "system_configuration.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05307#include "vlan_interface.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include "xyz/openbmc_project/Network/VLAN/Create/server.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05309
Manojkiran Edaa879baa2020-06-13 14:39:08 +053010#include <filesystem>
Ratan Gupta05eb1092017-04-14 16:33:53 +053011#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053012#include <memory>
Patrick Venture189d44e2018-07-09 12:30:59 -070013#include <sdbusplus/bus.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053014#include <string>
15#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070016#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053017
18namespace phosphor
19{
20namespace network
21{
22
Ratan Gupta2b106532017-07-25 16:05:02 +053023using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
24using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
25
Manojkiran Edaa879baa2020-06-13 14:39:08 +053026namespace fs = std::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053027namespace details
28{
29
Michael Tritz29f2fd62017-05-22 15:27:26 -050030template <typename T, typename U>
31using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053032
Michael Tritz29f2fd62017-05-22 15:27:26 -050033using VLANCreateIface = details::ServerObject<
34 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
35 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053036
Ratan Gupta05eb1092017-04-14 16:33:53 +053037} // namespace details
38
39/** @class Manager
40 * @brief OpenBMC network manager implementation.
41 */
42class Manager : public details::VLANCreateIface
43{
Gunnar Mills57d9c502018-09-14 14:42:34 -050044 public:
45 Manager() = delete;
46 Manager(const Manager&) = delete;
47 Manager& operator=(const Manager&) = delete;
48 Manager(Manager&&) = delete;
49 Manager& operator=(Manager&&) = delete;
50 virtual ~Manager() = default;
Ratan Gupta05eb1092017-04-14 16:33:53 +053051
Gunnar Mills57d9c502018-09-14 14:42:34 -050052 /** @brief Constructor to put object onto bus at a dbus path.
53 * @param[in] bus - Bus to attach to.
54 * @param[in] objPath - Path to attach at.
55 * @param[in] dir - Network Configuration directory path.
56 */
57 Manager(sdbusplus::bus::bus& bus, const char* objPath,
58 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053059
Patrick Williams8173e022021-05-01 06:39:41 -050060 ObjectPath vlan(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053061
Gunnar Mills57d9c502018-09-14 14:42:34 -050062 /** @brief write the network conf file with the in-memory objects.
63 */
64 void writeToConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053065
Gunnar Mills57d9c502018-09-14 14:42:34 -050066 /** @brief Fetch the interface and the ipaddress details
67 * from the system and create the ethernet interraces
68 * dbus object.
69 */
Manojkiran Edaacd6dd52019-10-15 15:00:51 +053070 virtual void createInterfaces();
Ratan Gupta29b0e432017-05-25 12:51:40 +053071
Gunnar Mills57d9c502018-09-14 14:42:34 -050072 /** @brief create child interface object and the system conf object.
73 */
74 void createChildObjects();
Ratan Guptaef85eb92017-06-15 08:57:54 +053075
Gunnar Mills57d9c502018-09-14 14:42:34 -050076 /** @brief sets the network conf directory.
77 * @param[in] dirName - Absolute path of the directory.
78 */
79 void setConfDir(const fs::path& dir);
Ratan Guptaef85eb92017-06-15 08:57:54 +053080
Gunnar Mills57d9c502018-09-14 14:42:34 -050081 /** @brief gets the network conf directory.
82 */
83 fs::path getConfDir()
84 {
85 return confDir;
86 }
Ratan Gupta255d5142017-08-10 09:02:08 +053087
Gunnar Mills57d9c502018-09-14 14:42:34 -050088 /** @brief gets the system conf object.
89 *
90 */
91 const SystemConfPtr& getSystemConf()
92 {
93 return systemConf;
94 }
Ratan Gupta05eb1092017-04-14 16:33:53 +053095
Gunnar Mills57d9c502018-09-14 14:42:34 -050096 /** @brief gets the dhcp conf object.
97 *
98 */
99 const DHCPConfPtr& getDHCPConf()
100 {
101 return dhcpConf;
102 }
Ratan Gupta2b106532017-07-25 16:05:02 +0530103
Gunnar Mills57d9c502018-09-14 14:42:34 -0500104 /** @brief create the default network files for each interface
105 * @detail if force param is true then forcefully create the network
106 * files otherwise if network file doesn't exist then
107 * create it.
108 * @param[in] force - forcefully create the file
109 * @return true if network file created else false
110 */
111 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530112
Gunnar Mills57d9c502018-09-14 14:42:34 -0500113 /** @brief restart the network timers. */
114 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530115
Manojkiran Edacc099a82020-05-11 14:25:16 +0530116 /** @brief This function gets the MAC address from the VPD and
117 * sets it on the corresponding ethernet interface during first
118 * Boot, once it sets the MAC from VPD, it creates a file named
119 * firstBoot under /var/lib to make sure we dont run this function
120 * again.
121 *
122 * @param[in] ethPair - Its a pair of ethernet interface name & the
123 * corresponding MAC Address from the VPD
124 *
125 * return - NULL
126 */
127 void setFistBootMACOnInterface(
128 const std::pair<std::string, std::string>& ethPair);
129
Ratan Gupta895f9e52018-11-26 20:57:34 +0530130 /** @brief Restart the systemd unit
131 * @param[in] unit - systemd unit name which needs to be
132 * restarted.
133 */
Ratan Gupta35297172018-11-28 18:40:16 +0530134 virtual void restartSystemdUnit(const std::string& unit);
Ratan Gupta895f9e52018-11-26 20:57:34 +0530135
William A. Kennington III56ecc782021-10-07 18:44:50 -0700136 /** @brief Tell systemd-network to reload all of the network configurations
137 */
138 virtual void reloadConfigs();
139
Patrick Ventured94d23e2019-01-07 13:05:23 -0800140 /** @brief Returns the number of interfaces under this manager.
141 *
142 * @return the number of interfaces managed by this manager.
143 */
144 int getInterfaceCount()
145 {
146 return interfaces.size();
147 }
148
149 /** @brief Does the requested interface exist under this manager?
150 *
151 * @param[in] intf - the interface name to check.
152 * @return true if found, false otherwise.
153 */
154 bool hasInterface(const std::string& intf)
155 {
156 return (interfaces.find(intf) != interfaces.end());
157 }
158
William A. Kennington IIIe0564842021-10-23 16:02:22 -0700159 /** @brief Get the routing table owned by the manager
160 *
161 * @return Routing table reference.
162 */
163 inline const auto& getRouteTable() const
164 {
165 return routeTable;
166 }
167
Ratan Gupta35297172018-11-28 18:40:16 +0530168 protected:
Gunnar Mills57d9c502018-09-14 14:42:34 -0500169 /** @brief Persistent sdbusplus DBus bus connection. */
170 sdbusplus::bus::bus& bus;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530171
Gunnar Mills57d9c502018-09-14 14:42:34 -0500172 /** @brief Persistent map of EthernetInterface dbus objects and their names
173 */
174 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530175
Gunnar Mills57d9c502018-09-14 14:42:34 -0500176 /** @brief BMC network reset - resets network configuration for BMC. */
177 void reset() override;
Michael Tritz29f2fd62017-05-22 15:27:26 -0500178
Gunnar Mills57d9c502018-09-14 14:42:34 -0500179 /** @brief Path of Object. */
180 std::string objectPath;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530181
Gunnar Mills57d9c502018-09-14 14:42:34 -0500182 /** @brief pointer to system conf object. */
183 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530184
Gunnar Mills57d9c502018-09-14 14:42:34 -0500185 /** @brief pointer to dhcp conf object. */
186 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530187
Gunnar Mills57d9c502018-09-14 14:42:34 -0500188 /** @brief Network Configuration directory. */
189 fs::path confDir;
William A. Kennington IIIe0564842021-10-23 16:02:22 -0700190
191 /** @brief The routing table */
192 route::Table routeTable;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530193};
194
195} // namespace network
196} // namespace phosphor