blob: 0bd082b20b3462c123f4d2e1b8ee5ff08a1bb5b0 [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
3#include "ethernet_interface.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05304#include "types.hpp"
Ratan Gupta05eb1092017-04-14 16:33:53 +05305#include "xyz/openbmc_project/Network/VLAN/Create/server.hpp"
Michael Tritz29f2fd62017-05-22 15:27:26 -05006#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +05307
8#include <sdbusplus/bus.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +05309#include <ifaddrs.h>
Ratan Gupta05eb1092017-04-14 16:33:53 +053010
11#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053012#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053013#include <string>
14#include <vector>
15
16namespace phosphor
17{
18namespace network
19{
20
21namespace details
22{
23
Michael Tritz29f2fd62017-05-22 15:27:26 -050024template <typename T, typename U>
25using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053026
Michael Tritz29f2fd62017-05-22 15:27:26 -050027using VLANCreateIface = details::ServerObject<
28 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
29 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053030
31using IntfName = std::string;
32
Ratan Gupta738a67f2017-04-21 10:38:05 +053033struct AddrInfo
34{
Ratan Gupta05eb1092017-04-14 16:33:53 +053035 short addrType;
36 std::string ipaddress;
37};
38
Ratan Gupta6811f822017-04-14 16:34:56 +053039using Addr_t = ifaddrs*;
40
41struct AddrDeleter
42{
43 void operator()(Addr_t ptr) const
44 {
45 freeifaddrs(ptr);
46 }
47};
48
49using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
50
Ratan Gupta05eb1092017-04-14 16:33:53 +053051using AddrList = std::list<AddrInfo>;
52using IntfAddrMap = std::map<IntfName, AddrList>;
53
54} // namespace details
55
56/** @class Manager
57 * @brief OpenBMC network manager implementation.
58 */
59class Manager : public details::VLANCreateIface
60{
61 public:
62 Manager() = delete;
63 Manager(const Manager&) = delete;
64 Manager& operator=(const Manager&) = delete;
65 Manager(Manager&&) = delete;
66 Manager& operator=(Manager&&) = delete;
67 virtual ~Manager() = default;
68
69 /** @brief Constructor to put object onto bus at a dbus path.
70 * @param[in] bus - Bus to attach to.
71 * @param[in] objPath - Path to attach at.
72 */
73 Manager(sdbusplus::bus::bus& bus, const char* objPath);
74
Ratan Gupta82549cc2017-04-21 08:45:23 +053075 void vLAN(IntfName interfaceName, uint16_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053076
77 private:
78 /** @brief Get all the interfaces from the system.
79 * @returns list of interface names.
80 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053081 IntfAddrMap getInterfaceAddrs() const;
Ratan Gupta05eb1092017-04-14 16:33:53 +053082
Ratan Gupta738a67f2017-04-21 10:38:05 +053083 /** @brief converts the given subnet into prefix notation **/
84 uint8_t toCidr(const char* subnetMask) const;
85
Ratan Gupta05eb1092017-04-14 16:33:53 +053086 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053087 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053088
Michael Tritz29f2fd62017-05-22 15:27:26 -050089 /** @brief BMC network reset - resets network configuration for BMC. */
90 void reset() override;
91
Ratan Gupta05eb1092017-04-14 16:33:53 +053092};
93
94} // namespace network
95} // namespace phosphor