blob: f37544c2c42d5e6e4b16220581328024c0cbb522 [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"
6
7#include <sdbusplus/bus.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +05308#include <ifaddrs.h>
Ratan Gupta05eb1092017-04-14 16:33:53 +05309
10#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053011#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053012#include <string>
13#include <vector>
14
15namespace phosphor
16{
17namespace network
18{
19
20namespace details
21{
22
23template <typename T>
24using ServerObject = typename sdbusplus::server::object::object<T>;
25
26using VLANCreateIface =
27 details::ServerObject<sdbusplus::xyz::openbmc_project::
28 Network::VLAN::server::Create>;
29
30using IntfName = std::string;
31
Ratan Gupta738a67f2017-04-21 10:38:05 +053032struct AddrInfo
33{
Ratan Gupta05eb1092017-04-14 16:33:53 +053034 short addrType;
35 std::string ipaddress;
36};
37
Ratan Gupta6811f822017-04-14 16:34:56 +053038using Addr_t = ifaddrs*;
39
40struct AddrDeleter
41{
42 void operator()(Addr_t ptr) const
43 {
44 freeifaddrs(ptr);
45 }
46};
47
48using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
49
Ratan Gupta05eb1092017-04-14 16:33:53 +053050using AddrList = std::list<AddrInfo>;
51using IntfAddrMap = std::map<IntfName, AddrList>;
52
53} // namespace details
54
55/** @class Manager
56 * @brief OpenBMC network manager implementation.
57 */
58class Manager : public details::VLANCreateIface
59{
60 public:
61 Manager() = delete;
62 Manager(const Manager&) = delete;
63 Manager& operator=(const Manager&) = delete;
64 Manager(Manager&&) = delete;
65 Manager& operator=(Manager&&) = delete;
66 virtual ~Manager() = default;
67
68 /** @brief Constructor to put object onto bus at a dbus path.
69 * @param[in] bus - Bus to attach to.
70 * @param[in] objPath - Path to attach at.
71 */
72 Manager(sdbusplus::bus::bus& bus, const char* objPath);
73
Ratan Gupta82549cc2017-04-21 08:45:23 +053074 void vLAN(IntfName interfaceName, uint16_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053075
76 private:
77 /** @brief Get all the interfaces from the system.
78 * @returns list of interface names.
79 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053080 IntfAddrMap getInterfaceAddrs() const;
Ratan Gupta05eb1092017-04-14 16:33:53 +053081
Ratan Gupta738a67f2017-04-21 10:38:05 +053082 /** @brief converts the given subnet into prefix notation **/
83 uint8_t toCidr(const char* subnetMask) const;
84
Ratan Gupta05eb1092017-04-14 16:33:53 +053085 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053086 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053087
88};
89
90} // namespace network
91} // namespace phosphor