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