summaryrefslogtreecommitdiffstats
path: root/ipaddress.cpp
blob: 43433e292aa423c32c8309a19cd0ea3b35bdab61 (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
#include "config.h"

#include "ipaddress.hpp"

#include "ethernet_interface.hpp"
#include "util.hpp"

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

namespace phosphor
{
namespace network
{

using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;

IPAddress::IPAddress(sdbusplus::bus::bus& bus, const char* objPath,
                     EthernetInterface& parent, IP::Protocol type,
                     const std::string& ipaddress, IP::AddressOrigin origin,
                     uint8_t prefixLength, const std::string& gateway) :
    IPIfaces(bus, objPath, true),
    parent(parent)
{
    this->address(ipaddress);
    this->prefixLength(prefixLength);
    this->gateway(gateway);
    this->type(type);
    this->origin(origin);

    // Emit deferred signal.
    emit_object_added();
}

void IPAddress::delete_()
{
    if (parent.dHCPEnabled())
    {
        log<level::ERR>("DHCP enabled on the interface"),
            entry("INTERFACE=%s", parent.interfaceName().c_str());
        return;
    }

#ifdef LINK_LOCAL_AUTOCONFIGURATION
    if (isLinkLocalIP(address()))
    {
        log<level::ERR>("Can not delete the LinkLocal address"),
            entry("INTERFACE=%s ADDRESS=%s", parent.interfaceName().c_str(),
                  address().c_str());
        return;
    }
#endif

    parent.deleteObject(address());
}

} // namespace network
} // namespace phosphor
OpenPOWER on IntegriCloud