blob: aae2e1f551a578be98e5596ae3d0fc9507a6659d [file] [log] [blame]
Ratan Gupta8c834932017-04-14 16:30:24 +05301#pragma once
Jishnu CM57dfea92023-05-05 06:07:26 -05002#include "dhcp_configuration.hpp"
William A. Kennington III9a20a6e2022-10-05 13:41:12 -07003#include "ipaddress.hpp"
4#include "neighbor.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05305#include "types.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05306#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
William A. Kennington III08505792019-01-30 16:00:04 -08007#include "xyz/openbmc_project/Network/Neighbor/CreateStatic/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +05308
9#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
William A. Kennington III9ede1b72022-11-21 01:59:28 -080011#include <stdplus/pinned.hpp>
Jishnu CM57dfea92023-05-05 06:07:26 -050012#include <stdplus/str/maps.hpp>
William A. Kennington IIIbe3bd2f2022-10-11 14:11:27 -070013#include <stdplus/zstring_view.hpp>
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>
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070017#include <xyz/openbmc_project/Network/VLAN/server.hpp>
18#include <xyz/openbmc_project/Object/Delete/server.hpp>
Ratan Gupta8c834932017-04-14 16:30:24 +053019
Patrick Williams89d734b2023-05-10 07:50:25 -050020#include <optional>
21#include <string>
22#include <vector>
23
Ratan Gupta8c834932017-04-14 16:30:24 +053024namespace phosphor
25{
26namespace network
27{
Ratan Gupta8c834932017-04-14 16:30:24 +053028
Patrick Williamsc38b0712022-07-22 19:26:54 -050029using Ifaces = sdbusplus::server::object_t<
Gunnar Mills57d9c502018-09-14 14:42:34 -050030 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
31 sdbusplus::xyz::openbmc_project::Network::server::MACAddress,
32 sdbusplus::xyz::openbmc_project::Network::IP::server::Create,
William A. Kennington III08505792019-01-30 16:00:04 -080033 sdbusplus::xyz::openbmc_project::Network::Neighbor::server::CreateStatic,
Gunnar Mills57d9c502018-09-14 14:42:34 -050034 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Ratan Gupta8c834932017-04-14 16:30:24 +053035
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070036using VlanIfaces = sdbusplus::server::object_t<
37 sdbusplus::xyz::openbmc_project::Object::server::Delete,
38 sdbusplus::xyz::openbmc_project::Network::server::VLAN>;
39
40using VlanIntf = sdbusplus::xyz::openbmc_project::Network::server::VLAN;
41
Ratan Gupta82549cc2017-04-21 08:45:23 +053042using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053043
44using EthernetInterfaceIntf =
45 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
Ratan Guptabd303b12017-08-18 17:10:07 +053046using MacAddressIntf =
47 sdbusplus::xyz::openbmc_project::Network::server::MACAddress;
Ratan Gupta87c13982017-06-15 09:27:27 +053048
Ratan Gupta497c0c92017-08-22 19:15:59 +053049using ServerList = std::vector<std::string>;
raviteja-bce379562019-03-28 05:59:36 -050050using ObjectPath = sdbusplus::message::object_path;
Ratan Gupta497c0c92017-08-22 19:15:59 +053051
William A. Kennington III9a20a6e2022-10-05 13:41:12 -070052class Manager;
Ratan Gupta8c834932017-04-14 16:30:24 +053053
Ratan Gupta47722dc2017-05-26 18:32:23 +053054class TestEthernetInterface;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070055class TestNetworkManager;
Ratan Gupta5978dd12017-07-25 13:47:13 +053056
William A. Kennington III95530ec2022-08-19 01:44:39 -070057namespace config
58{
59class Parser;
60}
William A. Kennington IIId298f932022-10-17 14:31:38 -070061
Ratan Gupta8c834932017-04-14 16:30:24 +053062/** @class EthernetInterface
63 * @brief OpenBMC Ethernet Interface implementation.
64 * @details A concrete implementation for the
65 * xyz.openbmc_project.Network.EthernetInterface DBus API.
66 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053067class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053068{
Gunnar Mills57d9c502018-09-14 14:42:34 -050069 public:
Gunnar Mills57d9c502018-09-14 14:42:34 -050070 EthernetInterface(EthernetInterface&&) = delete;
71 EthernetInterface& operator=(EthernetInterface&&) = delete;
Ratan Gupta8c834932017-04-14 16:30:24 +053072
Gunnar Mills57d9c502018-09-14 14:42:34 -050073 /** @brief Constructor to put object onto bus at a dbus path.
74 * @param[in] bus - Bus to attach to.
William A. Kennington IIId298f932022-10-17 14:31:38 -070075 * @param[in] manager - parent object.
76 * @param[in] info - Interface information.
77 * @param[in] objRoot - Path to attach at.
Manojkiran Edad92826d2024-06-17 14:43:14 +053078 * @param[in] config - The parsed configuration file.
William A. Kennington III09f3a4a2022-10-25 02:59:16 -070079 * @param[in] vlan - The id of the vlan if configured
William A. Kennington III80d29012022-11-12 02:31:40 -080080 * @param[in] enabled - Determine if systemd-networkd is managing this link
Gunnar Mills57d9c502018-09-14 14:42:34 -050081 */
William A. Kennington III9ede1b72022-11-21 01:59:28 -080082 EthernetInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
83 stdplus::PinnedRef<Manager> manager,
William A. Kennington III13d665c2022-11-15 20:34:40 -080084 const AllIntfInfo& info, std::string_view objRoot,
William A. Kennington IIIb6452542022-11-15 18:09:12 -080085 const config::Parser& config, bool enabled);
Ratan Gupta82549cc2017-04-21 08:45:23 +053086
William A. Kennington III59e5b912022-11-02 02:49:46 -070087 /** @brief Network Manager object. */
William A. Kennington III9ede1b72022-11-21 01:59:28 -080088 stdplus::PinnedRef<Manager> manager;
William A. Kennington III59e5b912022-11-02 02:49:46 -070089
90 /** @brief Persistent map of IPAddress dbus objects and their names */
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070091 std::unordered_map<stdplus::SubnetAny, std::unique_ptr<IPAddress>> addrs;
William A. Kennington III59e5b912022-11-02 02:49:46 -070092
William A. Kennington III434a9432022-11-04 18:38:46 -070093 /** @brief Persistent map of Neighbor dbus objects and their names */
William A. Kennington III9b2a20d2023-06-17 14:05:48 -070094 std::unordered_map<stdplus::InAnyAddr, std::unique_ptr<Neighbor>>
95 staticNeighbors;
William A. Kennington III434a9432022-11-04 18:38:46 -070096
William A. Kennington IIId6f53402022-11-07 14:48:53 -080097 void addAddr(const AddressInfo& info);
William A. Kennington IIIbc2502c2022-11-07 16:31:54 -080098 void addStaticNeigh(const NeighborInfo& info);
William A. Kennington IIId6f53402022-11-07 14:48:53 -080099
William A. Kennington IIId298f932022-10-17 14:31:38 -0700100 /** @brief Updates the interface information based on new InterfaceInfo */
William A. Kennington IIId99e6db2022-11-15 20:39:45 -0800101 void updateInfo(const InterfaceInfo& info, bool skipSignal = false);
William A. Kennington IIId298f932022-10-17 14:31:38 -0700102
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600103 /** @brief Function used to load the ntpservers
104 */
105 void loadNTPServers(const config::Parser& config);
106
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530107 /** @brief Function used to load the nameservers.
108 */
William A. Kennington IIIa520a392022-08-08 12:17:34 -0700109 void loadNameServers(const config::Parser& config);
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530110
Patrick Williams6aef7692021-05-01 06:39:41 -0500111 /** @brief Function to create ipAddress dbus object.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500112 * @param[in] addressType - Type of ip address.
Patrick Williams6aef7692021-05-01 06:39:41 -0500113 * @param[in] ipAddress- IP address.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500114 * @param[in] prefixLength - Length of prefix.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500115 */
Ratan Gupta82549cc2017-04-21 08:45:23 +0530116
Patrick Williams6aef7692021-05-01 06:39:41 -0500117 ObjectPath ip(IP::Protocol addressType, std::string ipAddress,
William A. Kennington IIIe25f8b42022-10-11 14:43:28 -0700118 uint8_t prefixLength, std::string) override;
Ratan Gupta8c834932017-04-14 16:30:24 +0530119
William A. Kennington III08505792019-01-30 16:00:04 -0800120 /** @brief Function to create static neighbor dbus object.
121 * @param[in] ipAddress - IP address.
122 * @param[in] macAddress - Low level MAC address.
123 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500124 ObjectPath neighbor(std::string ipAddress, std::string macAddress) override;
William A. Kennington III08505792019-01-30 16:00:04 -0800125
Gunnar Mills57d9c502018-09-14 14:42:34 -0500126 /** Set value of DHCPEnabled */
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700127 DHCPConf dhcpEnabled() const override;
Patrick Williams6aef7692021-05-01 06:39:41 -0500128 DHCPConf dhcpEnabled(DHCPConf value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700129 using EthernetInterfaceIntf::dhcp4;
130 bool dhcp4(bool value) override;
131 using EthernetInterfaceIntf::dhcp6;
132 bool dhcp6(bool value) override;
Ratan Gupta87c13982017-06-15 09:27:27 +0530133
William A. Kennington III9b2a20d2023-06-17 14:05:48 -0700134 inline bool dhcpIsEnabled(stdplus::In4Addr) const
William A. Kennington III59e5b912022-11-02 02:49:46 -0700135 {
136 return dhcp4();
137 }
William A. Kennington III9b2a20d2023-06-17 14:05:48 -0700138 inline bool dhcpIsEnabled(stdplus::In6Addr) const
William A. Kennington III59e5b912022-11-02 02:49:46 -0700139 {
140 return dhcp6();
141 }
William A. Kennington III9b2a20d2023-06-17 14:05:48 -0700142 inline bool dhcpIsEnabled(stdplus::InAnyAddr addr) const
William A. Kennington III59e5b912022-11-02 02:49:46 -0700143 {
144 return std::visit([&](auto v) { return dhcpIsEnabled(v); }, addr);
145 }
146
Tejas Patil2c0fc562021-08-03 19:13:46 +0530147 /** Set size of MTU */
148 size_t mtu(size_t value) override;
149
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700150 /** Set value of NICEnabled */
Patrick Williams6aef7692021-05-01 06:39:41 -0500151 bool nicEnabled(bool value) override;
Johnathan Manteyd0679f92019-10-29 16:20:28 -0700152
Gunnar Mills57d9c502018-09-14 14:42:34 -0500153 /** @brief sets the MAC address.
154 * @param[in] value - MAC address which needs to be set on the system.
155 * @returns macAddress of the interface or throws an error.
156 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500157 std::string macAddress(std::string value) override;
Ratan Guptabd303b12017-08-18 17:10:07 +0530158
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700159 /** @brief check conf file for Router Advertisements
160 *
161 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500162 bool ipv6AcceptRA(bool value) override;
William A. Kennington III8060c0d2022-08-18 19:19:34 -0700163 using EthernetInterfaceIntf::ipv6AcceptRA;
Johnathan Mantey5b023f52019-06-24 16:06:37 -0700164
Gunnar Mills57d9c502018-09-14 14:42:34 -0500165 /** @brief sets the NTP servers.
166 * @param[in] value - vector of NTP servers.
167 */
Patrick Williams6aef7692021-05-01 06:39:41 -0500168 ServerList ntpServers(ServerList value) override;
Ratan Gupta497c0c92017-08-22 19:15:59 +0530169
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600170 /** @brief sets the static NTP servers.
171 * @param[in] value - vector of NTP servers.
172 */
173 ServerList staticNTPServers(ServerList value) override;
174
Ravi Teja4f8b9a02023-09-06 13:41:52 -0500175 /** @brief Get value of nameservers */
176 ServerList nameservers() const override;
177
Manojkiran Edaacd6dd52019-10-15 15:00:51 +0530178 /** @brief sets the Static DNS/nameservers.
179 * @param[in] value - vector of DNS servers.
180 */
181
182 ServerList staticNameServers(ServerList value) override;
183
Gunnar Mills57d9c502018-09-14 14:42:34 -0500184 /** @brief create Vlan interface.
185 * @param[in] id- VLAN identifier.
186 */
William A. Kennington IIId298f932022-10-17 14:31:38 -0700187 ObjectPath createVLAN(uint16_t id);
Ratan Gupta5978dd12017-07-25 13:47:13 +0530188
Gunnar Mills57d9c502018-09-14 14:42:34 -0500189 /** @brief write the network conf file with the in-memory objects.
190 */
191 void writeConfigurationFile();
Ratan Gupta2b106532017-07-25 16:05:02 +0530192
Gunnar Mills57d9c502018-09-14 14:42:34 -0500193 /** @brief delete all dbus objects.
194 */
William A. Kennington IIIaf77f822023-06-23 02:17:20 -0700195 void deleteAll() override;
Ratan Guptae9c9b812017-09-22 17:15:37 +0530196
Ravi Tejaa5a09442020-07-17 00:57:33 -0500197 /** @brief set the default v4 gateway of the interface.
198 * @param[in] gateway - default v4 gateway of the interface.
199 */
200 std::string defaultGateway(std::string gateway) override;
201
202 /** @brief set the default v6 gateway of the interface.
203 * @param[in] gateway - default v6 gateway of the interface.
204 */
205 std::string defaultGateway6(std::string gateway) override;
206
Jishnu CM57dfea92023-05-05 06:07:26 -0500207 /** @brief Function to reload network configurations.
208 */
209 void reloadConfigs();
210
Gunnar Mills57d9c502018-09-14 14:42:34 -0500211 using EthernetInterfaceIntf::interfaceName;
Johnathan Manteyfaa72e52020-01-08 10:38:58 -0800212 using EthernetInterfaceIntf::linkUp;
Tejas Patil2c0fc562021-08-03 19:13:46 +0530213 using EthernetInterfaceIntf::mtu;
Patrick Williams6aef7692021-05-01 06:39:41 -0500214 using EthernetInterfaceIntf::nicEnabled;
215 using MacAddressIntf::macAddress;
Ratan Gupta5978dd12017-07-25 13:47:13 +0530216
Ravi Tejaa5a09442020-07-17 00:57:33 -0500217 using EthernetInterfaceIntf::defaultGateway;
218 using EthernetInterfaceIntf::defaultGateway6;
Ratan Gupta6dec390f2017-08-20 15:28:12 +0530219
Gunnar Mills57d9c502018-09-14 14:42:34 -0500220 protected:
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600221 /** @brief get the NTP server list from the timsyncd dbus obj
Gunnar Mills57d9c502018-09-14 14:42:34 -0500222 *
223 */
Asmitha Karunanithi003b8b72022-01-06 04:17:59 -0600224 virtual ServerList getNTPServerFromTimeSyncd();
Ratan Gupta497c0c92017-08-22 19:15:59 +0530225
Gunnar Mills57d9c502018-09-14 14:42:34 -0500226 /** @brief get the name server details from the network conf
227 *
228 */
Ravi Teja4f8b9a02023-09-06 13:41:52 -0500229 virtual ServerList getNameServerFromResolvd() const;
Ratan Gupta6dec390f2017-08-20 15:28:12 +0530230
Gunnar Mills57d9c502018-09-14 14:42:34 -0500231 /** @brief Persistent sdbusplus DBus bus connection. */
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800232 stdplus::PinnedRef<sdbusplus::bus_t> bus;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530233
Gunnar Mills57d9c502018-09-14 14:42:34 -0500234 /** @brief Dbus object path */
235 std::string objPath;
Ratan Gupta47722dc2017-05-26 18:32:23 +0530236
William A. Kennington III2e09d272022-10-14 17:15:00 -0700237 /** @brief Interface index */
238 unsigned ifIdx;
239
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700240 struct VlanProperties : VlanIfaces
241 {
242 VlanProperties(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800243 const InterfaceInfo& info,
244 stdplus::PinnedRef<EthernetInterface> eth);
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700245 void delete_() override;
246 unsigned parentIdx;
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800247 stdplus::PinnedRef<EthernetInterface> eth;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700248 };
249 std::optional<VlanProperties> vlan;
250
William A. Kennington IIIf179e702024-04-17 00:50:28 -0700251 std::optional<dhcp::Configuration> dhcp4Conf, dhcp6Conf;
252
Gunnar Mills57d9c502018-09-14 14:42:34 -0500253 friend class TestEthernetInterface;
William A. Kennington III09f3a4a2022-10-25 02:59:16 -0700254 friend class TestNetworkManager;
Johnathan Mantey817012a2020-01-30 15:07:39 -0800255
256 private:
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800257 EthernetInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
258 stdplus::PinnedRef<Manager> manager,
William A. Kennington III13d665c2022-11-15 20:34:40 -0800259 const AllIntfInfo& info, std::string&& objPath,
William A. Kennington IIIb6452542022-11-15 18:09:12 -0800260 const config::Parser& config, bool enabled);
William A. Kennington IIId298f932022-10-17 14:31:38 -0700261
Johnathan Mantey817012a2020-01-30 15:07:39 -0800262 /** @brief Determines if the address is manually assigned
263 * @param[in] origin - The origin entry of the IP::Address
264 * @returns true/false value if the address is static
265 */
266 bool originIsManuallyAssigned(IP::AddressOrigin origin);
Ratan Gupta8c834932017-04-14 16:30:24 +0530267};
268
269} // namespace network
270} // namespace phosphor