Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "ethernet_interface.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 4 | #include "types.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 7 | |
| 8 | #include <sdbusplus/bus.hpp> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 9 | #include <ifaddrs.h> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 10 | |
| 11 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 12 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
| 20 | |
| 21 | namespace details |
| 22 | { |
| 23 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 24 | template <typename T, typename U> |
| 25 | using ServerObject = typename sdbusplus::server::object::object<T, U>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 26 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 27 | using VLANCreateIface = details::ServerObject< |
| 28 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 29 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 30 | |
| 31 | using IntfName = std::string; |
| 32 | |
Ratan Gupta | 738a67f | 2017-04-21 10:38:05 +0530 | [diff] [blame] | 33 | struct AddrInfo |
| 34 | { |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 35 | short addrType; |
| 36 | std::string ipaddress; |
| 37 | }; |
| 38 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 39 | using Addr_t = ifaddrs*; |
| 40 | |
| 41 | struct AddrDeleter |
| 42 | { |
| 43 | void operator()(Addr_t ptr) const |
| 44 | { |
| 45 | freeifaddrs(ptr); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>; |
| 50 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 51 | using AddrList = std::list<AddrInfo>; |
| 52 | using IntfAddrMap = std::map<IntfName, AddrList>; |
| 53 | |
| 54 | } // namespace details |
| 55 | |
| 56 | /** @class Manager |
| 57 | * @brief OpenBMC network manager implementation. |
| 58 | */ |
| 59 | class 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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 75 | void vLAN(IntfName interfaceName, uint16_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | /** @brief Get all the interfaces from the system. |
| 79 | * @returns list of interface names. |
| 80 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 81 | IntfAddrMap getInterfaceAddrs() const; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 82 | |
Ratan Gupta | 719f83a | 2017-06-02 11:54:53 +0530 | [diff] [blame] | 83 | /** @brief converts the given subnet into prefix notation |
Ratan Gupta | c41692c | 2017-05-09 18:35:36 +0530 | [diff] [blame] | 84 | * @param[in] addressFamily - IP address family(AF_INET/AF_INET6) |
| 85 | * @param[in] subnetMask - SubnetMask which needs to be converted. |
| 86 | * @returns prefix. |
Ratan Gupta | 719f83a | 2017-06-02 11:54:53 +0530 | [diff] [blame] | 87 | */ |
Ratan Gupta | c41692c | 2017-05-09 18:35:36 +0530 | [diff] [blame] | 88 | 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 Gupta | 738a67f | 2017-04-21 10:38:05 +0530 | [diff] [blame] | 95 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 96 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 97 | std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 98 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 99 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 100 | void reset() override; |
| 101 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace network |
| 105 | } // namespace phosphor |