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