blob: 869312319c75cb771cf2f65bb334da9cf2f7cce8 [file] [log] [blame]
Ratan Gupta2eff84f2017-04-20 19:19:15 +05301#include "ipaddress.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07002
3#include "config.h"
Ratan Gupta2eff84f2017-04-20 19:19:15 +05304#include "ethernet_interface.hpp"
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05005#include "util.hpp"
Ratan Gupta2eff84f2017-04-20 19:19:15 +05306
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -05007#include <phosphor-logging/elog-errors.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -07008#include <phosphor-logging/log.hpp>
9#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta2eff84f2017-04-20 19:19:15 +053010
11namespace 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;
Ratan Gupta2eff84f2017-04-20 19:19:15 +053018
19IPAddress::IPAddress(sdbusplus::bus::bus& bus,
20 const char* objPath,
21 EthernetInterface& parent,
22 IP::Protocol type,
23 const std::string& ipaddress,
Ratan Gupta29b0e432017-05-25 12:51:40 +053024 IP::AddressOrigin origin,
Ratan Gupta2eff84f2017-04-20 19:19:15 +053025 uint8_t prefixLength,
26 const std::string& gateway):
27 IPIfaces(bus, objPath, true),
28 parent(parent)
29{
30 this->address(ipaddress);
31 this->prefixLength(prefixLength);
32 this->gateway(gateway);
33 this->type(type);
Ratan Gupta29b0e432017-05-25 12:51:40 +053034 this->origin(origin);
35
Ratan Gupta2eff84f2017-04-20 19:19:15 +053036 // Emit deferred signal.
37 emit_object_added();
38}
39
40
41void IPAddress::delete_()
42{
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050043 if (parent.dHCPEnabled())
44 {
45 log<level::ERR>("DHCP enabled on the interface"),
46 entry("INTERFACE=%s", parent.interfaceName().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053047 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050048 }
49
Oskar Senftad21fc22018-07-26 16:32:23 -040050#ifdef LINK_LOCAL_AUTOCONFIGURATION
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050051 if (isLinkLocalIP(address()))
52 {
53 log<level::ERR>("Can not delete the LinkLocal address"),
54 entry("INTERFACE=%s ADDRESS=%s",
55 parent.interfaceName().c_str(), address().c_str());
Ratan Gupta20037432017-11-08 16:35:22 +053056 return;
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050057 }
Oskar Senftad21fc22018-07-26 16:32:23 -040058#endif
Nagaraju Goruganti66b974d2017-10-03 08:43:08 -050059
Ratan Gupta2eff84f2017-04-20 19:19:15 +053060 parent.deleteObject(address());
61}
62
63}//namespace network
64}//namespace phosphor