William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "types.hpp" |
| 3 | |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 4 | #include <net/ethernet.h> |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 5 | |
| 6 | #include <cstdint> |
| 7 | #include <optional> |
| 8 | #include <stdplus/zstring.hpp> |
| 9 | #include <stdplus/zstring_view.hpp> |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 10 | #include <string> |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 11 | #include <string_view> |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | struct nlmsghdr; |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 15 | |
| 16 | namespace phosphor::network::system |
| 17 | { |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 18 | struct EthInfo |
| 19 | { |
| 20 | bool autoneg; |
| 21 | uint16_t speed; |
| 22 | }; |
| 23 | EthInfo getEthInfo(stdplus::zstring_view ifname); |
| 24 | |
| 25 | bool intfIsRunning(std::string_view ifname); |
| 26 | |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 27 | std::optional<unsigned> getMTU(stdplus::zstring_view ifname); |
| 28 | |
| 29 | void setMTU(std::string_view ifname, unsigned mtu); |
| 30 | |
| 31 | void setNICUp(std::string_view ifname, bool up); |
| 32 | |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 33 | /** @class InterfaceInfo |
| 34 | * @brief Information about interfaces from the kernel |
| 35 | */ |
| 36 | struct InterfaceInfo |
| 37 | { |
| 38 | unsigned idx; |
| 39 | unsigned flags; |
| 40 | std::optional<std::string> name = std::nullopt; |
| 41 | std::optional<ether_addr> mac = std::nullopt; |
| 42 | std::optional<unsigned> mtu = std::nullopt; |
William A. Kennington III | 09f3a4a | 2022-10-25 02:59:16 -0700 | [diff] [blame] | 43 | std::optional<unsigned> parent_idx = std::nullopt; |
| 44 | std::optional<std::string> kind = std::nullopt; |
| 45 | std::optional<uint16_t> vlan_id = std::nullopt; |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 46 | |
| 47 | constexpr bool operator==(const InterfaceInfo& rhs) const noexcept |
| 48 | { |
| 49 | return idx == rhs.idx && flags == rhs.flags && name == rhs.name && |
William A. Kennington III | 09f3a4a | 2022-10-25 02:59:16 -0700 | [diff] [blame] | 50 | mac == rhs.mac && mtu == rhs.mtu && |
| 51 | parent_idx == rhs.parent_idx && kind == rhs.kind && |
| 52 | vlan_id == rhs.vlan_id; |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
| 56 | namespace detail |
| 57 | { |
| 58 | InterfaceInfo parseInterface(const nlmsghdr& hdr, std::string_view msg); |
| 59 | bool validateNewInterface(const InterfaceInfo& info); |
| 60 | } // namespace detail |
| 61 | |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 62 | /** @brief Get all the interfaces from the system. |
| 63 | * @returns list of interface names. |
| 64 | */ |
William A. Kennington III | fd862be | 2022-10-09 18:40:55 -0700 | [diff] [blame] | 65 | std::vector<InterfaceInfo> getInterfaces(); |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 66 | |
| 67 | } // namespace phosphor::network::system |