blob: ee87d6cc00c72d17a273841827aa897b032e3e09 [file] [log] [blame]
Gunnar Mills57d9c502018-09-14 14:42:34 -05001#include "config.h"
2
Ratan Gupta2eff84f2017-04-20 19:19:15 +05303#include "ipaddress.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07004
Ratan Gupta2eff84f2017-04-20 19:19:15 +05305#include "ethernet_interface.hpp"
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05006#include "util.hpp"
Ratan Gupta2eff84f2017-04-20 19:19:15 +05307
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05008#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07009#include <phosphor-logging/log.hpp>
10#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta2eff84f2017-04-20 19:19:15 +053011namespace phosphor
12{
13namespace network
14{
15
16using namespace phosphor::logging;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050017using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050018using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
19using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
Ratan Gupta2eff84f2017-04-20 19:19:15 +053020
Patrick Williamsc38b0712022-07-22 19:26:54 -050021IPAddress::IPAddress(sdbusplus::bus_t& bus, const char* objPath,
Gunnar Mills57d9c502018-09-14 14:42:34 -050022 EthernetInterface& parent, IP::Protocol type,
23 const std::string& ipaddress, IP::AddressOrigin origin,
24 uint8_t prefixLength, const std::string& gateway) :
Patrick Williams166b9592022-03-30 16:09:16 -050025 IPIfaces(bus, objPath, IPIfaces::action::defer_emit),
Gunnar Mills57d9c502018-09-14 14:42:34 -050026 parent(parent)
Ratan Gupta2eff84f2017-04-20 19:19:15 +053027{
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050028
29 IP::address(ipaddress);
30 IP::prefixLength(prefixLength);
31 IP::gateway(gateway);
32 IP::type(type);
33 IP::origin(origin);
Ratan Gupta29b0e432017-05-25 12:51:40 +053034
Gunnar Mills57d9c502018-09-14 14:42:34 -050035 // Emit deferred signal.
36 emit_object_added();
Ratan Gupta2eff84f2017-04-20 19:19:15 +053037}
Manojkiran Edaaa57fa52020-06-13 14:59:53 +053038std::string IPAddress::address(std::string /*ipAddress*/)
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050039{
40 elog<NotAllowed>(Reason("Property update is not allowed"));
41}
Manojkiran Edaaa57fa52020-06-13 14:59:53 +053042uint8_t IPAddress::prefixLength(uint8_t /*value*/)
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050043{
44 elog<NotAllowed>(Reason("Property update is not allowed"));
45}
Manojkiran Edaaa57fa52020-06-13 14:59:53 +053046std::string IPAddress::gateway(std::string /*gateway*/)
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050047{
48 elog<NotAllowed>(Reason("Property update is not allowed"));
49}
Manojkiran Edaaa57fa52020-06-13 14:59:53 +053050IP::Protocol IPAddress::type(IP::Protocol /*type*/)
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050051{
52 elog<NotAllowed>(Reason("Property update is not allowed"));
53}
Manojkiran Edaaa57fa52020-06-13 14:59:53 +053054IP::AddressOrigin IPAddress::origin(IP::AddressOrigin /*origin*/)
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050055{
56 elog<NotAllowed>(Reason("Property update is not allowed"));
57}
Ratan Gupta2eff84f2017-04-20 19:19:15 +053058void IPAddress::delete_()
59{
William A. Kennington III2dae9692019-04-22 02:18:41 -070060 if (origin() != IP::AddressOrigin::Static)
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050061 {
William A. Kennington III2dae9692019-04-22 02:18:41 -070062 log<level::ERR>("Tried to delete a non-static address"),
63 entry("ADDRESS=%s", address().c_str()),
64 entry("PREFIX=%" PRIu8, prefixLength()),
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050065 entry("INTERFACE=%s", parent.interfaceName().c_str());
William A. Kennington III2dae9692019-04-22 02:18:41 -070066 elog<InternalFailure>();
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050067 }
68
Ratan Gupta2eff84f2017-04-20 19:19:15 +053069 parent.deleteObject(address());
70}
71
Gunnar Mills57d9c502018-09-14 14:42:34 -050072} // namespace network
73} // namespace phosphor