| #pragma once |
| #include "types.hpp" |
| |
| #include <net/ethernet.h> |
| |
| #include <cstdint> |
| #include <optional> |
| #include <stdplus/zstring.hpp> |
| #include <stdplus/zstring_view.hpp> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
| |
| struct nlmsghdr; |
| |
| namespace phosphor::network::system |
| { |
| struct EthInfo |
| { |
| bool autoneg; |
| uint16_t speed; |
| }; |
| EthInfo getEthInfo(stdplus::zstring_view ifname); |
| |
| bool intfIsRunning(std::string_view ifname); |
| |
| std::optional<unsigned> getMTU(stdplus::zstring_view ifname); |
| |
| void setMTU(std::string_view ifname, unsigned mtu); |
| |
| void setNICUp(std::string_view ifname, bool up); |
| |
| /** @class InterfaceInfo |
| * @brief Information about interfaces from the kernel |
| */ |
| struct InterfaceInfo |
| { |
| unsigned idx; |
| unsigned flags; |
| std::optional<std::string> name = std::nullopt; |
| std::optional<ether_addr> mac = std::nullopt; |
| std::optional<unsigned> mtu = std::nullopt; |
| std::optional<unsigned> parent_idx = std::nullopt; |
| std::optional<std::string> kind = std::nullopt; |
| std::optional<uint16_t> vlan_id = std::nullopt; |
| |
| constexpr bool operator==(const InterfaceInfo& rhs) const noexcept |
| { |
| return idx == rhs.idx && flags == rhs.flags && name == rhs.name && |
| mac == rhs.mac && mtu == rhs.mtu && |
| parent_idx == rhs.parent_idx && kind == rhs.kind && |
| vlan_id == rhs.vlan_id; |
| } |
| }; |
| |
| struct AddressFilter |
| { |
| unsigned ifidx = 0; |
| }; |
| |
| struct NeighborFilter |
| { |
| unsigned ifidx = 0; |
| }; |
| |
| namespace detail |
| { |
| InterfaceInfo parseInterface(const nlmsghdr& hdr, std::string_view msg); |
| bool validateNewInterface(const InterfaceInfo& info); |
| bool validateNewAddr(const AddressInfo& info, |
| const AddressFilter& filter) noexcept; |
| bool validateNewNeigh(const NeighborInfo& info, |
| const NeighborFilter& filter) noexcept; |
| } // namespace detail |
| |
| /** @brief Get all the interfaces from the system. |
| * @returns list of interface names. |
| */ |
| std::vector<InterfaceInfo> getInterfaces(); |
| |
| /** @brief Get all the addreses from the system. |
| * @returns list of addresses |
| */ |
| std::vector<AddressInfo> getAddresses(const AddressFilter& filter); |
| |
| /** @brief Returns a list of system neighbor table |
| */ |
| std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter); |
| |
| } // namespace phosphor::network::system |