summaryrefslogtreecommitdiffstats
path: root/dhcp_configuration.cpp
blob: 77074611e7d7bb54e3110198f4a88686158dd8a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "config.h"

#include "dhcp_configuration.hpp"

#include "network_manager.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>

namespace phosphor
{
namespace network
{
namespace dhcp
{

using namespace phosphor::network;
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
bool Configuration::sendHostNameEnabled(bool value)
{
    if (value == sendHostNameEnabled())
    {
        return value;
    }

    auto name = ConfigIntf::sendHostNameEnabled(value);
    manager.writeToConfigurationFile();

    return name;
}

bool Configuration::hostNameEnabled(bool value)
{
    if (value == hostNameEnabled())
    {
        return value;
    }

    auto name = ConfigIntf::hostNameEnabled(value);
    manager.writeToConfigurationFile();
    manager.restartSystemdUnit(phosphor::network::networkdService);

    return name;
}

bool Configuration::nTPEnabled(bool value)
{
    if (value == nTPEnabled())
    {
        return value;
    }

    auto ntp = ConfigIntf::nTPEnabled(value);
    manager.writeToConfigurationFile();
    manager.restartSystemdUnit(phosphor::network::networkdService);
    manager.restartSystemdUnit(phosphor::network::timeSynchdService);

    return ntp;
}

bool Configuration::dNSEnabled(bool value)
{
    if (value == dNSEnabled())
    {
        return value;
    }

    auto dns = ConfigIntf::dNSEnabled(value);
    manager.writeToConfigurationFile();
    manager.restartSystemdUnit(phosphor::network::networkdService);

    return dns;
}

bool Configuration::getDHCPPropFromConf(const std::string& prop)
{
    fs::path confPath = manager.getConfDir();
    auto interfaceStrList = getInterfaces();
    // get the first interface name, we need it to know config file name.
    auto interface = *interfaceStrList.begin();
    auto fileName = systemd::config::networkFilePrefix + interface +
                    systemd::config::networkFileSuffix;

    confPath /= fileName;
    // systemd default behaviour is all DHCP fields should be enabled by
    // default.
    auto propValue = true;
    config::Parser parser(confPath);

    auto rc = config::ReturnCode::SUCCESS;
    config::ValueList values{};
    std::tie(rc, values) = parser.getValues("DHCP", prop);

    if (rc != config::ReturnCode::SUCCESS)
    {
        log<level::DEBUG>("Unable to get the value from section DHCP",
                          entry("PROP=%s", prop.c_str()), entry("RC=%d", rc));
        return propValue;
    }

    if (values[0] == "false")
    {
        propValue = false;
    }
    return propValue;
}
} // namespace dhcp
} // namespace network
} // namespace phosphor
OpenPOWER on IntegriCloud