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