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 validateNewAddr(const AddressInfo& info, 47 const AddressFilter& filter) noexcept; 48 bool validateNewNeigh(const NeighborInfo& info, 49 const NeighborFilter& filter) noexcept; 50 } // namespace detail 51 52 /** @brief Get all the interfaces from the system. 53 * @returns list of interface names. 54 */ 55 std::vector<InterfaceInfo> getInterfaces(); 56 57 /** @brief Get all the addreses from the system. 58 * @returns list of addresses 59 */ 60 std::vector<AddressInfo> getAddresses(const AddressFilter& filter); 61 62 /** @brief Returns a list of system neighbor table 63 */ 64 std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter); 65 66 } // namespace phosphor::network::system 67