util.hpp (95530ec9fbfd478f85b1452571b9df21c76ec242) util.hpp (69f4554be96691ee3a9e2fb334af0fb5a33c43f4)
1#pragma once
2#include "config_parser.hpp"
3#include "types.hpp"
4
5#include <netinet/ether.h>
6#include <unistd.h>
7
8#include <cstring>
9#include <filesystem>
10#include <optional>
11#include <sdbusplus/bus.hpp>
1#pragma once
2#include "config_parser.hpp"
3#include "types.hpp"
4
5#include <netinet/ether.h>
6#include <unistd.h>
7
8#include <cstring>
9#include <filesystem>
10#include <optional>
11#include <sdbusplus/bus.hpp>
12#include <stdplus/zstring.hpp>
13#include <stdplus/zstring_view.hpp>
12#include <string>
13#include <string_view>
14#include <unordered_set>
15#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
16
17namespace phosphor
18{
19namespace network

--- 15 unchanged lines hidden (view full) ---

35 */
36ether_addr getfromInventory(sdbusplus::bus_t& bus, const std::string& intfName);
37
38/** @brief Converts the given mac address into byte form
39 * @param[in] str - The mac address in human readable form
40 * @returns A mac address in network byte order
41 * @throws std::runtime_error for bad mac
42 */
14#include <string>
15#include <string_view>
16#include <unordered_set>
17#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
18
19namespace phosphor
20{
21namespace network

--- 15 unchanged lines hidden (view full) ---

37 */
38ether_addr getfromInventory(sdbusplus::bus_t& bus, const std::string& intfName);
39
40/** @brief Converts the given mac address into byte form
41 * @param[in] str - The mac address in human readable form
42 * @returns A mac address in network byte order
43 * @throws std::runtime_error for bad mac
44 */
43ether_addr fromString(const char* str);
44inline ether_addr fromString(const std::string& str)
45{
46 return fromString(str.c_str());
47}
45ether_addr fromString(stdplus::zstring_view str);
48
49/** @brief Converts the given mac address bytes into a string
50 * @param[in] mac - The mac address
51 * @returns A valid mac address string
52 */
53std::string toString(const ether_addr& mac);
54
55/** @brief Determines if the mac address is empty

--- 34 unchanged lines hidden (view full) ---

90std::string toString(const struct in_addr& addr);
91std::string toString(const struct in6_addr& addr);
92
93/* @brief checks that the given ip address valid or not.
94 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
95 * @param[in] address - IP address.
96 * @returns true if it is valid otherwise false.
97 */
46
47/** @brief Converts the given mac address bytes into a string
48 * @param[in] mac - The mac address
49 * @returns A valid mac address string
50 */
51std::string toString(const ether_addr& mac);
52
53/** @brief Determines if the mac address is empty

--- 34 unchanged lines hidden (view full) ---

88std::string toString(const struct in_addr& addr);
89std::string toString(const struct in6_addr& addr);
90
91/* @brief checks that the given ip address valid or not.
92 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
93 * @param[in] address - IP address.
94 * @returns true if it is valid otherwise false.
95 */
98bool isValidIP(int addressFamily, const std::string& address);
96bool isValidIP(int addressFamily, stdplus::const_zstring address);
99
100/* @brief checks that the given prefix is valid or not.
101 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
102 * @param[in] prefix - prefix length.
103 * @returns true if it is valid otherwise false.
104 */
105bool isValidPrefix(int addressFamily, uint8_t prefixLength);
106
107/** @brief Get all the interfaces from the system.
108 * @returns list of interface names.
109 */
110InterfaceList getInterfaces();
111
112/** @brief Delete the given interface.
113 * @param[in] intf - interface name.
114 */
97
98/* @brief checks that the given prefix is valid or not.
99 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
100 * @param[in] prefix - prefix length.
101 * @returns true if it is valid otherwise false.
102 */
103bool isValidPrefix(int addressFamily, uint8_t prefixLength);
104
105/** @brief Get all the interfaces from the system.
106 * @returns list of interface names.
107 */
108InterfaceList getInterfaces();
109
110/** @brief Delete the given interface.
111 * @param[in] intf - interface name.
112 */
115void deleteInterface(const std::string& intf);
113void deleteInterface(stdplus::const_zstring intf);
116
117/** @brief Converts the interface name into a u-boot environment
118 * variable that would hold its ethernet address.
119 *
120 * @param[in] intf - interface name
121 * @return The name of th environment key
122 */
114
115/** @brief Converts the interface name into a u-boot environment
116 * variable that would hold its ethernet address.
117 *
118 * @param[in] intf - interface name
119 * @return The name of th environment key
120 */
123std::optional<std::string> interfaceToUbootEthAddr(const char* intf);
121std::optional<std::string> interfaceToUbootEthAddr(std::string_view intf);
124
125/** @brief read the IPv6AcceptRA value from the configuration file
126 * @param[in] config - The parsed configuration.
127 */
128bool getIPv6AcceptRA(const config::Parser& config);
129
130/** @brief read the DHCP value from the configuration file
131 * @param[in] config - The parsed configuration.

--- 12 unchanged lines hidden (view full) ---

144
145namespace internal
146{
147
148/* @brief runs the given command in child process.
149 * @param[in] path - path of the binary file which needs to be execeuted.
150 * @param[in] args - arguments of the command.
151 */
122
123/** @brief read the IPv6AcceptRA value from the configuration file
124 * @param[in] config - The parsed configuration.
125 */
126bool getIPv6AcceptRA(const config::Parser& config);
127
128/** @brief read the DHCP value from the configuration file
129 * @param[in] config - The parsed configuration.

--- 12 unchanged lines hidden (view full) ---

142
143namespace internal
144{
145
146/* @brief runs the given command in child process.
147 * @param[in] path - path of the binary file which needs to be execeuted.
148 * @param[in] args - arguments of the command.
149 */
152void executeCommandinChildProcess(const char* path, char** args);
150void executeCommandinChildProcess(stdplus::const_zstring path, char** args);
153
154/** @brief Get ignored interfaces from environment */
155std::string_view getIgnoredInterfacesEnv();
156
157/** @brief Parse the comma separated interface names */
158std::unordered_set<std::string_view>
159 parseInterfaces(std::string_view interfaces);
160
161/** @brief Get the ignored interfaces */
162const std::unordered_set<std::string_view>& getIgnoredInterfaces();
163
164} // namespace internal
165
166/* @brief runs the given command in child process.
167 * @param[in] path -path of the binary file which needs to be execeuted.
168 * @param[in] tArgs - arguments of the command.
169 */
170template <typename... ArgTypes>
151
152/** @brief Get ignored interfaces from environment */
153std::string_view getIgnoredInterfacesEnv();
154
155/** @brief Parse the comma separated interface names */
156std::unordered_set<std::string_view>
157 parseInterfaces(std::string_view interfaces);
158
159/** @brief Get the ignored interfaces */
160const std::unordered_set<std::string_view>& getIgnoredInterfaces();
161
162} // namespace internal
163
164/* @brief runs the given command in child process.
165 * @param[in] path -path of the binary file which needs to be execeuted.
166 * @param[in] tArgs - arguments of the command.
167 */
168template <typename... ArgTypes>
171void execute(const char* path, ArgTypes&&... tArgs)
169void execute(stdplus::const_zstring path, ArgTypes&&... tArgs)
172{
173 using expandType = char*[];
174
175 expandType args = {const_cast<char*>(tArgs)..., nullptr};
176
177 internal::executeCommandinChildProcess(path, args);
178}
179
180} // namespace network
181
182} // namespace phosphor
170{
171 using expandType = char*[];
172
173 expandType args = {const_cast<char*>(tArgs)..., nullptr};
174
175 internal::executeCommandinChildProcess(path, args);
176}
177
178} // namespace network
179
180} // namespace phosphor