blob: f1e9db4b40296f341b36ec06e60b3c78a47b8523 [file] [log] [blame]
Ravi Tejaab27a812023-05-02 10:01:53 -05001#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
12namespace phosphor
13{
14namespace network
15{
16
17static 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
24StaticGateway::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
31StaticGateway::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
44void 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
62using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
63using REASON =
64 phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
65using phosphor::logging::elog;
66
67std::string StaticGateway::gateway(std::string /*gateway*/)
68{
69 elog<NotAllowed>(REASON("Property update is not allowed"));
70}
71
72IP::Protocol StaticGateway::protocolType(IP::Protocol /*protocolType*/)
73{
74 elog<NotAllowed>(REASON("Property update is not allowed"));
75}
76} // namespace network
77} // namespace phosphor