Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 3 | #include "config_parser.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 4 | #include "types.hpp" |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 5 | #include "util.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Network/IP/Create/server.hpp" |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Network/Neighbor/CreateStatic/server.hpp" |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 8 | |
Manojkiran Eda | a879baa | 2020-06-13 14:39:08 +0530 | [diff] [blame] | 9 | #include <filesystem> |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 12 | #include <string> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> |
| 14 | #include <xyz/openbmc_project/Network/EthernetInterface/server.hpp> |
| 15 | #include <xyz/openbmc_project/Network/MACAddress/server.hpp> |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace network |
| 20 | { |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 21 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 22 | using Ifaces = sdbusplus::server::object_t< |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 23 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface, |
| 24 | sdbusplus::xyz::openbmc_project::Network::server::MACAddress, |
| 25 | sdbusplus::xyz::openbmc_project::Network::IP::server::Create, |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 26 | sdbusplus::xyz::openbmc_project::Network::Neighbor::server::CreateStatic, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 27 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 28 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 29 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 30 | |
| 31 | using EthernetInterfaceIntf = |
| 32 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface; |
Ratan Gupta | bd303b1 | 2017-08-18 17:10:07 +0530 | [diff] [blame] | 33 | using MacAddressIntf = |
| 34 | sdbusplus::xyz::openbmc_project::Network::server::MACAddress; |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 35 | |
Ratan Gupta | 497c0c9 | 2017-08-22 19:15:59 +0530 | [diff] [blame] | 36 | using ServerList = std::vector<std::string>; |
raviteja-b | ce37956 | 2019-03-28 05:59:36 -0500 | [diff] [blame] | 37 | using ObjectPath = sdbusplus::message::object_path; |
Ratan Gupta | 497c0c9 | 2017-08-22 19:15:59 +0530 | [diff] [blame] | 38 | |
Manojkiran Eda | a879baa | 2020-06-13 14:39:08 +0530 | [diff] [blame] | 39 | namespace fs = std::filesystem; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 40 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 41 | class Manager; // forward declaration of network manager. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 42 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 43 | class TestEthernetInterface; |
| 44 | |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 45 | class VlanInterface; |
| 46 | |
| 47 | class IPAddress; |
| 48 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 49 | class Neighbor; |
| 50 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 51 | using LinkSpeed = uint16_t; |
| 52 | using DuplexMode = uint8_t; |
| 53 | using Autoneg = uint8_t; |
Johnathan Mantey | faa72e5 | 2020-01-08 10:38:58 -0800 | [diff] [blame] | 54 | using LinkUp = bool; |
Johnathan Mantey | d0679f9 | 2019-10-29 16:20:28 -0700 | [diff] [blame] | 55 | using NICEnabled = bool; |
Tejas Patil | 2c0fc56 | 2021-08-03 19:13:46 +0530 | [diff] [blame] | 56 | using MTU = size_t; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 57 | using VlanId = uint32_t; |
| 58 | using InterfaceName = std::string; |
Johnathan Mantey | d0679f9 | 2019-10-29 16:20:28 -0700 | [diff] [blame] | 59 | using InterfaceInfo = |
Tejas Patil | 2c0fc56 | 2021-08-03 19:13:46 +0530 | [diff] [blame] | 60 | std::tuple<LinkSpeed, DuplexMode, Autoneg, LinkUp, NICEnabled, MTU>; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 61 | using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>; |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 62 | using NeighborMap = std::map<std::string, std::shared_ptr<Neighbor>>; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 63 | using VlanInterfaceMap = |
| 64 | std::map<InterfaceName, std::unique_ptr<VlanInterface>>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 65 | |
| 66 | /** @class EthernetInterface |
| 67 | * @brief OpenBMC Ethernet Interface implementation. |
| 68 | * @details A concrete implementation for the |
| 69 | * xyz.openbmc_project.Network.EthernetInterface DBus API. |
| 70 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 71 | class EthernetInterface : public Ifaces |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 72 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 73 | public: |
| 74 | EthernetInterface() = delete; |
| 75 | EthernetInterface(const EthernetInterface&) = delete; |
| 76 | EthernetInterface& operator=(const EthernetInterface&) = delete; |
| 77 | EthernetInterface(EthernetInterface&&) = delete; |
| 78 | EthernetInterface& operator=(EthernetInterface&&) = delete; |
| 79 | virtual ~EthernetInterface() = default; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 80 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 81 | /** @brief Constructor to put object onto bus at a dbus path. |
| 82 | * @param[in] bus - Bus to attach to. |
| 83 | * @param[in] objPath - Path to attach at. |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 84 | * @param[in] config - The parsed configuation file. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 85 | * @param[in] parent - parent object. |
| 86 | * @param[in] emitSignal - true if the object added signal needs to be |
| 87 | * send. |
William A. Kennington III | 26275a3 | 2021-07-13 20:32:42 -0700 | [diff] [blame] | 88 | * @param[in] enabled - Override the lookup of nicEnabled |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 89 | */ |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 90 | EthernetInterface(sdbusplus::bus_t& bus, const std::string& objPath, |
William A. Kennington III | 0caf221 | 2022-08-18 18:15:51 -0700 | [diff] [blame] | 91 | const config::Parser& config, Manager& parent, |
| 92 | bool emitSignal = true, |
William A. Kennington III | 26275a3 | 2021-07-13 20:32:42 -0700 | [diff] [blame] | 93 | std::optional<bool> enabled = std::nullopt); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 94 | |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 95 | /** @brief Function used to load the nameservers. |
| 96 | */ |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 97 | void loadNameServers(const config::Parser& config); |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 98 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 99 | /** @brief Function to create ipAddress dbus object. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 100 | * @param[in] addressType - Type of ip address. |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 101 | * @param[in] ipAddress- IP address. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 102 | * @param[in] prefixLength - Length of prefix. |
| 103 | * @param[in] gateway - Gateway ip address. |
| 104 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 105 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 106 | ObjectPath ip(IP::Protocol addressType, std::string ipAddress, |
raviteja-b | ce37956 | 2019-03-28 05:59:36 -0500 | [diff] [blame] | 107 | uint8_t prefixLength, std::string gateway) override; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 108 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 109 | /** @brief Function to create static neighbor dbus object. |
| 110 | * @param[in] ipAddress - IP address. |
| 111 | * @param[in] macAddress - Low level MAC address. |
| 112 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 113 | ObjectPath neighbor(std::string ipAddress, std::string macAddress) override; |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 114 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 115 | /* @brief delete the dbus object of the given ipAddress. |
| 116 | * @param[in] ipAddress - IP address. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 117 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 118 | void deleteObject(const std::string& ipAddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 119 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 120 | /* @brief delete the dbus object of the given ipAddress. |
| 121 | * @param[in] ipAddress - IP address. |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 122 | */ |
| 123 | void deleteStaticNeighborObject(const std::string& ipAddress); |
| 124 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 125 | /* @brief delete the vlan dbus object of the given interface. |
| 126 | * Also deletes the device file and the network file. |
| 127 | * @param[in] interface - VLAN Interface. |
| 128 | */ |
| 129 | void deleteVLANObject(const std::string& interface); |
Ratan Gupta | bc88629 | 2017-07-25 18:29:57 +0530 | [diff] [blame] | 130 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 131 | /* @brief creates the dbus object(IPaddres) given in the address list. |
| 132 | * @param[in] addrs - address list for which dbus objects needs |
| 133 | * to create. |
| 134 | */ |
| 135 | void createIPAddressObjects(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 136 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 137 | /* @brief creates the dbus object(Neighbor) given in the neighbor list. |
| 138 | */ |
| 139 | void createStaticNeighborObjects(); |
| 140 | |
William A. Kennington III | d7946a7 | 2019-04-19 14:24:09 -0700 | [diff] [blame] | 141 | /* @brief Gets the index of the interface on the system |
| 142 | */ |
| 143 | unsigned ifIndex() const; |
| 144 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 145 | /* @brief Gets all the ip addresses. |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 146 | * @returns the list of ipAddress. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 147 | */ |
| 148 | const AddressMap& getAddresses() const |
| 149 | { |
| 150 | return addrs; |
| 151 | } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 152 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 153 | /* @brief Gets all the static neighbor entries. |
| 154 | * @returns Static neighbor map. |
| 155 | */ |
| 156 | const NeighborMap& getStaticNeighbors() const |
| 157 | { |
| 158 | return staticNeighbors; |
| 159 | } |
| 160 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 161 | /** Set value of DHCPEnabled */ |
William A. Kennington III | 8060c0d | 2022-08-18 19:19:34 -0700 | [diff] [blame^] | 162 | DHCPConf dhcpEnabled() const override; |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 163 | DHCPConf dhcpEnabled(DHCPConf value) override; |
William A. Kennington III | 8060c0d | 2022-08-18 19:19:34 -0700 | [diff] [blame^] | 164 | using EthernetInterfaceIntf::dhcp4; |
| 165 | bool dhcp4(bool value) override; |
| 166 | using EthernetInterfaceIntf::dhcp6; |
| 167 | bool dhcp6(bool value) override; |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 168 | |
Johnathan Mantey | faa72e5 | 2020-01-08 10:38:58 -0800 | [diff] [blame] | 169 | /** Retrieve Link State */ |
| 170 | bool linkUp() const override; |
| 171 | |
Tejas Patil | 2c0fc56 | 2021-08-03 19:13:46 +0530 | [diff] [blame] | 172 | /** Retrieve MTU Size */ |
| 173 | size_t mtu() const override; |
| 174 | |
| 175 | /** Set size of MTU */ |
| 176 | size_t mtu(size_t value) override; |
| 177 | |
Johnathan Mantey | d0679f9 | 2019-10-29 16:20:28 -0700 | [diff] [blame] | 178 | /** Set value of NICEnabled */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 179 | bool nicEnabled(bool value) override; |
Johnathan Mantey | d0679f9 | 2019-10-29 16:20:28 -0700 | [diff] [blame] | 180 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 181 | /** @brief sets the MAC address. |
| 182 | * @param[in] value - MAC address which needs to be set on the system. |
| 183 | * @returns macAddress of the interface or throws an error. |
| 184 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 185 | std::string macAddress(std::string value) override; |
Ratan Gupta | bd303b1 | 2017-08-18 17:10:07 +0530 | [diff] [blame] | 186 | |
Johnathan Mantey | 5b023f5 | 2019-06-24 16:06:37 -0700 | [diff] [blame] | 187 | /** @brief check conf file for Router Advertisements |
| 188 | * |
| 189 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 190 | bool ipv6AcceptRA(bool value) override; |
William A. Kennington III | 8060c0d | 2022-08-18 19:19:34 -0700 | [diff] [blame^] | 191 | using EthernetInterfaceIntf::ipv6AcceptRA; |
Johnathan Mantey | 5b023f5 | 2019-06-24 16:06:37 -0700 | [diff] [blame] | 192 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 193 | /** @brief sets the NTP servers. |
| 194 | * @param[in] value - vector of NTP servers. |
| 195 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 196 | ServerList ntpServers(ServerList value) override; |
Ratan Gupta | 497c0c9 | 2017-08-22 19:15:59 +0530 | [diff] [blame] | 197 | |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 198 | /** @brief sets the Static DNS/nameservers. |
| 199 | * @param[in] value - vector of DNS servers. |
| 200 | */ |
| 201 | |
| 202 | ServerList staticNameServers(ServerList value) override; |
| 203 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 204 | /** @brief create Vlan interface. |
| 205 | * @param[in] id- VLAN identifier. |
| 206 | */ |
William A. Kennington III | f4b4ff8 | 2019-04-09 19:06:52 -0700 | [diff] [blame] | 207 | ObjectPath createVLAN(VlanId id); |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 208 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 209 | /** @brief load the vlan info from the system |
| 210 | * and creates the ip address dbus objects. |
| 211 | * @param[in] vlanID- VLAN identifier. |
| 212 | */ |
| 213 | void loadVLAN(VlanId vlanID); |
Ratan Gupta | 92bc2fe | 2017-07-26 22:40:21 +0530 | [diff] [blame] | 214 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 215 | /** @brief write the network conf file with the in-memory objects. |
| 216 | */ |
| 217 | void writeConfigurationFile(); |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 218 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 219 | /** @brief delete all dbus objects. |
| 220 | */ |
| 221 | void deleteAll(); |
Ratan Gupta | e9c9b81 | 2017-09-22 17:15:37 +0530 | [diff] [blame] | 222 | |
Ravi Teja | a5a0944 | 2020-07-17 00:57:33 -0500 | [diff] [blame] | 223 | /** @brief set the default v4 gateway of the interface. |
| 224 | * @param[in] gateway - default v4 gateway of the interface. |
| 225 | */ |
| 226 | std::string defaultGateway(std::string gateway) override; |
| 227 | |
| 228 | /** @brief set the default v6 gateway of the interface. |
| 229 | * @param[in] gateway - default v6 gateway of the interface. |
| 230 | */ |
| 231 | std::string defaultGateway6(std::string gateway) override; |
| 232 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 233 | using EthernetInterfaceIntf::interfaceName; |
Johnathan Mantey | faa72e5 | 2020-01-08 10:38:58 -0800 | [diff] [blame] | 234 | using EthernetInterfaceIntf::linkUp; |
Tejas Patil | 2c0fc56 | 2021-08-03 19:13:46 +0530 | [diff] [blame] | 235 | using EthernetInterfaceIntf::mtu; |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 236 | using EthernetInterfaceIntf::nicEnabled; |
| 237 | using MacAddressIntf::macAddress; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 238 | |
Ravi Teja | a5a0944 | 2020-07-17 00:57:33 -0500 | [diff] [blame] | 239 | using EthernetInterfaceIntf::defaultGateway; |
| 240 | using EthernetInterfaceIntf::defaultGateway6; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 241 | /** @brief Absolute path of the resolv conf file */ |
| 242 | static constexpr auto resolvConfFile = "/etc/resolv.conf"; |
Ratan Gupta | 6dec390f | 2017-08-20 15:28:12 +0530 | [diff] [blame] | 243 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 244 | protected: |
| 245 | /** @brief get the info of the ethernet interface. |
| 246 | * @return tuple having the link speed,autonegotiation,duplexmode . |
| 247 | */ |
| 248 | InterfaceInfo getInterfaceInfo() const; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 249 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 250 | /* @brief delete the vlan interface from system. |
| 251 | * @param[in] interface - vlan Interface. |
| 252 | */ |
| 253 | void deleteVLANFromSystem(const std::string& interface); |
Ratan Gupta | e9c9b81 | 2017-09-22 17:15:37 +0530 | [diff] [blame] | 254 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 255 | /** @brief get the mac address of the interface. |
| 256 | * @param[in] interfaceName - Network interface name. |
| 257 | * @return macaddress on success |
| 258 | */ |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 259 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 260 | std::string getMACAddress(const std::string& interfaceName) const; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 261 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 262 | /** @brief construct the ip address dbus object path. |
| 263 | * @param[in] addressType - Type of ip address. |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 264 | * @param[in] ipAddress - IP address. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 265 | * @param[in] prefixLength - Length of prefix. |
| 266 | * @param[in] gateway - Gateway address. |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 267 | * @param[in] origin - The origin entry of the IP::Address |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 268 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 269 | * @return path of the address object. |
| 270 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 271 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 272 | std::string generateObjectPath(IP::Protocol addressType, |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 273 | const std::string& ipAddress, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 274 | uint8_t prefixLength, |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 275 | const std::string& gateway, |
| 276 | IP::AddressOrigin origin) const; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 277 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 278 | std::string |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 279 | generateStaticNeighborObjectPath(const std::string& ipAddress, |
| 280 | const std::string& macAddress) const; |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 281 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 282 | /** @brief generates the id by doing hash of ipAddress, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 283 | * prefixlength and the gateway. |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 284 | * @param[in] ipAddress - IP address. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 285 | * @param[in] prefixLength - Length of prefix. |
| 286 | * @param[in] gateway - Gateway address. |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 287 | * @param[in] origin - The string of the address origin |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 288 | * @return hash string. |
| 289 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 290 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 291 | static std::string generateId(const std::string& ipAddress, |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 292 | uint8_t prefixLength, |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 293 | const std::string& gateway, |
| 294 | const std::string& origin); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 295 | |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 296 | /** @brief generates the id by doing hash of ipAddress |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 297 | * and the mac address. |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 298 | * @param[in] ipAddress - IP address. |
| 299 | * @param[in] macAddress - Gateway address. |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 300 | * @return hash string. |
| 301 | */ |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 302 | static std::string generateNeighborId(const std::string& ipAddress, |
| 303 | const std::string& macAddress); |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 304 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 305 | /** @brief get the NTP server list from the network conf |
| 306 | * |
| 307 | */ |
| 308 | ServerList getNTPServersFromConf(); |
Ratan Gupta | 497c0c9 | 2017-08-22 19:15:59 +0530 | [diff] [blame] | 309 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 310 | /** @brief get the name server details from the network conf |
| 311 | * |
| 312 | */ |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 313 | virtual ServerList getNameServerFromResolvd(); |
Ratan Gupta | 6dec390f | 2017-08-20 15:28:12 +0530 | [diff] [blame] | 314 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 315 | /** @brief Persistent sdbusplus DBus bus connection. */ |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 316 | sdbusplus::bus_t& bus; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 317 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 318 | /** @brief Network Manager object. */ |
| 319 | Manager& manager; |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 320 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 321 | /** @brief Persistent map of IPAddress dbus objects and their names */ |
| 322 | AddressMap addrs; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 323 | |
William A. Kennington III | 0850579 | 2019-01-30 16:00:04 -0800 | [diff] [blame] | 324 | /** @brief Persistent map of Neighbor dbus objects and their names */ |
| 325 | NeighborMap staticNeighbors; |
| 326 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 327 | /** @brief Persistent map of VLAN interface dbus objects and their names */ |
| 328 | VlanInterfaceMap vlanInterfaces; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 329 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 330 | /** @brief Dbus object path */ |
| 331 | std::string objPath; |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 332 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 333 | friend class TestEthernetInterface; |
Johnathan Mantey | 817012a | 2020-01-30 15:07:39 -0800 | [diff] [blame] | 334 | |
| 335 | private: |
| 336 | /** @brief Determines if DHCP is active for the IP::Protocol supplied. |
| 337 | * @param[in] protocol - Either IPv4 or IPv6 |
Johnathan Mantey | 817012a | 2020-01-30 15:07:39 -0800 | [diff] [blame] | 338 | * @returns true/false value if DHCP is active for the input protocol |
| 339 | */ |
William A. Kennington III | 24957b9 | 2021-12-03 13:59:19 -0800 | [diff] [blame] | 340 | bool dhcpIsEnabled(IP::Protocol protocol); |
Johnathan Mantey | 817012a | 2020-01-30 15:07:39 -0800 | [diff] [blame] | 341 | |
Johnathan Mantey | 817012a | 2020-01-30 15:07:39 -0800 | [diff] [blame] | 342 | /** @brief Determines if the address is manually assigned |
| 343 | * @param[in] origin - The origin entry of the IP::Address |
| 344 | * @returns true/false value if the address is static |
| 345 | */ |
| 346 | bool originIsManuallyAssigned(IP::AddressOrigin origin); |
William A. Kennington III | 26275a3 | 2021-07-13 20:32:42 -0700 | [diff] [blame] | 347 | |
| 348 | /** @brief Determines if the NIC is enabled in systemd |
| 349 | * @returns true/false value if the NIC is enabled |
| 350 | */ |
| 351 | bool queryNicEnabled() const; |
William A. Kennington III | a520a39 | 2022-08-08 12:17:34 -0700 | [diff] [blame] | 352 | |
| 353 | std::string vlanIntfName(VlanId id) const; |
| 354 | std::string vlanObjPath(VlanId id) const; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | } // namespace network |
| 358 | } // namespace phosphor |