blob: b66030adb61b572349674b05c16e0e304d6dcfcf [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 III9ede1b72022-11-21 01:59:28 -080011#include <stdplus/pinned.hpp>
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070012#include <stdplus/zstring_view.hpp>
Ratan Gupta8c834932017-04-14 16:30:24 +053013#include <string>
William A. Kennington III95530ec2022-08-19 01:44:39 -070014#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070015#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
16#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
17#include <xyz/openbmc_project/Network/MACAddress/server.hpp>
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070018#include <xyz/openbmc_project/Network/VLAN/server.hpp>
19#include <xyz/openbmc_project/Object/Delete/server.hpp>
Ratan Gupta8c834932017-04-14 16:30:24 +053020
21namespace phosphor
22{
23namespace network
24{
Ratan Gupta8c834932017-04-14 16:30:24 +053025
Patrick Williamsc38b0712022-07-22 19:26:54 -050026using Ifaces = sdbusplus::server::object_t<
Gunnar Mills57d9c502018-09-14 14:42:34 -050027 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
28 sdbusplus::xyz::openbmc_project::Network::server::MACAddress,
29 sdbusplus::xyz::openbmc_project::Network::IP::server::Create,
William A. Kennington III08505792019-01-30 16:00:04 -080030 sdbusplus::xyz::openbmc_project::Network::Neighbor::server::CreateStatic,
Gunnar Mills57d9c502018-09-14 14:42:34 -050031 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Ratan Gupta8c834932017-04-14 16:30:24 +053032
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070033using VlanIfaces = sdbusplus::server::object_t<
34 sdbusplus::xyz::openbmc_project::Object::server::Delete,
35 sdbusplus::xyz::openbmc_project::Network::server::VLAN>;
36
37using VlanIntf = sdbusplus::xyz::openbmc_project::Network::server::VLAN;
38
Ratan Gupta82549cc2017-04-21 08:45:23 +053039using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053040
41using EthernetInterfaceIntf =
42 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
Ratan Guptabd303b12017-08-18 17:10:07 +053043using MacAddressIntf =
44 sdbusplus::xyz::openbmc_project::Network::server::MACAddress;
Ratan Gupta87c13982017-06-15 09:27:27 +053045
Ratan Gupta497c0c92017-08-22 19:15:59 +053046using ServerList = std::vector<std::string>;
raviteja-bce379562019-03-28 05:59:36 -050047using ObjectPath = sdbusplus::message::object_path;
Ratan Gupta497c0c92017-08-22 19:15:59 +053048
William A. Kennington III9a20a6e2022-10-05 13:41:12 -070049class Manager;
Ratan Gupta8c834932017-04-14 16:30:24 +053050
Ratan Gupta47722dc2017-05-26 18:32:23 +053051class TestEthernetInterface;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070052class TestNetworkManager;
Ratan Gupta5978dd12017-07-25 13:47:13 +053053
William A. Kennington III95530ec2022-08-19 01:44:39 -070054namespace config
55{
56class Parser;
57}
William A. Kennington IIId298f932022-10-17 14:31:38 -070058
Ratan Gupta8c834932017-04-14 16:30:24 +053059/** @class EthernetInterface
60 * @brief OpenBMC Ethernet Interface implementation.
61 * @details A concrete implementation for the
62 * xyz.openbmc_project.Network.EthernetInterface DBus API.
63 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053064class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053065{
Gunnar Mills57d9c502018-09-14 14:42:34 -050066 public:
Gunnar Mills57d9c502018-09-14 14:42:34 -050067 EthernetInterface(EthernetInterface&&) = delete;
68 EthernetInterface& operator=(EthernetInterface&&) = delete;
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.
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070076 * @param[in] vlan - The id of the vlan if configured
William A. Kennington III80d29012022-11-12 02:31:40 -080077 * @param[in] enabled - Determine if systemd-networkd is managing this link
Gunnar Mills57d9c502018-09-14 14:42:34 -050078 */
William A. Kennington III9ede1b72022-11-21 01:59:28 -080079 EthernetInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
80 stdplus::PinnedRef<Manager> manager,
William A. Kennington III13d665c2022-11-15 20:34:40 -080081 const AllIntfInfo& info, std::string_view objRoot,
William A. Kennington IIIb6452542022-11-15 18:09:12 -080082 const config::Parser& config, bool enabled);
Ratan Gupta82549cc2017-04-21 08:45:23 +053083
William A. Kennington III59e5b912022-11-02 02:49:46 -070084 /** @brief Network Manager object. */
William A. Kennington III9ede1b72022-11-21 01:59:28 -080085 stdplus::PinnedRef<Manager> manager;
William A. Kennington III59e5b912022-11-02 02:49:46 -070086
87 /** @brief Persistent map of IPAddress dbus objects and their names */
88 std::unordered_map<IfAddr, std::unique_ptr<IPAddress>> addrs;
89
William A. Kennington III434a9432022-11-04 18:38:46 -070090 /** @brief Persistent map of Neighbor dbus objects and their names */
91 std::unordered_map<InAddrAny, std::unique_ptr<Neighbor>> staticNeighbors;
92
William A. Kennington IIId6f53402022-11-07 14:48:53 -080093 void addAddr(const AddressInfo& info);
William A. Kennington IIIbc2502c2022-11-07 16:31:54 -080094 void addStaticNeigh(const NeighborInfo& info);
William A. Kennington IIId6f53402022-11-07 14:48:53 -080095
William A. Kennington IIId298f932022-10-17 14:31:38 -070096 /** @brief Updates the interface information based on new InterfaceInfo */
William A. Kennington IIId99e6db2022-11-15 20:39:45 -080097 void updateInfo(const InterfaceInfo& info, bool skipSignal = false);
William A. Kennington IIId298f932022-10-17 14:31:38 -070098
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -060099 /** @brief Function used to load the ntpservers
100 */
101 void loadNTPServers(const config::Parser& config);
102
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530103 /** @brief Function used to load the nameservers.
104 */
William A. Kennington IIIa520a392022-08-08 12:17:34 -0700105 void loadNameServers(const config::Parser& config);
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530106
Patrick Williams6aef7692021-05-01 06:39:41 -0500107 /** @brief Function to create ipAddress dbus object.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500108 * @param[in] addressType - Type of ip address.
Patrick Williams6aef7692021-05-01 06:39:41 -0500109 * @param[in] ipAddress- IP address.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500110 * @param[in] prefixLength - Length of prefix.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500111 */
Ratan Gupta82549cc2017-04-21 08:45:23 +0530112
Patrick Williams6aef7692021-05-01 06:39:41 -0500113 ObjectPath ip(IP::Protocol addressType, std::string ipAddress,
William A. Kennington IIIe25f8b42022-10-11 14:43:28 -0700114 uint8_t prefixLength, std::string) override;
Ratan Gupta8c834932017-04-14 16:30:24 +0530115
William A. Kennington III08505792019-01-30 16:00:04 -0800116 /** @brief Function to create static neighbor dbus object.
117 * @param[in] ipAddress - IP address.
118 * @param[in] macAddress - Low level MAC address.
119 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500120 ObjectPath neighbor(std::string ipAddress, std::string macAddress) override;
William A. Kennington III08505792019-01-30 16:00:04 -0800121
Gunnar Mills57d9c502018-09-14 14:42:34 -0500122 /** Set value of DHCPEnabled */
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700123 DHCPConf dhcpEnabled() const override;
Patrick Williams6aef7692021-05-01 06:39:41 -0500124 DHCPConf dhcpEnabled(DHCPConf value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700125 using EthernetInterfaceIntf::dhcp4;
126 bool dhcp4(bool value) override;
127 using EthernetInterfaceIntf::dhcp6;
128 bool dhcp6(bool value) override;
Ratan Gupta87c13982017-06-15 09:27:27 +0530129
William A. Kennington III59e5b912022-11-02 02:49:46 -0700130 inline bool dhcpIsEnabled(in_addr) const
131 {
132 return dhcp4();
133 }
134 inline bool dhcpIsEnabled(in6_addr) const
135 {
136 return dhcp6();
137 }
138 inline bool dhcpIsEnabled(InAddrAny addr) const
139 {
140 return std::visit([&](auto v) { return dhcpIsEnabled(v); }, addr);
141 }
142
Tejas Patil2c0fc562021-08-03 19:13:46 +0530143 /** Set size of MTU */
144 size_t mtu(size_t value) override;
145
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700146 /** Set value of NICEnabled */
Patrick Williams6aef7692021-05-01 06:39:41 -0500147 bool nicEnabled(bool value) override;
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700148
Gunnar Mills57d9c502018-09-14 14:42:34 -0500149 /** @brief sets the MAC address.
150 * @param[in] value - MAC address which needs to be set on the system.
151 * @returns macAddress of the interface or throws an error.
152 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500153 std::string macAddress(std::string value) override;
Ratan Guptabd303b12017-08-18 17:10:07 +0530154
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700155 /** @brief check conf file for Router Advertisements
156 *
157 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500158 bool ipv6AcceptRA(bool value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700159 using EthernetInterfaceIntf::ipv6AcceptRA;
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700160
Gunnar Mills57d9c502018-09-14 14:42:34 -0500161 /** @brief sets the NTP servers.
162 * @param[in] value - vector of NTP servers.
163 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500164 ServerList ntpServers(ServerList value) override;
Ratan Gupta497c0c92017-08-22 19:15:59 +0530165
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600166 /** @brief sets the static NTP servers.
167 * @param[in] value - vector of NTP servers.
168 */
169 ServerList staticNTPServers(ServerList value) override;
170
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530171 /** @brief sets the Static DNS/nameservers.
172 * @param[in] value - vector of DNS servers.
173 */
174
175 ServerList staticNameServers(ServerList value) override;
176
Gunnar Mills57d9c502018-09-14 14:42:34 -0500177 /** @brief create Vlan interface.
178 * @param[in] id- VLAN identifier.
179 */
William A. Kennington IIId298f932022-10-17 14:31:38 -0700180 ObjectPath createVLAN(uint16_t id);
Ratan Gupta5978dd12017-07-25 13:47:13 +0530181
Gunnar Mills57d9c502018-09-14 14:42:34 -0500182 /** @brief write the network conf file with the in-memory objects.
183 */
184 void writeConfigurationFile();
Ratan Gupta2b106532017-07-25 16:05:02 +0530185
Gunnar Mills57d9c502018-09-14 14:42:34 -0500186 /** @brief delete all dbus objects.
187 */
188 void deleteAll();
Ratan Guptae9c9b812017-09-22 17:15:37 +0530189
Ravi Tejaa5a09442020-07-17 00:57:33 -0500190 /** @brief set the default v4 gateway of the interface.
191 * @param[in] gateway - default v4 gateway of the interface.
192 */
193 std::string defaultGateway(std::string gateway) override;
194
195 /** @brief set the default v6 gateway of the interface.
196 * @param[in] gateway - default v6 gateway of the interface.
197 */
198 std::string defaultGateway6(std::string gateway) override;
199
Gunnar Mills57d9c502018-09-14 14:42:34 -0500200 using EthernetInterfaceIntf::interfaceName;
Johnathan Manteyfaa72e52020-01-08 10:38:58 -0800201 using EthernetInterfaceIntf::linkUp;
Tejas Patil2c0fc562021-08-03 19:13:46 +0530202 using EthernetInterfaceIntf::mtu;
Patrick Williams6aef7692021-05-01 06:39:41 -0500203 using EthernetInterfaceIntf::nicEnabled;
204 using MacAddressIntf::macAddress;
Ratan Gupta5978dd12017-07-25 13:47:13 +0530205
Ravi Tejaa5a09442020-07-17 00:57:33 -0500206 using EthernetInterfaceIntf::defaultGateway;
207 using EthernetInterfaceIntf::defaultGateway6;
Ratan Gupta6dec390f2017-08-20 15:28:12 +0530208
Gunnar Mills57d9c502018-09-14 14:42:34 -0500209 protected:
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600210 /** @brief get the NTP server list from the timsyncd dbus obj
Gunnar Mills57d9c502018-09-14 14:42:34 -0500211 *
212 */
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600213 virtual ServerList getNTPServerFromTimeSyncd();
Ratan Gupta497c0c92017-08-22 19:15:59 +0530214
Gunnar Mills57d9c502018-09-14 14:42:34 -0500215 /** @brief get the name server details from the network conf
216 *
217 */
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530218 virtual ServerList getNameServerFromResolvd();
Ratan Gupta6dec390f2017-08-20 15:28:12 +0530219
Gunnar Mills57d9c502018-09-14 14:42:34 -0500220 /** @brief Persistent sdbusplus DBus bus connection. */
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800221 stdplus::PinnedRef<sdbusplus::bus_t> bus;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530222
Gunnar Mills57d9c502018-09-14 14:42:34 -0500223 /** @brief Dbus object path */
224 std::string objPath;
Ratan Gupta47722dc2017-05-26 18:32:23 +0530225
William A. Kennington III2e09d272022-10-14 17:15:00 -0700226 /** @brief Interface index */
227 unsigned ifIdx;
228
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700229 struct VlanProperties : VlanIfaces
230 {
231 VlanProperties(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800232 const InterfaceInfo& info,
233 stdplus::PinnedRef<EthernetInterface> eth);
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700234 void delete_() override;
235 unsigned parentIdx;
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800236 stdplus::PinnedRef<EthernetInterface> eth;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700237 };
238 std::optional<VlanProperties> vlan;
239
Gunnar Mills57d9c502018-09-14 14:42:34 -0500240 friend class TestEthernetInterface;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700241 friend class TestNetworkManager;
Johnathan Mantey817012a2020-01-30 15:07:39 -0800242
243 private:
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800244 EthernetInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
245 stdplus::PinnedRef<Manager> manager,
William A. Kennington III13d665c2022-11-15 20:34:40 -0800246 const AllIntfInfo& info, std::string&& objPath,
William A. Kennington IIIb6452542022-11-15 18:09:12 -0800247 const config::Parser& config, bool enabled);
William A. Kennington IIId298f932022-10-17 14:31:38 -0700248
Johnathan Mantey817012a2020-01-30 15:07:39 -0800249 /** @brief Determines if the address is manually assigned
250 * @param[in] origin - The origin entry of the IP::Address
251 * @returns true/false value if the address is static
252 */
253 bool originIsManuallyAssigned(IP::AddressOrigin origin);
Ratan Gupta8c834932017-04-14 16:30:24 +0530254};
255
256} // namespace network
257} // namespace phosphor