1*ab27a819SRavi Teja #include "static_gateway.hpp"
2*ab27a819SRavi Teja
3*ab27a819SRavi Teja #include "ethernet_interface.hpp"
4*ab27a819SRavi Teja #include "network_manager.hpp"
5*ab27a819SRavi Teja
6*ab27a819SRavi Teja #include <phosphor-logging/elog-errors.hpp>
7*ab27a819SRavi Teja #include <phosphor-logging/elog.hpp>
8*ab27a819SRavi Teja #include <xyz/openbmc_project/Common/error.hpp>
9*ab27a819SRavi Teja
10*ab27a819SRavi Teja #include <string>
11*ab27a819SRavi Teja
12*ab27a819SRavi Teja namespace phosphor
13*ab27a819SRavi Teja {
14*ab27a819SRavi Teja namespace network
15*ab27a819SRavi Teja {
16*ab27a819SRavi Teja
makeObjPath(std::string_view root,std::string addr)17*ab27a819SRavi Teja static auto makeObjPath(std::string_view root, std::string addr)
18*ab27a819SRavi Teja {
19*ab27a819SRavi Teja auto ret = sdbusplus::message::object_path(std::string(root));
20*ab27a819SRavi Teja ret /= addr;
21*ab27a819SRavi Teja return ret;
22*ab27a819SRavi Teja }
23*ab27a819SRavi Teja
StaticGateway(sdbusplus::bus_t & bus,std::string_view objRoot,stdplus::PinnedRef<EthernetInterface> parent,std::string gateway,IP::Protocol protocolType)24*ab27a819SRavi Teja StaticGateway::StaticGateway(sdbusplus::bus_t& bus, std::string_view objRoot,
25*ab27a819SRavi Teja stdplus::PinnedRef<EthernetInterface> parent,
26*ab27a819SRavi Teja std::string gateway, IP::Protocol protocolType) :
27*ab27a819SRavi Teja StaticGateway(bus, makeObjPath(objRoot, gateway), parent, gateway,
28*ab27a819SRavi Teja protocolType)
29*ab27a819SRavi Teja {}
30*ab27a819SRavi Teja
StaticGateway(sdbusplus::bus_t & bus,sdbusplus::message::object_path objPath,stdplus::PinnedRef<EthernetInterface> parent,std::string gateway,IP::Protocol protocolType)31*ab27a819SRavi Teja StaticGateway::StaticGateway(sdbusplus::bus_t& bus,
32*ab27a819SRavi Teja sdbusplus::message::object_path objPath,
33*ab27a819SRavi Teja stdplus::PinnedRef<EthernetInterface> parent,
34*ab27a819SRavi Teja std::string gateway, IP::Protocol protocolType) :
35*ab27a819SRavi Teja StaticGatewayObj(bus, objPath.str.c_str(),
36*ab27a819SRavi Teja StaticGatewayObj::action::defer_emit),
37*ab27a819SRavi Teja parent(parent), objPath(std::move(objPath))
38*ab27a819SRavi Teja {
39*ab27a819SRavi Teja StaticGatewayObj::gateway(gateway, true);
40*ab27a819SRavi Teja StaticGatewayObj::protocolType(protocolType, true);
41*ab27a819SRavi Teja emit_object_added();
42*ab27a819SRavi Teja }
43*ab27a819SRavi Teja
delete_()44*ab27a819SRavi Teja void StaticGateway::delete_()
45*ab27a819SRavi Teja {
46*ab27a819SRavi Teja auto& staticGateways = parent.get().staticGateways;
47*ab27a819SRavi Teja std::unique_ptr<StaticGateway> ptr;
48*ab27a819SRavi Teja for (auto it = staticGateways.begin(); it != staticGateways.end(); ++it)
49*ab27a819SRavi Teja {
50*ab27a819SRavi Teja if (it->second.get() == this)
51*ab27a819SRavi Teja {
52*ab27a819SRavi Teja ptr = std::move(it->second);
53*ab27a819SRavi Teja staticGateways.erase(it);
54*ab27a819SRavi Teja break;
55*ab27a819SRavi Teja }
56*ab27a819SRavi Teja }
57*ab27a819SRavi Teja
58*ab27a819SRavi Teja parent.get().writeConfigurationFile();
59*ab27a819SRavi Teja parent.get().manager.get().reloadConfigs();
60*ab27a819SRavi Teja }
61*ab27a819SRavi Teja
62*ab27a819SRavi Teja using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
63*ab27a819SRavi Teja using REASON =
64*ab27a819SRavi Teja phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
65*ab27a819SRavi Teja using phosphor::logging::elog;
66*ab27a819SRavi Teja
gateway(std::string)67*ab27a819SRavi Teja std::string StaticGateway::gateway(std::string /*gateway*/)
68*ab27a819SRavi Teja {
69*ab27a819SRavi Teja elog<NotAllowed>(REASON("Property update is not allowed"));
70*ab27a819SRavi Teja }
71*ab27a819SRavi Teja
protocolType(IP::Protocol)72*ab27a819SRavi Teja IP::Protocol StaticGateway::protocolType(IP::Protocol /*protocolType*/)
73*ab27a819SRavi Teja {
74*ab27a819SRavi Teja elog<NotAllowed>(REASON("Property update is not allowed"));
75*ab27a819SRavi Teja }
76*ab27a819SRavi Teja } // namespace network
77*ab27a819SRavi Teja } // namespace phosphor
78