Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 2 | #include "dhcp_configuration.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 3 | #include "ethernet_interface.hpp" |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 4 | #include "system_configuration.hpp" |
William A. Kennington III | dd9ef81 | 2022-10-05 02:08:02 -0700 | [diff] [blame] | 5 | #include "types.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 7 | |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 8 | #include <function2/function2.hpp> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 10 | #include <sdbusplus/bus/match.hpp> |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 11 | #include <sdbusplus/message/native_types.hpp> |
William A. Kennington III | 9ede1b7 | 2022-11-21 01:59:28 -0800 | [diff] [blame] | 12 | #include <stdplus/pinned.hpp> |
William A. Kennington III | 60903ee | 2023-06-02 15:17:49 -0700 | [diff] [blame] | 13 | #include <stdplus/str/maps.hpp> |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 14 | #include <stdplus/zstring_view.hpp> |
Patrick Williams | 89d734b | 2023-05-10 07:50:25 -0500 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
| 16 | |
| 17 | #include <filesystem> |
| 18 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 19 | #include <string> |
William A. Kennington III | dd9ef81 | 2022-10-05 02:08:02 -0700 | [diff] [blame] | 20 | #include <string_view> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | namespace phosphor |
| 24 | { |
| 25 | namespace network |
| 26 | { |
| 27 | |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 28 | using ManagerIface = sdbusplus::server::object_t< |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 29 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 30 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 31 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 32 | /** @class Manager |
| 33 | * @brief OpenBMC network manager implementation. |
| 34 | */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 35 | class Manager : public ManagerIface |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 36 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 37 | public: |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 38 | Manager(Manager&&) = delete; |
| 39 | Manager& operator=(Manager&&) = delete; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 40 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 41 | /** @brief Constructor to put object onto bus at a dbus path. |
| 42 | * @param[in] bus - Bus to attach to. |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 43 | * @param[in] reload - The executor for reloading configs |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 44 | * @param[in] objPath - Path to attach at. |
William A. Kennington III | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 45 | * @param[in] confDir - Network Configuration directory path. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 46 | */ |
William A. Kennington III | d40046b | 2023-06-30 20:36:11 -0700 | [diff] [blame] | 47 | Manager(stdplus::PinnedRef<sdbusplus::bus_t> bus, |
| 48 | stdplus::PinnedRef<DelayedExecutor> reload, |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 49 | stdplus::zstring_view objPath, |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 50 | const std::filesystem::path& confDir); |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 51 | |
William A. Kennington III | dd9ef81 | 2022-10-05 02:08:02 -0700 | [diff] [blame] | 52 | ObjectPath vlan(std::string interfaceName, uint32_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 53 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 54 | /** @brief write the network conf file with the in-memory objects. |
| 55 | */ |
| 56 | void writeToConfigurationFile(); |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 57 | |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 58 | /** @brief Adds a single interface to the interface map */ |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame] | 59 | void addInterface(const InterfaceInfo& info); |
| 60 | void removeInterface(const InterfaceInfo& info); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 61 | |
William A. Kennington III | ed5ff47 | 2022-11-12 16:24:02 -0800 | [diff] [blame] | 62 | /** @brief Add / remove an address to the interface or queue */ |
| 63 | void addAddress(const AddressInfo& info); |
| 64 | void removeAddress(const AddressInfo& info); |
| 65 | |
| 66 | /** @brief Add / remove a neighbor to the interface or queue */ |
| 67 | void addNeighbor(const NeighborInfo& info); |
| 68 | void removeNeighbor(const NeighborInfo& info); |
| 69 | |
| 70 | /** @brief Add / remove default gateway for interface */ |
William A. Kennington III | 9b2a20d | 2023-06-17 14:05:48 -0700 | [diff] [blame] | 71 | void addDefGw(unsigned ifidx, stdplus::InAnyAddr addr); |
| 72 | void removeDefGw(unsigned ifidx, stdplus::InAnyAddr addr); |
William A. Kennington III | ed5ff47 | 2022-11-12 16:24:02 -0800 | [diff] [blame] | 73 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 74 | /** @brief gets the network conf directory. |
| 75 | */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 76 | inline const auto& getConfDir() const |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 77 | { |
| 78 | return confDir; |
| 79 | } |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 80 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 81 | /** @brief gets the system conf object. |
| 82 | * |
| 83 | */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 84 | inline auto& getSystemConf() |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 85 | { |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 86 | return *systemConf; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 87 | } |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 88 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 89 | /** @brief gets the dhcp conf object. |
| 90 | * |
| 91 | */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 92 | inline auto& getDHCPConf() |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 93 | { |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 94 | return *dhcpConf; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 95 | } |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 96 | |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 97 | /** @brief Arms a timer to tell systemd-network to reload all of the network |
| 98 | * configurations |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 99 | */ |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 100 | inline void reloadConfigs() |
| 101 | { |
William A. Kennington III | d40046b | 2023-06-30 20:36:11 -0700 | [diff] [blame] | 102 | reload.get().schedule(); |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 103 | } |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 104 | |
William A. Kennington III | 09f3a4a | 2022-10-25 02:59:16 -0700 | [diff] [blame] | 105 | /** @brief Persistent map of EthernetInterface dbus objects and their names |
Patrick Venture | d94d23e | 2019-01-07 13:05:23 -0800 | [diff] [blame] | 106 | */ |
William A. Kennington III | 60903ee | 2023-06-02 15:17:49 -0700 | [diff] [blame] | 107 | stdplus::string_umap<std::unique_ptr<EthernetInterface>> interfaces; |
William A. Kennington III | 67b09da | 2022-10-31 14:09:53 -0700 | [diff] [blame] | 108 | std::unordered_map<unsigned, EthernetInterface*> interfacesByIdx; |
William A. Kennington III | 93f5c6d | 2022-11-17 16:23:44 -0800 | [diff] [blame] | 109 | std::unordered_set<unsigned> ignoredIntf; |
Patrick Venture | d94d23e | 2019-01-07 13:05:23 -0800 | [diff] [blame] | 110 | |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 111 | /** @brief Adds a hook that runs immediately prior to reloading |
| 112 | * |
| 113 | * @param[in] hook - The hook to execute before reloading |
| 114 | */ |
| 115 | inline void addReloadPreHook(fu2::unique_function<void()>&& hook) |
| 116 | { |
| 117 | reloadPreHooks.push_back(std::move(hook)); |
| 118 | } |
William A. Kennington III | de4668a | 2022-11-17 16:02:30 -0800 | [diff] [blame] | 119 | inline void addReloadPostHook(fu2::unique_function<void()>&& hook) |
| 120 | { |
| 121 | reloadPostHooks.push_back(std::move(hook)); |
| 122 | } |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 123 | |
Ratan Gupta | 3529717 | 2018-11-28 18:40:16 +0530 | [diff] [blame] | 124 | protected: |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 125 | /** @brief Handle to the object used to trigger reloads of networkd. */ |
William A. Kennington III | d40046b | 2023-06-30 20:36:11 -0700 | [diff] [blame] | 126 | stdplus::PinnedRef<DelayedExecutor> reload; |
William A. Kennington III | de70ccf | 2022-11-20 17:18:01 -0800 | [diff] [blame] | 127 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 128 | /** @brief Persistent sdbusplus DBus bus connection. */ |
William A. Kennington III | 9ede1b7 | 2022-11-21 01:59:28 -0800 | [diff] [blame] | 129 | stdplus::PinnedRef<sdbusplus::bus_t> bus; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 130 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 131 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 132 | void reset() override; |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 133 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 134 | /** @brief Path of Object. */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 135 | sdbusplus::message::object_path objPath; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 136 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 137 | /** @brief pointer to system conf object. */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 138 | std::unique_ptr<SystemConfiguration> systemConf = nullptr; |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 139 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 140 | /** @brief pointer to dhcp conf object. */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 141 | std::unique_ptr<dhcp::Configuration> dhcpConf = nullptr; |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 142 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 143 | /** @brief Network Configuration directory. */ |
William A. Kennington III | 5b17938 | 2022-11-15 15:23:26 -0800 | [diff] [blame] | 144 | std::filesystem::path confDir; |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 145 | |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 146 | /** @brief Map of interface info for undiscovered interfaces */ |
William A. Kennington III | 2fb0c87 | 2022-11-15 19:35:39 -0800 | [diff] [blame] | 147 | std::unordered_map<unsigned, AllIntfInfo> intfInfo; |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 148 | |
| 149 | /** @brief Map of enabled interfaces */ |
| 150 | std::unordered_map<unsigned, bool> systemdNetworkdEnabled; |
| 151 | sdbusplus::bus::match_t systemdNetworkdEnabledMatch; |
| 152 | |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 153 | /** @brief List of hooks to execute during the next reload */ |
| 154 | std::vector<fu2::unique_function<void()>> reloadPreHooks; |
William A. Kennington III | de4668a | 2022-11-17 16:02:30 -0800 | [diff] [blame] | 155 | std::vector<fu2::unique_function<void()>> reloadPostHooks; |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 156 | |
| 157 | /** @brief Handles the recipt of an adminstrative state string */ |
| 158 | void handleAdminState(std::string_view state, unsigned ifidx); |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame] | 159 | |
| 160 | /** @brief Creates the interface in the maps */ |
William A. Kennington III | 2fb0c87 | 2022-11-15 19:35:39 -0800 | [diff] [blame] | 161 | void createInterface(const AllIntfInfo& info, bool enabled); |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } // namespace network |
| 165 | } // namespace phosphor |