1 #include "config.h"
2 
3 #include "ipaddress.hpp"
4 
5 #include "ethernet_interface.hpp"
6 #include "util.hpp"
7 
8 #include <phosphor-logging/elog-errors.hpp>
9 #include <phosphor-logging/log.hpp>
10 #include <xyz/openbmc_project/Common/error.hpp>
11 namespace phosphor
12 {
13 namespace network
14 {
15 
16 using namespace phosphor::logging;
17 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
18 using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
19 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
20 
21 IPAddress::IPAddress(sdbusplus::bus_t& 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, IPIfaces::action::defer_emit),
26     parent(parent)
27 {
28 
29     IP::address(ipaddress);
30     IP::prefixLength(prefixLength);
31     IP::gateway(gateway);
32     IP::type(type);
33     IP::origin(origin);
34 
35     // Emit deferred signal.
36     emit_object_added();
37 }
38 std::string IPAddress::address(std::string /*ipAddress*/)
39 {
40     elog<NotAllowed>(Reason("Property update is not allowed"));
41 }
42 uint8_t IPAddress::prefixLength(uint8_t /*value*/)
43 {
44     elog<NotAllowed>(Reason("Property update is not allowed"));
45 }
46 std::string IPAddress::gateway(std::string /*gateway*/)
47 {
48     elog<NotAllowed>(Reason("Property update is not allowed"));
49 }
50 IP::Protocol IPAddress::type(IP::Protocol /*type*/)
51 {
52     elog<NotAllowed>(Reason("Property update is not allowed"));
53 }
54 IP::AddressOrigin IPAddress::origin(IP::AddressOrigin /*origin*/)
55 {
56     elog<NotAllowed>(Reason("Property update is not allowed"));
57 }
58 void IPAddress::delete_()
59 {
60     if (origin() != IP::AddressOrigin::Static)
61     {
62         log<level::ERR>("Tried to delete a non-static address"),
63             entry("ADDRESS=%s", address().c_str()),
64             entry("PREFIX=%" PRIu8, prefixLength()),
65             entry("INTERFACE=%s", parent.interfaceName().c_str());
66         elog<InternalFailure>();
67     }
68 
69     parent.deleteObject(address());
70 }
71 
72 } // namespace network
73 } // namespace phosphor
74