blob: 9217a1f588ab40735e1bf94b5acf2a8b1755d1d5 [file] [log] [blame]
William A. Kennington III2e09d272022-10-14 17:15:00 -07001#pragma once
2#include "types.hpp"
3
William A. Kennington IIIfd862be2022-10-09 18:40:55 -07004#include <net/ethernet.h>
William A. Kennington III2e09d272022-10-14 17:15:00 -07005
6#include <cstdint>
7#include <optional>
8#include <stdplus/zstring.hpp>
9#include <stdplus/zstring_view.hpp>
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070010#include <string>
William A. Kennington III2e09d272022-10-14 17:15:00 -070011#include <string_view>
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070012#include <vector>
13
14struct nlmsghdr;
William A. Kennington III2e09d272022-10-14 17:15:00 -070015
16namespace phosphor::network::system
17{
William A. Kennington III2e09d272022-10-14 17:15:00 -070018struct EthInfo
19{
20 bool autoneg;
21 uint16_t speed;
22};
23EthInfo getEthInfo(stdplus::zstring_view ifname);
24
25bool intfIsRunning(std::string_view ifname);
26
William A. Kennington III2e09d272022-10-14 17:15:00 -070027std::optional<unsigned> getMTU(stdplus::zstring_view ifname);
28
29void setMTU(std::string_view ifname, unsigned mtu);
30
31void setNICUp(std::string_view ifname, bool up);
32
William A. Kennington III6a923632022-11-06 18:17:33 -080033struct AddressFilter
34{
35 unsigned ifidx = 0;
36};
37
William A. Kennington IIIa8426902022-11-07 15:37:41 -080038struct NeighborFilter
39{
40 unsigned ifidx = 0;
41};
42
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070043namespace detail
44{
45InterfaceInfo parseInterface(const nlmsghdr& hdr, std::string_view msg);
46bool validateNewInterface(const InterfaceInfo& info);
William A. Kennington III6a923632022-11-06 18:17:33 -080047bool validateNewAddr(const AddressInfo& info,
48 const AddressFilter& filter) noexcept;
William A. Kennington IIIa8426902022-11-07 15:37:41 -080049bool validateNewNeigh(const NeighborInfo& info,
50 const NeighborFilter& filter) noexcept;
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070051} // namespace detail
52
William A. Kennington III2e09d272022-10-14 17:15:00 -070053/** @brief Get all the interfaces from the system.
54 * @returns list of interface names.
55 */
William A. Kennington IIIfd862be2022-10-09 18:40:55 -070056std::vector<InterfaceInfo> getInterfaces();
William A. Kennington III2e09d272022-10-14 17:15:00 -070057
William A. Kennington III6a923632022-11-06 18:17:33 -080058/** @brief Get all the addreses from the system.
59 * @returns list of addresses
60 */
61std::vector<AddressInfo> getAddresses(const AddressFilter& filter);
62
William A. Kennington IIIa8426902022-11-07 15:37:41 -080063/** @brief Returns a list of system neighbor table
64 */
65std::vector<NeighborInfo> getNeighbors(const NeighborFilter& filter);
66
William A. Kennington III2e09d272022-10-14 17:15:00 -070067} // namespace phosphor::network::system