blob: d0cb77982be2bb0aef7c5a39de2ed002042da69e [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 Gupta719f83a2017-06-02 11:54:53 +053083 /** @brief converts the given subnet into prefix notation
Ratan Guptac41692c2017-05-09 18:35:36 +053084 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6)
85 * @param[in] subnetMask - SubnetMask which needs to be converted.
86 * @returns prefix.
Ratan Gupta719f83a2017-06-02 11:54:53 +053087 */
Ratan Guptac41692c2017-05-09 18:35:36 +053088 uint8_t toCidr(int addressFamily, const std::string& subnetMask) const;
89
90 /** @brief converts the given V6 subnet into prefix notation
91 * @param[in] subnetMask - SubnetMask which needs to be converted.
92 * @returns prefix.
93 */
94 uint8_t toV6Cidr(const std::string& subnetMask) const;
Ratan Gupta738a67f2017-04-21 10:38:05 +053095
Ratan Gupta05eb1092017-04-14 16:33:53 +053096 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053097 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053098
Michael Tritz29f2fd62017-05-22 15:27:26 -050099 /** @brief BMC network reset - resets network configuration for BMC. */
100 void reset() override;
101
Ratan Gupta05eb1092017-04-14 16:33:53 +0530102};
103
104} // namespace network
105} // namespace phosphor