blob: f9839750af75da5d780dc54ff86c30b9031bb05c [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
Gunnar Mills57d9c502018-09-14 14:42:34 -050021IPAddress::IPAddress(sdbusplus::bus::bus& bus, const char* objPath,
22 EthernetInterface& parent, IP::Protocol type,
23 const std::string& ipaddress, IP::AddressOrigin origin,
24 uint8_t prefixLength, const std::string& gateway) :
25 IPIfaces(bus, objPath, true),
26 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}
Ravi Teja2fd2f7d2019-06-06 03:27:55 -050038std::string IPAddress::address(std::string ipAddress)
39{
40 elog<NotAllowed>(Reason("Property update is not allowed"));
41}
42uint8_t IPAddress::prefixLength(uint8_t value)
43{
44 elog<NotAllowed>(Reason("Property update is not allowed"));
45}
46std::string IPAddress::gateway(std::string gateway)
47{
48 elog<NotAllowed>(Reason("Property update is not allowed"));
49}
50IP::Protocol IPAddress::type(IP::Protocol type)
51{
52 elog<NotAllowed>(Reason("Property update is not allowed"));
53}
54IP::AddressOrigin IPAddress::origin(IP::AddressOrigin origin)
55{
56 elog<NotAllowed>(Reason("Property update is not allowed"));
57}
Ratan Gupta2eff84f2017-04-20 19:19:15 +053058void IPAddress::delete_()
59{
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050060 if (parent.dHCPEnabled())
61 {
62 log<level::ERR>("DHCP enabled on the interface"),
63 entry("INTERFACE=%s", parent.interfaceName().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053064 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050065 }
66
Oskar Senftad21fc22018-07-26 16:32:23 -040067#ifdef LINK_LOCAL_AUTOCONFIGURATION
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050068 if (isLinkLocalIP(address()))
69 {
70 log<level::ERR>("Can not delete the LinkLocal address"),
Gunnar Mills57d9c502018-09-14 14:42:34 -050071 entry("INTERFACE=%s ADDRESS=%s", parent.interfaceName().c_str(),
72 address().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053073 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050074 }
Oskar Senftad21fc22018-07-26 16:32:23 -040075#endif
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050076
Ratan Gupta2eff84f2017-04-20 19:19:15 +053077 parent.deleteObject(address());
78}
79
Gunnar Mills57d9c502018-09-14 14:42:34 -050080} // namespace network
81} // namespace phosphor