1 #pragma once 2 #include "types.hpp" 3 4 #include <net/ethernet.h> 5 6 #include <cstdint> 7 #include <optional> 8 #include <stdplus/zstring.hpp> 9 #include <stdplus/zstring_view.hpp> 10 #include <string> 11 #include <string_view> 12 #include <vector> 13 14 struct nlmsghdr; 15 16 namespace phosphor::network::system 17 { 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 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 33 struct AddressFilter 34 { 35 unsigned ifidx = 0; 36 }; 37 38 struct NeighborFilter 39 { 40 unsigned ifidx = 0; 41 }; 42 43 namespace detail 44 { 45 InterfaceInfo parseInterface(const nlmsghdr& hdr, std::string_view msg); 46 bool validateNewInterface(const InterfaceInfo& info); 47 bool validateNewAddr(const AddressInfo& info, 48 const AddressFilter& filter) noexcept; 49 bool validateNewNeigh(const NeighborInfo& info, 50 const NeighborFilter& filter) noexcept; 51 } // namespace detail 52 53 /** @brief Get all the interfaces from the system. 54 * @returns list of interface names. 55 */ 56 std::vector<InterfaceInfo> getInterfaces(); 57 58 /** @brief Get all the addreses from the system. 59 * @returns list of addresses 60 */ 61 std::vector<AddressInfo> getAddresses(const AddressFilter& filter); 62 63 /** @brief Returns a list of system neighbor table 64 */ 65 std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter); 66 67 } // namespace phosphor::network::system 68