blob: 4db338e145163a9d70d9411f4be19f56602c7a1a [file] [log] [blame]
Ratan Gupta8c834932017-04-14 16:30:24 +05301#pragma once
William A. Kennington III9a20a6e2022-10-05 13:41:12 -07002#include "ipaddress.hpp"
3#include "neighbor.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05304#include "types.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05305#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
William A. Kennington III08505792019-01-30 16:00:04 -08006#include "xyz/openbmc_project/Network/Neighbor/CreateStatic/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +05307
William A. Kennington IIId298f932022-10-17 14:31:38 -07008#include <optional>
Ratan Gupta8c834932017-04-14 16:30:24 +05309#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070011#include <stdplus/zstring_view.hpp>
Ratan Gupta8c834932017-04-14 16:30:24 +053012#include <string>
William A. Kennington III95530ec2022-08-19 01:44:39 -070013#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070014#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
15#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
16#include <xyz/openbmc_project/Network/MACAddress/server.hpp>
Ratan Gupta8c834932017-04-14 16:30:24 +053017
18namespace phosphor
19{
20namespace network
21{
Ratan Gupta8c834932017-04-14 16:30:24 +053022
Patrick Williamsc38b0712022-07-22 19:26:54 -050023using Ifaces = sdbusplus::server::object_t<
Gunnar Mills57d9c502018-09-14 14:42:34 -050024 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
25 sdbusplus::xyz::openbmc_project::Network::server::MACAddress,
26 sdbusplus::xyz::openbmc_project::Network::IP::server::Create,
William A. Kennington III08505792019-01-30 16:00:04 -080027 sdbusplus::xyz::openbmc_project::Network::Neighbor::server::CreateStatic,
Gunnar Mills57d9c502018-09-14 14:42:34 -050028 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Ratan Gupta8c834932017-04-14 16:30:24 +053029
Ratan Gupta82549cc2017-04-21 08:45:23 +053030using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053031
32using EthernetInterfaceIntf =
33 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
Ratan Guptabd303b12017-08-18 17:10:07 +053034using MacAddressIntf =
35 sdbusplus::xyz::openbmc_project::Network::server::MACAddress;
Ratan Gupta87c13982017-06-15 09:27:27 +053036
Ratan Gupta497c0c92017-08-22 19:15:59 +053037using ServerList = std::vector<std::string>;
raviteja-bce379562019-03-28 05:59:36 -050038using ObjectPath = sdbusplus::message::object_path;
Ratan Gupta497c0c92017-08-22 19:15:59 +053039
William A. Kennington III9a20a6e2022-10-05 13:41:12 -070040class Manager;
Ratan Gupta8c834932017-04-14 16:30:24 +053041
Ratan Gupta47722dc2017-05-26 18:32:23 +053042class TestEthernetInterface;
43
Ratan Gupta5978dd12017-07-25 13:47:13 +053044class VlanInterface;
45
William A. Kennington III95530ec2022-08-19 01:44:39 -070046namespace config
47{
48class Parser;
49}
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070050namespace system
William A. Kennington IIId298f932022-10-17 14:31:38 -070051{
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070052struct InterfaceInfo;
William A. Kennington IIId298f932022-10-17 14:31:38 -070053};
54
Ratan Gupta8c834932017-04-14 16:30:24 +053055/** @class EthernetInterface
56 * @brief OpenBMC Ethernet Interface implementation.
57 * @details A concrete implementation for the
58 * xyz.openbmc_project.Network.EthernetInterface DBus API.
59 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053060class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053061{
Gunnar Mills57d9c502018-09-14 14:42:34 -050062 public:
63 EthernetInterface() = delete;
64 EthernetInterface(const EthernetInterface&) = delete;
65 EthernetInterface& operator=(const EthernetInterface&) = delete;
66 EthernetInterface(EthernetInterface&&) = delete;
67 EthernetInterface& operator=(EthernetInterface&&) = delete;
68 virtual ~EthernetInterface() = default;
Ratan Gupta8c834932017-04-14 16:30:24 +053069
Gunnar Mills57d9c502018-09-14 14:42:34 -050070 /** @brief Constructor to put object onto bus at a dbus path.
71 * @param[in] bus - Bus to attach to.
William A. Kennington IIId298f932022-10-17 14:31:38 -070072 * @param[in] manager - parent object.
73 * @param[in] info - Interface information.
74 * @param[in] objRoot - Path to attach at.
William A. Kennington IIIa520a392022-08-08 12:17:34 -070075 * @param[in] config - The parsed configuation file.
Gunnar Mills57d9c502018-09-14 14:42:34 -050076 * @param[in] emitSignal - true if the object added signal needs to be
77 * send.
William A. Kennington III26275a32021-07-13 20:32:42 -070078 * @param[in] enabled - Override the lookup of nicEnabled
Gunnar Mills57d9c502018-09-14 14:42:34 -050079 */
William A. Kennington IIId298f932022-10-17 14:31:38 -070080 EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070081 const system::InterfaceInfo& info,
82 std::string_view objRoot, const config::Parser& config,
83 bool emitSignal = true,
William A. Kennington III26275a32021-07-13 20:32:42 -070084 std::optional<bool> enabled = std::nullopt);
Ratan Gupta82549cc2017-04-21 08:45:23 +053085
William A. Kennington IIId298f932022-10-17 14:31:38 -070086 /** @brief Updates the interface information based on new InterfaceInfo */
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070087 void updateInfo(const system::InterfaceInfo& info);
William A. Kennington IIId298f932022-10-17 14:31:38 -070088
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -060089 /** @brief Function used to load the ntpservers
90 */
91 void loadNTPServers(const config::Parser& config);
92
Manojkiran Edaacd6dd52019-10-15 15:00:51 +053093 /** @brief Function used to load the nameservers.
94 */
William A. Kennington IIIa520a392022-08-08 12:17:34 -070095 void loadNameServers(const config::Parser& config);
Manojkiran Edaacd6dd52019-10-15 15:00:51 +053096
Patrick Williams6aef7692021-05-01 06:39:41 -050097 /** @brief Function to create ipAddress dbus object.
Gunnar Mills57d9c502018-09-14 14:42:34 -050098 * @param[in] addressType - Type of ip address.
Patrick Williams6aef7692021-05-01 06:39:41 -050099 * @param[in] ipAddress- IP address.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500100 * @param[in] prefixLength - Length of prefix.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500101 */
Ratan Gupta82549cc2017-04-21 08:45:23 +0530102
Patrick Williams6aef7692021-05-01 06:39:41 -0500103 ObjectPath ip(IP::Protocol addressType, std::string ipAddress,
William A. Kennington IIIe25f8b42022-10-11 14:43:28 -0700104 uint8_t prefixLength, std::string) override;
Ratan Gupta8c834932017-04-14 16:30:24 +0530105
William A. Kennington III08505792019-01-30 16:00:04 -0800106 /** @brief Function to create static neighbor dbus object.
107 * @param[in] ipAddress - IP address.
108 * @param[in] macAddress - Low level MAC address.
109 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500110 ObjectPath neighbor(std::string ipAddress, std::string macAddress) override;
William A. Kennington III08505792019-01-30 16:00:04 -0800111
Patrick Williams6aef7692021-05-01 06:39:41 -0500112 /* @brief delete the dbus object of the given ipAddress.
113 * @param[in] ipAddress - IP address.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500114 */
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700115 void deleteObject(std::string_view ipAddress);
Ratan Gupta8c834932017-04-14 16:30:24 +0530116
Patrick Williams6aef7692021-05-01 06:39:41 -0500117 /* @brief delete the dbus object of the given ipAddress.
118 * @param[in] ipAddress - IP address.
William A. Kennington III08505792019-01-30 16:00:04 -0800119 */
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700120 void deleteStaticNeighborObject(std::string_view ipAddress);
William A. Kennington III08505792019-01-30 16:00:04 -0800121
Gunnar Mills57d9c502018-09-14 14:42:34 -0500122 /* @brief delete the vlan dbus object of the given interface.
123 * Also deletes the device file and the network file.
124 * @param[in] interface - VLAN Interface.
125 */
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700126 void deleteVLANObject(stdplus::zstring_view interface);
Ratan Guptabc886292017-07-25 18:29:57 +0530127
Gunnar Mills57d9c502018-09-14 14:42:34 -0500128 /* @brief creates the dbus object(IPaddres) given in the address list.
129 * @param[in] addrs - address list for which dbus objects needs
130 * to create.
131 */
132 void createIPAddressObjects();
Ratan Gupta29b0e432017-05-25 12:51:40 +0530133
William A. Kennington III08505792019-01-30 16:00:04 -0800134 /* @brief creates the dbus object(Neighbor) given in the neighbor list.
135 */
136 void createStaticNeighborObjects();
137
Gunnar Mills57d9c502018-09-14 14:42:34 -0500138 /* @brief Gets all the ip addresses.
Patrick Williams6aef7692021-05-01 06:39:41 -0500139 * @returns the list of ipAddress.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500140 */
William A. Kennington III9a20a6e2022-10-05 13:41:12 -0700141 inline const auto& getAddresses() const
Gunnar Mills57d9c502018-09-14 14:42:34 -0500142 {
143 return addrs;
144 }
Ratan Gupta8c834932017-04-14 16:30:24 +0530145
William A. Kennington III08505792019-01-30 16:00:04 -0800146 /* @brief Gets all the static neighbor entries.
147 * @returns Static neighbor map.
148 */
William A. Kennington III9a20a6e2022-10-05 13:41:12 -0700149 inline const auto& getStaticNeighbors() const
William A. Kennington III08505792019-01-30 16:00:04 -0800150 {
151 return staticNeighbors;
152 }
153
Gunnar Mills57d9c502018-09-14 14:42:34 -0500154 /** Set value of DHCPEnabled */
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700155 DHCPConf dhcpEnabled() const override;
Patrick Williams6aef7692021-05-01 06:39:41 -0500156 DHCPConf dhcpEnabled(DHCPConf value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700157 using EthernetInterfaceIntf::dhcp4;
158 bool dhcp4(bool value) override;
159 using EthernetInterfaceIntf::dhcp6;
160 bool dhcp6(bool value) override;
Ratan Gupta87c13982017-06-15 09:27:27 +0530161
Johnathan Manteyfaa72e52020-01-08 10:38:58 -0800162 /** Retrieve Link State */
163 bool linkUp() const override;
164
Tejas Patil2c0fc562021-08-03 19:13:46 +0530165 /** Retrieve MTU Size */
166 size_t mtu() const override;
167
168 /** Set size of MTU */
169 size_t mtu(size_t value) override;
170
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700171 /** Set value of NICEnabled */
Patrick Williams6aef7692021-05-01 06:39:41 -0500172 bool nicEnabled(bool value) override;
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700173
Gunnar Mills57d9c502018-09-14 14:42:34 -0500174 /** @brief sets the MAC address.
175 * @param[in] value - MAC address which needs to be set on the system.
176 * @returns macAddress of the interface or throws an error.
177 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500178 std::string macAddress(std::string value) override;
Ratan Guptabd303b12017-08-18 17:10:07 +0530179
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700180 /** @brief check conf file for Router Advertisements
181 *
182 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500183 bool ipv6AcceptRA(bool value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700184 using EthernetInterfaceIntf::ipv6AcceptRA;
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700185
Gunnar Mills57d9c502018-09-14 14:42:34 -0500186 /** @brief sets the NTP servers.
187 * @param[in] value - vector of NTP servers.
188 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500189 ServerList ntpServers(ServerList value) override;
Ratan Gupta497c0c92017-08-22 19:15:59 +0530190
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600191 /** @brief sets the static NTP servers.
192 * @param[in] value - vector of NTP servers.
193 */
194 ServerList staticNTPServers(ServerList value) override;
195
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530196 /** @brief sets the Static DNS/nameservers.
197 * @param[in] value - vector of DNS servers.
198 */
199
200 ServerList staticNameServers(ServerList value) override;
201
Gunnar Mills57d9c502018-09-14 14:42:34 -0500202 /** @brief create Vlan interface.
203 * @param[in] id- VLAN identifier.
204 */
William A. Kennington IIId298f932022-10-17 14:31:38 -0700205 ObjectPath createVLAN(uint16_t id);
Ratan Gupta5978dd12017-07-25 13:47:13 +0530206
Gunnar Mills57d9c502018-09-14 14:42:34 -0500207 /** @brief load the vlan info from the system
208 * and creates the ip address dbus objects.
209 * @param[in] vlanID- VLAN identifier.
210 */
William A. Kennington IIIfd862be2022-10-09 18:40:55 -0700211 void loadVLAN(std::string_view objRoot, uint16_t vlanID,
212 system::InterfaceInfo&& info);
Ratan Gupta92bc2fe2017-07-26 22:40:21 +0530213
Gunnar Mills57d9c502018-09-14 14:42:34 -0500214 /** @brief write the network conf file with the in-memory objects.
215 */
216 void writeConfigurationFile();
Ratan Gupta2b106532017-07-25 16:05:02 +0530217
Gunnar Mills57d9c502018-09-14 14:42:34 -0500218 /** @brief delete all dbus objects.
219 */
220 void deleteAll();
Ratan Guptae9c9b812017-09-22 17:15:37 +0530221
Ravi Tejaa5a09442020-07-17 00:57:33 -0500222 /** @brief set the default v4 gateway of the interface.
223 * @param[in] gateway - default v4 gateway of the interface.
224 */
225 std::string defaultGateway(std::string gateway) override;
226
227 /** @brief set the default v6 gateway of the interface.
228 * @param[in] gateway - default v6 gateway of the interface.
229 */
230 std::string defaultGateway6(std::string gateway) override;
231
Gunnar Mills57d9c502018-09-14 14:42:34 -0500232 using EthernetInterfaceIntf::interfaceName;
Johnathan Manteyfaa72e52020-01-08 10:38:58 -0800233 using EthernetInterfaceIntf::linkUp;
Tejas Patil2c0fc562021-08-03 19:13:46 +0530234 using EthernetInterfaceIntf::mtu;
Patrick Williams6aef7692021-05-01 06:39:41 -0500235 using EthernetInterfaceIntf::nicEnabled;
236 using MacAddressIntf::macAddress;
Ratan Gupta5978dd12017-07-25 13:47:13 +0530237
Ravi Tejaa5a09442020-07-17 00:57:33 -0500238 using EthernetInterfaceIntf::defaultGateway;
239 using EthernetInterfaceIntf::defaultGateway6;
Ratan Gupta6dec3902017-08-20 15:28:12 +0530240
Gunnar Mills57d9c502018-09-14 14:42:34 -0500241 protected:
Gunnar Mills57d9c502018-09-14 14:42:34 -0500242 /* @brief delete the vlan interface from system.
243 * @param[in] interface - vlan Interface.
244 */
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700245 void deleteVLANFromSystem(stdplus::zstring_view interface);
Ratan Guptae9c9b812017-09-22 17:15:37 +0530246
Gunnar Mills57d9c502018-09-14 14:42:34 -0500247 /** @brief construct the ip address dbus object path.
248 * @param[in] addressType - Type of ip address.
Patrick Williams6aef7692021-05-01 06:39:41 -0500249 * @param[in] ipAddress - IP address.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500250 * @param[in] prefixLength - Length of prefix.
Lei YU34027572021-08-11 15:23:52 +0800251 * @param[in] origin - The origin entry of the IP::Address
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530252
Gunnar Mills57d9c502018-09-14 14:42:34 -0500253 * @return path of the address object.
254 */
Gunnar Mills57d9c502018-09-14 14:42:34 -0500255 std::string generateObjectPath(IP::Protocol addressType,
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700256 std::string_view ipAddress,
Gunnar Mills57d9c502018-09-14 14:42:34 -0500257 uint8_t prefixLength,
Lei YU34027572021-08-11 15:23:52 +0800258 IP::AddressOrigin origin) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530259
William A. Kennington III08505792019-01-30 16:00:04 -0800260 std::string
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -0700261 generateStaticNeighborObjectPath(std::string_view ipAddress,
262 std::string_view macAddress) const;
William A. Kennington III08505792019-01-30 16:00:04 -0800263
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600264 /** @brief get the NTP server list from the timsyncd dbus obj
Gunnar Mills57d9c502018-09-14 14:42:34 -0500265 *
266 */
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600267 virtual ServerList getNTPServerFromTimeSyncd();
Ratan Gupta497c0c92017-08-22 19:15:59 +0530268
Gunnar Mills57d9c502018-09-14 14:42:34 -0500269 /** @brief get the name server details from the network conf
270 *
271 */
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530272 virtual ServerList getNameServerFromResolvd();
Ratan Gupta6dec3902017-08-20 15:28:12 +0530273
Gunnar Mills57d9c502018-09-14 14:42:34 -0500274 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williamsc38b0712022-07-22 19:26:54 -0500275 sdbusplus::bus_t& bus;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530276
Gunnar Mills57d9c502018-09-14 14:42:34 -0500277 /** @brief Network Manager object. */
278 Manager& manager;
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530279
Gunnar Mills57d9c502018-09-14 14:42:34 -0500280 /** @brief Persistent map of IPAddress dbus objects and their names */
William A. Kennington III9a20a6e2022-10-05 13:41:12 -0700281 string_umap<std::unique_ptr<IPAddress>> addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530282
William A. Kennington III08505792019-01-30 16:00:04 -0800283 /** @brief Persistent map of Neighbor dbus objects and their names */
William A. Kennington III9a20a6e2022-10-05 13:41:12 -0700284 string_umap<std::unique_ptr<Neighbor>> staticNeighbors;
William A. Kennington III08505792019-01-30 16:00:04 -0800285
Gunnar Mills57d9c502018-09-14 14:42:34 -0500286 /** @brief Persistent map of VLAN interface dbus objects and their names */
William A. Kennington III9a20a6e2022-10-05 13:41:12 -0700287 string_umap<std::unique_ptr<VlanInterface>> vlanInterfaces;
Ratan Gupta5978dd12017-07-25 13:47:13 +0530288
Gunnar Mills57d9c502018-09-14 14:42:34 -0500289 /** @brief Dbus object path */
290 std::string objPath;
Ratan Gupta47722dc2017-05-26 18:32:23 +0530291
William A. Kennington III2e09d272022-10-14 17:15:00 -0700292 /** @brief Interface index */
293 unsigned ifIdx;
294
Gunnar Mills57d9c502018-09-14 14:42:34 -0500295 friend class TestEthernetInterface;
Johnathan Mantey817012a2020-01-30 15:07:39 -0800296
297 private:
William A. Kennington IIId298f932022-10-17 14:31:38 -0700298 EthernetInterface(sdbusplus::bus_t& bus, Manager& manager,
William A. Kennington IIIfd862be2022-10-09 18:40:55 -0700299 const system::InterfaceInfo& info, std::string&& objPath,
William A. Kennington IIId298f932022-10-17 14:31:38 -0700300 const config::Parser& config, bool emitSignal,
301 std::optional<bool> enabled);
302
Johnathan Mantey817012a2020-01-30 15:07:39 -0800303 /** @brief Determines if DHCP is active for the IP::Protocol supplied.
304 * @param[in] protocol - Either IPv4 or IPv6
Johnathan Mantey817012a2020-01-30 15:07:39 -0800305 * @returns true/false value if DHCP is active for the input protocol
306 */
William A. Kennington III24957b92021-12-03 13:59:19 -0800307 bool dhcpIsEnabled(IP::Protocol protocol);
Johnathan Mantey817012a2020-01-30 15:07:39 -0800308
Johnathan Mantey817012a2020-01-30 15:07:39 -0800309 /** @brief Determines if the address is manually assigned
310 * @param[in] origin - The origin entry of the IP::Address
311 * @returns true/false value if the address is static
312 */
313 bool originIsManuallyAssigned(IP::AddressOrigin origin);
William A. Kennington III26275a32021-07-13 20:32:42 -0700314
315 /** @brief Determines if the NIC is enabled in systemd
316 * @returns true/false value if the NIC is enabled
317 */
318 bool queryNicEnabled() const;
William A. Kennington IIIa520a392022-08-08 12:17:34 -0700319
William A. Kennington IIId298f932022-10-17 14:31:38 -0700320 std::string vlanIntfName(uint16_t id) const;
Ratan Gupta8c834932017-04-14 16:30:24 +0530321};
322
323} // namespace network
324} // namespace phosphor