11bbe3d1eSWilliam A. Kennington III #pragma once
21bbe3d1eSWilliam A. Kennington III #include "types.hpp"
31bbe3d1eSWilliam A. Kennington III
401c816f2SWilliam A. Kennington III #include <stdplus/raw.hpp>
58664252aSWilliam A. Kennington III #include <stdplus/zstring_view.hpp>
689d734b9SPatrick Williams
789d734b9SPatrick Williams #include <optional>
81bbe3d1eSWilliam A. Kennington III #include <string>
91bbe3d1eSWilliam A. Kennington III #include <string_view>
1095530ec9SWilliam A. Kennington III #include <unordered_set>
111bbe3d1eSWilliam A. Kennington III
121bbe3d1eSWilliam A. Kennington III namespace phosphor
131bbe3d1eSWilliam A. Kennington III {
141bbe3d1eSWilliam A. Kennington III namespace network
151bbe3d1eSWilliam A. Kennington III {
1620efa79fSWilliam A. Kennington III namespace config
1720efa79fSWilliam A. Kennington III {
1820efa79fSWilliam A. Kennington III class Parser;
1920efa79fSWilliam A. Kennington III }
201bbe3d1eSWilliam A. Kennington III
211bbe3d1eSWilliam A. Kennington III /* @brief converts a sockaddr for the specified address family into
221bbe3d1eSWilliam A. Kennington III * a type_safe InAddrAny.
2397b5dc68SWilliam A. Kennington III * @param[in] family - The address family of the buf
241bbe3d1eSWilliam A. Kennington III * @param[in] buf - The network byte order address
251bbe3d1eSWilliam A. Kennington III */
addrFromBuf(int family,std::string_view buf)269b2a20d3SWilliam A. Kennington III constexpr stdplus::InAnyAddr addrFromBuf(int family, std::string_view buf)
2701c816f2SWilliam A. Kennington III {
2801c816f2SWilliam A. Kennington III switch (family)
2901c816f2SWilliam A. Kennington III {
3001c816f2SWilliam A. Kennington III case AF_INET:
319b2a20d3SWilliam A. Kennington III return stdplus::raw::copyFromStrict<stdplus::In4Addr>(buf);
3201c816f2SWilliam A. Kennington III case AF_INET6:
339b2a20d3SWilliam A. Kennington III return stdplus::raw::copyFromStrict<stdplus::In6Addr>(buf);
3401c816f2SWilliam A. Kennington III }
3501c816f2SWilliam A. Kennington III throw std::invalid_argument("Unrecognized family");
3601c816f2SWilliam A. Kennington III }
371bbe3d1eSWilliam A. Kennington III
381bbe3d1eSWilliam A. Kennington III /** @brief Converts the interface name into a u-boot environment
391bbe3d1eSWilliam A. Kennington III * variable that would hold its ethernet address.
401bbe3d1eSWilliam A. Kennington III *
411bbe3d1eSWilliam A. Kennington III * @param[in] intf - interface name
421bbe3d1eSWilliam A. Kennington III * @return The name of th environment key
431bbe3d1eSWilliam A. Kennington III */
4469f4554bSWilliam A. Kennington III std::optional<std::string> interfaceToUbootEthAddr(std::string_view intf);
451bbe3d1eSWilliam A. Kennington III
46a520a39dSWilliam A. Kennington III /** @brief read the IPv6AcceptRA value from the configuration file
47a520a39dSWilliam A. Kennington III * @param[in] config - The parsed configuration.
481bbe3d1eSWilliam A. Kennington III */
49a520a39dSWilliam A. Kennington III bool getIPv6AcceptRA(const config::Parser& config);
50a520a39dSWilliam A. Kennington III
51a520a39dSWilliam A. Kennington III /** @brief read the DHCP value from the configuration file
52a520a39dSWilliam A. Kennington III * @param[in] config - The parsed configuration.
53a520a39dSWilliam A. Kennington III */
548060c0daSWilliam A. Kennington III struct DHCPVal
558060c0daSWilliam A. Kennington III {
568060c0daSWilliam A. Kennington III bool v4, v6;
578060c0daSWilliam A. Kennington III };
58*57dfea94SJishnu CM
59*57dfea94SJishnu CM enum class DHCPType
60*57dfea94SJishnu CM {
61*57dfea94SJishnu CM v4,
62*57dfea94SJishnu CM v6
63*57dfea94SJishnu CM };
64*57dfea94SJishnu CM
658060c0daSWilliam A. Kennington III DHCPVal getDHCPValue(const config::Parser& config);
661bbe3d1eSWilliam A. Kennington III
67e94c9ffcSWilliam A. Kennington III /** @brief Read a boolean DHCP property from a conf file
68e94c9ffcSWilliam A. Kennington III * @param[in] config - The parsed configuration.
69*57dfea94SJishnu CM * @param[in] nwType - The network type.
70e94c9ffcSWilliam A. Kennington III * @param[in] key - The property name.
71e94c9ffcSWilliam A. Kennington III */
72*57dfea94SJishnu CM bool getDHCPProp(const config::Parser& config, DHCPType dhcpType,
73*57dfea94SJishnu CM std::string_view key);
74e94c9ffcSWilliam A. Kennington III
751bbe3d1eSWilliam A. Kennington III namespace internal
761bbe3d1eSWilliam A. Kennington III {
771bbe3d1eSWilliam A. Kennington III
781bbe3d1eSWilliam A. Kennington III /* @brief runs the given command in child process.
791bbe3d1eSWilliam A. Kennington III * @param[in] path - path of the binary file which needs to be execeuted.
801bbe3d1eSWilliam A. Kennington III * @param[in] args - arguments of the command.
811bbe3d1eSWilliam A. Kennington III */
828664252aSWilliam A. Kennington III void executeCommandinChildProcess(stdplus::zstring_view path, char** args);
831bbe3d1eSWilliam A. Kennington III
841bbe3d1eSWilliam A. Kennington III /** @brief Get ignored interfaces from environment */
851bbe3d1eSWilliam A. Kennington III std::string_view getIgnoredInterfacesEnv();
861bbe3d1eSWilliam A. Kennington III
871bbe3d1eSWilliam A. Kennington III /** @brief Parse the comma separated interface names */
8895530ec9SWilliam A. Kennington III std::unordered_set<std::string_view>
8995530ec9SWilliam A. Kennington III parseInterfaces(std::string_view interfaces);
901bbe3d1eSWilliam A. Kennington III
911bbe3d1eSWilliam A. Kennington III /** @brief Get the ignored interfaces */
9295530ec9SWilliam A. Kennington III const std::unordered_set<std::string_view>& getIgnoredInterfaces();
931bbe3d1eSWilliam A. Kennington III
941bbe3d1eSWilliam A. Kennington III } // namespace internal
951bbe3d1eSWilliam A. Kennington III
961bbe3d1eSWilliam A. Kennington III /* @brief runs the given command in child process.
971bbe3d1eSWilliam A. Kennington III * @param[in] path -path of the binary file which needs to be execeuted.
981bbe3d1eSWilliam A. Kennington III * @param[in] tArgs - arguments of the command.
991bbe3d1eSWilliam A. Kennington III */
1001bbe3d1eSWilliam A. Kennington III template <typename... ArgTypes>
execute(stdplus::zstring_view path,ArgTypes &&...tArgs)1018664252aSWilliam A. Kennington III void execute(stdplus::zstring_view path, ArgTypes&&... tArgs)
1021bbe3d1eSWilliam A. Kennington III {
1031bbe3d1eSWilliam A. Kennington III using expandType = char*[];
1041bbe3d1eSWilliam A. Kennington III
1051bbe3d1eSWilliam A. Kennington III expandType args = {const_cast<char*>(tArgs)..., nullptr};
1061bbe3d1eSWilliam A. Kennington III
1071bbe3d1eSWilliam A. Kennington III internal::executeCommandinChildProcess(path, args);
1081bbe3d1eSWilliam A. Kennington III }
1091bbe3d1eSWilliam A. Kennington III
1101bbe3d1eSWilliam A. Kennington III } // namespace network
1111bbe3d1eSWilliam A. Kennington III
1121bbe3d1eSWilliam A. Kennington III } // namespace phosphor
113