blob: 43433e292aa423c32c8309a19cd0ea3b35bdab61 [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 +053011
12namespace phosphor
13{
14namespace network
15{
16
17using namespace phosphor::logging;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050018using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Gupta2eff84f2017-04-20 19:19:15 +053019
Gunnar Mills57d9c502018-09-14 14:42:34 -050020IPAddress::IPAddress(sdbusplus::bus::bus& bus, const char* objPath,
21 EthernetInterface& parent, IP::Protocol type,
22 const std::string& ipaddress, IP::AddressOrigin origin,
23 uint8_t prefixLength, const std::string& gateway) :
24 IPIfaces(bus, objPath, true),
25 parent(parent)
Ratan Gupta2eff84f2017-04-20 19:19:15 +053026{
Gunnar Mills57d9c502018-09-14 14:42:34 -050027 this->address(ipaddress);
28 this->prefixLength(prefixLength);
29 this->gateway(gateway);
30 this->type(type);
31 this->origin(origin);
Ratan Gupta29b0e432017-05-25 12:51:40 +053032
Gunnar Mills57d9c502018-09-14 14:42:34 -050033 // Emit deferred signal.
34 emit_object_added();
Ratan Gupta2eff84f2017-04-20 19:19:15 +053035}
36
Ratan Gupta2eff84f2017-04-20 19:19:15 +053037void IPAddress::delete_()
38{
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050039 if (parent.dHCPEnabled())
40 {
41 log<level::ERR>("DHCP enabled on the interface"),
42 entry("INTERFACE=%s", parent.interfaceName().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053043 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050044 }
45
Oskar Senftad21fc22018-07-26 16:32:23 -040046#ifdef LINK_LOCAL_AUTOCONFIGURATION
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050047 if (isLinkLocalIP(address()))
48 {
49 log<level::ERR>("Can not delete the LinkLocal address"),
Gunnar Mills57d9c502018-09-14 14:42:34 -050050 entry("INTERFACE=%s ADDRESS=%s", parent.interfaceName().c_str(),
51 address().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053052 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050053 }
Oskar Senftad21fc22018-07-26 16:32:23 -040054#endif
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050055
Ratan Gupta2eff84f2017-04-20 19:19:15 +053056 parent.deleteObject(address());
57}
58
Gunnar Mills57d9c502018-09-14 14:42:34 -050059} // namespace network
60} // namespace phosphor