blob: 019311bac4b63c82f1b3e851a651c081b82eedd1 [file] [log] [blame]
Patrick Venture690a2342020-05-17 11:51:31 -07001#pragma once
2
John Wang8a7236a2021-01-04 15:31:44 +08003#include "app/channel.hpp"
4#include "user_channel/cipher_mgmt.hpp"
5
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05006#include <ipmid/api-types.hpp>
7#include <ipmid/api.hpp>
8#include <ipmid/message.hpp>
9#include <ipmid/message/types.hpp>
10#include <ipmid/types.hpp>
11#include <ipmid/utils.hpp>
12#include <phosphor-logging/elog-errors.hpp>
13#include <phosphor-logging/elog.hpp>
14#include <phosphor-logging/log.hpp>
15#include <sdbusplus/bus.hpp>
16#include <sdbusplus/exception.hpp>
William A. Kennington III726f2bd2023-06-21 01:11:40 -070017#include <stdplus/net/addr/ether.hpp>
18#include <stdplus/net/addr/ip.hpp>
19#include <stdplus/str/conv.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050020#include <user_channel/channel_layer.hpp>
21#include <xyz/openbmc_project/Common/error.hpp>
22#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
23#include <xyz/openbmc_project/Network/IP/server.hpp>
24#include <xyz/openbmc_project/Network/Neighbor/server.hpp>
25
John Wang8a7236a2021-01-04 15:31:44 +080026#include <cinttypes>
John Wang8a7236a2021-01-04 15:31:44 +080027#include <functional>
John Wang8a7236a2021-01-04 15:31:44 +080028#include <optional>
John Wang8a7236a2021-01-04 15:31:44 +080029#include <string>
30#include <string_view>
John Wang8a7236a2021-01-04 15:31:44 +080031#include <unordered_map>
32#include <unordered_set>
John Wang8a7236a2021-01-04 15:31:44 +080033#include <utility>
Patrick Venture690a2342020-05-17 11:51:31 -070034
35namespace ipmi
36{
37namespace transport
38{
39
John Wang8a7236a2021-01-04 15:31:44 +080040// D-Bus Network Daemon definitions
41constexpr auto PATH_ROOT = "/xyz/openbmc_project/network";
John Wang8a7236a2021-01-04 15:31:44 +080042constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface";
43constexpr auto INTF_IP = "xyz.openbmc_project.Network.IP";
44constexpr auto INTF_IP_CREATE = "xyz.openbmc_project.Network.IP.Create";
45constexpr auto INTF_MAC = "xyz.openbmc_project.Network.MACAddress";
46constexpr auto INTF_NEIGHBOR = "xyz.openbmc_project.Network.Neighbor";
47constexpr auto INTF_NEIGHBOR_CREATE_STATIC =
48 "xyz.openbmc_project.Network.Neighbor.CreateStatic";
49constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN";
50constexpr auto INTF_VLAN_CREATE = "xyz.openbmc_project.Network.VLAN.Create";
51
Patrick Venture690a2342020-05-17 11:51:31 -070052/** @brief IPMI LAN Parameters */
53enum class LanParam : uint8_t
54{
55 SetStatus = 0,
56 AuthSupport = 1,
57 AuthEnables = 2,
58 IP = 3,
59 IPSrc = 4,
60 MAC = 5,
61 SubnetMask = 6,
62 Gateway1 = 12,
63 Gateway1MAC = 13,
64 VLANId = 20,
65 CiphersuiteSupport = 22,
66 CiphersuiteEntries = 23,
67 cipherSuitePrivilegeLevels = 24,
68 IPFamilySupport = 50,
69 IPFamilyEnables = 51,
70 IPv6Status = 55,
71 IPv6StaticAddresses = 56,
72 IPv6DynamicAddresses = 59,
73 IPv6RouterControl = 64,
74 IPv6StaticRouter1IP = 65,
75 IPv6StaticRouter1MAC = 66,
76 IPv6StaticRouter1PrefixLength = 67,
77 IPv6StaticRouter1PrefixValue = 68,
78};
79
80/** @brief IPMI IP Origin Types */
81enum class IPSrc : uint8_t
82{
83 Unspecified = 0,
84 Static = 1,
85 DHCP = 2,
86 BIOS = 3,
87 BMC = 4,
88};
89
90/** @brief IPMI Set Status */
91enum class SetStatus : uint8_t
92{
93 Complete = 0,
94 InProgress = 1,
95 Commit = 2,
96};
97
98/** @brief IPMI Family Suport Bits */
99namespace IPFamilySupportFlag
100{
101constexpr uint8_t IPv6Only = 0;
102constexpr uint8_t DualStack = 1;
103constexpr uint8_t IPv6Alerts = 2;
104} // namespace IPFamilySupportFlag
105
106/** @brief IPMI IPFamily Enables Flag */
107enum class IPFamilyEnables : uint8_t
108{
109 IPv4Only = 0,
110 IPv6Only = 1,
111 DualStack = 2,
112};
113
114/** @brief IPMI IPv6 Dyanmic Status Bits */
115namespace IPv6StatusFlag
116{
117constexpr uint8_t DHCP = 0;
118constexpr uint8_t SLAAC = 1;
119}; // namespace IPv6StatusFlag
120
121/** @brief IPMI IPv6 Source */
122enum class IPv6Source : uint8_t
123{
124 Static = 0,
125 SLAAC = 1,
126 DHCP = 2,
127};
128
129/** @brief IPMI IPv6 Address Status */
130enum class IPv6AddressStatus : uint8_t
131{
132 Active = 0,
133 Disabled = 1,
134};
135
136namespace IPv6RouterControlFlag
137{
138constexpr uint8_t Static = 0;
139constexpr uint8_t Dynamic = 1;
140}; // namespace IPv6RouterControlFlag
141
142// LAN Handler specific response codes
143constexpr Cc ccParamNotSupported = 0x80;
144constexpr Cc ccParamSetLocked = 0x81;
145constexpr Cc ccParamReadOnly = 0x82;
146
147// VLANs are a 12-bit value
148constexpr uint16_t VLAN_VALUE_MASK = 0x0fff;
149constexpr uint16_t VLAN_ENABLE_FLAG = 0x8000;
150
151// Arbitrary v6 Address Limits to prevent too much output in ipmitool
152constexpr uint8_t MAX_IPV6_STATIC_ADDRESSES = 15;
153constexpr uint8_t MAX_IPV6_DYNAMIC_ADDRESSES = 15;
154
Jiaqing Zhao6d4a44e2022-01-24 15:04:00 +0800155// Prefix length limits of phosphor-networkd
Jiaqing Zhao6d4a44e2022-01-24 15:04:00 +0800156constexpr uint8_t MIN_IPV6_PREFIX_LENGTH = 1;
157constexpr uint8_t MAX_IPV6_PREFIX_LENGTH = 128;
158
John Wang8a7236a2021-01-04 15:31:44 +0800159/** @brief The dbus parameters for the interface corresponding to a channel
160 * This helps reduce the number of mapper lookups we need for each
161 * query and simplifies finding the VLAN interface if needed.
162 */
163struct ChannelParams
164{
165 /** @brief The channel ID */
166 int id;
167 /** @brief channel name for the interface */
168 std::string ifname;
169 /** @brief Name of the service on the bus */
170 std::string service;
171 /** @brief Lower level adapter path that is guaranteed to not be a VLAN */
172 std::string ifPath;
173 /** @brief Logical adapter path used for address assignment */
174 std::string logicalPath;
175};
176
John Wang8a7236a2021-01-04 15:31:44 +0800177/** @brief Determines the ethernet interface name corresponding to a channel
178 * Tries to map a VLAN object first so that the address information
179 * is accurate. Otherwise it gets the standard ethernet interface.
180 *
181 * @param[in] bus - The bus object used for lookups
182 * @param[in] channel - The channel id corresponding to an ethernet interface
183 * @return Ethernet interface service and object path if it exists
184 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500185std::optional<ChannelParams> maybeGetChannelParams(sdbusplus::bus_t& bus,
John Wang8a7236a2021-01-04 15:31:44 +0800186 uint8_t channel);
187
188/** @brief A trivial helper around maybeGetChannelParams() that throws an
189 * exception when it is unable to acquire parameters for the channel.
190 *
191 * @param[in] bus - The bus object used for lookups
192 * @param[in] channel - The channel id corresponding to an ethernet interface
193 * @return Ethernet interface service and object path
194 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500195ChannelParams getChannelParams(sdbusplus::bus_t& bus, uint8_t channel);
John Wang8a7236a2021-01-04 15:31:44 +0800196
197/** @brief Trivializes using parameter getter functions by providing a bus
198 * and channel parameters automatically.
199 *
200 * @param[in] channel - The channel id corresponding to an ethernet interface
201 * ...
202 */
203template <auto func, typename... Args>
204auto channelCall(uint8_t channel, Args&&... args)
205{
Patrick Williams5d82f472022-07-22 19:26:53 -0500206 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
John Wang8a7236a2021-01-04 15:31:44 +0800207 auto params = getChannelParams(bus, channel);
208 return std::invoke(func, bus, params, std::forward<Args>(args)...);
209}
210
211/** @brief Generic paramters for different address families */
212template <int family>
213struct AddrFamily
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500214{};
John Wang8a7236a2021-01-04 15:31:44 +0800215
216/** @brief Parameter specialization for IPv4 */
217template <>
218struct AddrFamily<AF_INET>
219{
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700220 using addr = stdplus::In4Addr;
John Wang8a7236a2021-01-04 15:31:44 +0800221 static constexpr auto protocol =
Willy Tu523e2d12023-09-05 11:36:48 -0700222 sdbusplus::server::xyz::openbmc_project::network::IP::Protocol::IPv4;
John Wang8a7236a2021-01-04 15:31:44 +0800223 static constexpr size_t maxStrLen = INET6_ADDRSTRLEN;
224 static constexpr uint8_t defaultPrefix = 32;
225 static constexpr char propertyGateway[] = "DefaultGateway";
226};
227
228/** @brief Parameter specialization for IPv6 */
229template <>
230struct AddrFamily<AF_INET6>
231{
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700232 using addr = stdplus::In6Addr;
John Wang8a7236a2021-01-04 15:31:44 +0800233 static constexpr auto protocol =
Willy Tu523e2d12023-09-05 11:36:48 -0700234 sdbusplus::server::xyz::openbmc_project::network::IP::Protocol::IPv6;
John Wang8a7236a2021-01-04 15:31:44 +0800235 static constexpr size_t maxStrLen = INET6_ADDRSTRLEN;
236 static constexpr uint8_t defaultPrefix = 128;
237 static constexpr char propertyGateway[] = "DefaultGateway6";
238};
239
240/** @brief Interface Neighbor configuration parameters */
241template <int family>
242struct IfNeigh
243{
244 std::string path;
245 typename AddrFamily<family>::addr ip;
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700246 stdplus::EtherAddr mac;
John Wang8a7236a2021-01-04 15:31:44 +0800247};
248
249/** @brief Interface IP Address configuration parameters */
250template <int family>
251struct IfAddr
252{
253 std::string path;
254 typename AddrFamily<family>::addr address;
Willy Tu523e2d12023-09-05 11:36:48 -0700255 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin origin;
John Wang8a7236a2021-01-04 15:31:44 +0800256 uint8_t prefix;
257};
258
259/** @brief Valid address origins for IPv6 */
260static inline const std::unordered_set<
Willy Tu523e2d12023-09-05 11:36:48 -0700261 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>
262 originsV6Static = {sdbusplus::server::xyz::openbmc_project::network::IP::
John Wang8a7236a2021-01-04 15:31:44 +0800263 AddressOrigin::Static};
264static inline const std::unordered_set<
Willy Tu523e2d12023-09-05 11:36:48 -0700265 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>
John Wang8a7236a2021-01-04 15:31:44 +0800266 originsV6Dynamic = {
Willy Tu523e2d12023-09-05 11:36:48 -0700267 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin::
John Wang8a7236a2021-01-04 15:31:44 +0800268 DHCP,
Willy Tu523e2d12023-09-05 11:36:48 -0700269 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin::
John Wang8a7236a2021-01-04 15:31:44 +0800270 SLAAC,
271};
272
273/** @brief A lazy lookup mechanism for iterating over object properties stored
274 * in DBus. This will only perform the object lookup when needed, and
275 * retains a cache of previous lookups to speed up future iterations.
276 */
277class ObjectLookupCache
278{
279 public:
280 using PropertiesCache = std::unordered_map<std::string, PropertyMap>;
281
282 /** @brief Creates a new ObjectLookupCache for the interface on the bus
283 * NOTE: The inputs to this object must outlive the object since
284 * they are only referenced by it.
285 *
286 * @param[in] bus - The bus object used for lookups
287 * @param[in] params - The parameters for the channel
288 * @param[in] intf - The interface we are looking up
289 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500290 ObjectLookupCache(sdbusplus::bus_t& bus, const ChannelParams& params,
John Wang8a7236a2021-01-04 15:31:44 +0800291 const char* intf) :
292 bus(bus),
293 params(params), intf(intf),
294 objs(getAllDbusObjects(bus, params.logicalPath, intf, ""))
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500295 {}
John Wang8a7236a2021-01-04 15:31:44 +0800296
297 class iterator : public ObjectTree::const_iterator
298 {
299 public:
300 using value_type = PropertiesCache::value_type;
301
302 iterator(ObjectTree::const_iterator it, ObjectLookupCache& container) :
303 ObjectTree::const_iterator(it), container(container),
304 ret(container.cache.end())
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500305 {}
John Wang8a7236a2021-01-04 15:31:44 +0800306 value_type& operator*()
307 {
308 ret = container.get(ObjectTree::const_iterator::operator*().first);
309 return *ret;
310 }
311 value_type* operator->()
312 {
313 return &operator*();
314 }
315
316 private:
317 ObjectLookupCache& container;
318 PropertiesCache::iterator ret;
319 };
320
321 iterator begin() noexcept
322 {
323 return iterator(objs.begin(), *this);
324 }
325
326 iterator end() noexcept
327 {
328 return iterator(objs.end(), *this);
329 }
330
331 private:
Patrick Williams5d82f472022-07-22 19:26:53 -0500332 sdbusplus::bus_t& bus;
John Wang8a7236a2021-01-04 15:31:44 +0800333 const ChannelParams& params;
334 const char* const intf;
335 const ObjectTree objs;
336 PropertiesCache cache;
337
338 /** @brief Gets a cached copy of the object properties if possible
339 * Otherwise performs a query on DBus to look them up
340 *
341 * @param[in] path - The object path to lookup
342 * @return An iterator for the specified object path + properties
343 */
344 PropertiesCache::iterator get(const std::string& path)
345 {
346 auto it = cache.find(path);
347 if (it != cache.end())
348 {
349 return it;
350 }
351 auto properties = getAllDbusProperties(bus, params.service, path, intf);
352 return cache.insert({path, std::move(properties)}).first;
353 }
354};
355
John Wang8a7236a2021-01-04 15:31:44 +0800356/** @brief Searches the ip object lookup cache for an address matching
357 * the input parameters. NOTE: The index lacks stability across address
358 * changes since the network daemon has no notion of stable indicies.
359 *
360 * @param[in] bus - The bus object used for lookups
361 * @param[in] params - The parameters for the channel
362 * @param[in] idx - The index of the desired address on the interface
363 * @param[in] origins - The allowed origins for the address objects
364 * @param[in] ips - The object lookup cache holding all of the address info
365 * @return The address and prefix if it was found
366 */
367template <int family>
368std::optional<IfAddr<family>> findIfAddr(
Patrick Williams5d82f472022-07-22 19:26:53 -0500369 [[maybe_unused]] sdbusplus::bus_t& bus,
Willy Tu11d68892022-01-20 10:37:34 -0800370 [[maybe_unused]] const ChannelParams& params, uint8_t idx,
John Wang8a7236a2021-01-04 15:31:44 +0800371 const std::unordered_set<
Willy Tu523e2d12023-09-05 11:36:48 -0700372 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>&
John Wang8a7236a2021-01-04 15:31:44 +0800373 origins,
374 ObjectLookupCache& ips)
375{
376 for (const auto& [path, properties] : ips)
377 {
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700378 std::optional<typename AddrFamily<family>::addr> addr;
379 try
380 {
381 addr.emplace(stdplus::fromStr<typename AddrFamily<family>::addr>(
382 std::get<std::string>(properties.at("Address"))));
383 }
384 catch (...)
John Wang8a7236a2021-01-04 15:31:44 +0800385 {
386 continue;
387 }
388
Willy Tu523e2d12023-09-05 11:36:48 -0700389 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin
390 origin = sdbusplus::server::xyz::openbmc_project::network::IP::
John Wang8a7236a2021-01-04 15:31:44 +0800391 convertAddressOriginFromString(
392 std::get<std::string>(properties.at("Origin")));
393 if (origins.find(origin) == origins.end())
394 {
395 continue;
396 }
397
398 if (idx > 0)
399 {
400 idx--;
401 continue;
402 }
403
404 IfAddr<family> ifaddr;
405 ifaddr.path = path;
406 ifaddr.address = *addr;
407 ifaddr.prefix = std::get<uint8_t>(properties.at("PrefixLength"));
408 ifaddr.origin = origin;
Willy Tu11d68892022-01-20 10:37:34 -0800409 return ifaddr;
John Wang8a7236a2021-01-04 15:31:44 +0800410 }
411
412 return std::nullopt;
413}
414/** @brief Trivial helper around findIfAddr that simplifies calls
415 * for one off lookups. Don't use this if you intend to do multiple
416 * lookups at a time.
417 *
418 * @param[in] bus - The bus object used for lookups
419 * @param[in] params - The parameters for the channel
420 * @param[in] idx - The index of the desired address on the interface
421 * @param[in] origins - The allowed origins for the address objects
422 * @return The address and prefix if it was found
423 */
424template <int family>
425auto getIfAddr(
Patrick Williams5d82f472022-07-22 19:26:53 -0500426 sdbusplus::bus_t& bus, const ChannelParams& params, uint8_t idx,
John Wang8a7236a2021-01-04 15:31:44 +0800427 const std::unordered_set<
Willy Tu523e2d12023-09-05 11:36:48 -0700428 sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>&
John Wang8a7236a2021-01-04 15:31:44 +0800429 origins)
430{
431 ObjectLookupCache ips(bus, params, INTF_IP);
432 return findIfAddr<family>(bus, params, idx, origins, ips);
433}
434
John Wang8a7236a2021-01-04 15:31:44 +0800435/** @brief Reconfigures the IPv6 address info configured for the interface
436 *
437 * @param[in] bus - The bus object used for lookups
438 * @param[in] params - The parameters for the channel
439 * @param[in] idx - The address index to operate on
440 * @param[in] address - The new address
441 * @param[in] prefix - The new address prefix
442 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500443void reconfigureIfAddr6(sdbusplus::bus_t& bus, const ChannelParams& params,
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700444 uint8_t idx, stdplus::In6Addr address, uint8_t prefix);
John Wang8a7236a2021-01-04 15:31:44 +0800445
446/** @brief Retrieves the current gateway for the address family on the system
Lei YUd1bd8c42021-08-11 17:13:56 +0800447 * NOTE: The gateway is per channel instead of the system wide one.
John Wang8a7236a2021-01-04 15:31:44 +0800448 *
449 * @param[in] bus - The bus object used for lookups
450 * @param[in] params - The parameters for the channel
451 * @return An address representing the gateway address if it exists
452 */
453template <int family>
454std::optional<typename AddrFamily<family>::addr>
Patrick Williams5d82f472022-07-22 19:26:53 -0500455 getGatewayProperty(sdbusplus::bus_t& bus, const ChannelParams& params)
John Wang8a7236a2021-01-04 15:31:44 +0800456{
Lei YUd1bd8c42021-08-11 17:13:56 +0800457 auto objPath = "/xyz/openbmc_project/network/" + params.ifname;
458 auto gatewayStr = std::get<std::string>(
459 getDbusProperty(bus, params.service, objPath, INTF_ETHERNET,
460 AddrFamily<family>::propertyGateway));
John Wang8a7236a2021-01-04 15:31:44 +0800461 if (gatewayStr.empty())
462 {
463 return std::nullopt;
464 }
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700465 return stdplus::fromStr<typename AddrFamily<family>::addr>(gatewayStr);
John Wang8a7236a2021-01-04 15:31:44 +0800466}
467
468template <int family>
469std::optional<IfNeigh<family>>
Patrick Williams5d82f472022-07-22 19:26:53 -0500470 findStaticNeighbor(sdbusplus::bus_t&, const ChannelParams&,
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700471 typename AddrFamily<family>::addr ip,
John Wang8a7236a2021-01-04 15:31:44 +0800472 ObjectLookupCache& neighbors)
473{
Willy Tu523e2d12023-09-05 11:36:48 -0700474 using sdbusplus::server::xyz::openbmc_project::network::Neighbor;
John Wang8a7236a2021-01-04 15:31:44 +0800475 const auto state =
Willy Tu523e2d12023-09-05 11:36:48 -0700476 sdbusplus::common::xyz::openbmc_project::network::convertForMessage(
John Wang8a7236a2021-01-04 15:31:44 +0800477 Neighbor::State::Permanent);
478 for (const auto& [path, neighbor] : neighbors)
479 {
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700480 std::optional<typename AddrFamily<family>::addr> neighIP;
481 try
482 {
483 neighIP.emplace(stdplus::fromStr<typename AddrFamily<family>::addr>(
484 std::get<std::string>(neighbor.at("IPAddress"))));
485 }
486 catch (...)
John Wang8a7236a2021-01-04 15:31:44 +0800487 {
488 continue;
489 }
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700490 if (*neighIP != ip)
John Wang8a7236a2021-01-04 15:31:44 +0800491 {
492 continue;
493 }
494 if (state != std::get<std::string>(neighbor.at("State")))
495 {
496 continue;
497 }
498
499 IfNeigh<family> ret;
500 ret.path = path;
501 ret.ip = ip;
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700502 ret.mac = stdplus::fromStr<stdplus::EtherAddr>(
503 std::get<std::string>(neighbor.at("MACAddress")));
Willy Tu11d68892022-01-20 10:37:34 -0800504 return ret;
John Wang8a7236a2021-01-04 15:31:44 +0800505 }
506
507 return std::nullopt;
508}
509
510template <int family>
Patrick Williams5d82f472022-07-22 19:26:53 -0500511void createNeighbor(sdbusplus::bus_t& bus, const ChannelParams& params,
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700512 typename AddrFamily<family>::addr address,
513 stdplus::EtherAddr mac)
John Wang8a7236a2021-01-04 15:31:44 +0800514{
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500515 auto newreq = bus.new_method_call(params.service.c_str(),
516 params.logicalPath.c_str(),
517 INTF_NEIGHBOR_CREATE_STATIC, "Neighbor");
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700518 stdplus::ToStrHandle<stdplus::ToStr<stdplus::EtherAddr>> macToStr;
519 stdplus::ToStrHandle<stdplus::ToStr<typename AddrFamily<family>::addr>>
520 addrToStr;
521 newreq.append(addrToStr(address), macToStr(mac));
John Wang8a7236a2021-01-04 15:31:44 +0800522 bus.call_noreply(newreq);
523}
524
525/** @brief Deletes the dbus object. Ignores empty objects or objects that are
526 * missing from the bus.
527 *
528 * @param[in] bus - The bus object used for lookups
529 * @param[in] service - The name of the service
530 * @param[in] path - The path of the object to delete
531 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500532void deleteObjectIfExists(sdbusplus::bus_t& bus, const std::string& service,
John Wang8a7236a2021-01-04 15:31:44 +0800533 const std::string& path);
534
Lei YUd1bd8c42021-08-11 17:13:56 +0800535/** @brief Sets the value for the default gateway of the channel
John Wang8a7236a2021-01-04 15:31:44 +0800536 *
537 * @param[in] bus - The bus object used for lookups
538 * @param[in] params - The parameters for the channel
539 * @param[in] gateway - Gateway address to apply
540 */
541template <int family>
Patrick Williams5d82f472022-07-22 19:26:53 -0500542void setGatewayProperty(sdbusplus::bus_t& bus, const ChannelParams& params,
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700543 typename AddrFamily<family>::addr address)
John Wang8a7236a2021-01-04 15:31:44 +0800544{
545 // Save the old gateway MAC address if it exists so we can recreate it
546 auto gateway = getGatewayProperty<family>(bus, params);
547 std::optional<IfNeigh<family>> neighbor;
548 if (gateway)
549 {
550 ObjectLookupCache neighbors(bus, params, INTF_NEIGHBOR);
551 neighbor = findStaticNeighbor<family>(bus, params, *gateway, neighbors);
552 }
553
Lei YUd1bd8c42021-08-11 17:13:56 +0800554 auto objPath = "/xyz/openbmc_project/network/" + params.ifname;
555 setDbusProperty(bus, params.service, objPath, INTF_ETHERNET,
John Wang8a7236a2021-01-04 15:31:44 +0800556 AddrFamily<family>::propertyGateway,
William A. Kennington III726f2bd2023-06-21 01:11:40 -0700557 stdplus::toStr(address));
John Wang8a7236a2021-01-04 15:31:44 +0800558
559 // Restore the gateway MAC if we had one
560 if (neighbor)
561 {
562 deleteObjectIfExists(bus, params.service, neighbor->path);
563 createNeighbor<family>(bus, params, address, neighbor->mac);
564 }
565}
566
Jian Zhang23f44652022-03-17 17:13:10 +0800567/** @enum SolConfParam
568 *
569 * using for Set/Get SOL configuration parameters command.
570 */
571enum class SolConfParam : uint8_t
572{
573 Progress, //!< Set In Progress.
574 Enable, //!< SOL Enable.
575 Authentication, //!< SOL Authentication.
576 Accumulate, //!< Character Accumulate Interval & Send Threshold.
577 Retry, //!< SOL Retry.
578 NonVbitrate, //!< SOL non-volatile bit rate.
579 Vbitrate, //!< SOL volatile bit rate.
580 Channel, //!< SOL payload channel.
581 Port, //!< SOL payload port.
582};
583
584constexpr uint8_t ipmiCCParamNotSupported = 0x80;
585constexpr uint8_t ipmiCCWriteReadParameter = 0x82;
586
Patrick Venture690a2342020-05-17 11:51:31 -0700587} // namespace transport
588} // namespace ipmi