blob: 4daccd5961fc4252fa46d621835b59d3b717e528 [file] [log] [blame]
Ratan Gupta2eff84f2017-04-20 19:19:15 +05301#include "ipaddress.hpp"
2#include "ethernet_interface.hpp"
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05003#include "util.hpp"
Ratan Gupta2eff84f2017-04-20 19:19:15 +05304
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05005#include "xyz/openbmc_project/Common/error.hpp"
Ratan Gupta2eff84f2017-04-20 19:19:15 +05306#include <phosphor-logging/log.hpp>
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05007#include <phosphor-logging/elog-errors.hpp>
Ratan Gupta2eff84f2017-04-20 19:19:15 +05308
9namespace phosphor
10{
11namespace network
12{
13
14using namespace phosphor::logging;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050015using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Gupta2eff84f2017-04-20 19:19:15 +053016
17IPAddress::IPAddress(sdbusplus::bus::bus& bus,
18 const char* objPath,
19 EthernetInterface& parent,
20 IP::Protocol type,
21 const std::string& ipaddress,
Ratan Gupta29b0e432017-05-25 12:51:40 +053022 IP::AddressOrigin origin,
Ratan Gupta2eff84f2017-04-20 19:19:15 +053023 uint8_t prefixLength,
24 const std::string& gateway):
25 IPIfaces(bus, objPath, true),
26 parent(parent)
27{
28 this->address(ipaddress);
29 this->prefixLength(prefixLength);
30 this->gateway(gateway);
31 this->type(type);
Ratan Gupta29b0e432017-05-25 12:51:40 +053032 this->origin(origin);
33
Ratan Gupta2eff84f2017-04-20 19:19:15 +053034 // Emit deferred signal.
35 emit_object_added();
36}
37
38
39void IPAddress::delete_()
40{
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050041 if (parent.dHCPEnabled())
42 {
43 log<level::ERR>("DHCP enabled on the interface"),
44 entry("INTERFACE=%s", parent.interfaceName().c_str());
45 elog<InternalFailure>();
46 }
47
48 if (isLinkLocalIP(address()))
49 {
50 log<level::ERR>("Can not delete the LinkLocal address"),
51 entry("INTERFACE=%s ADDRESS=%s",
52 parent.interfaceName().c_str(), address().c_str());
53 elog<InternalFailure>();
54 }
55
Ratan Gupta2eff84f2017-04-20 19:19:15 +053056 parent.deleteObject(address());
57}
58
59}//namespace network
60}//namespace phosphor