summaryrefslogtreecommitdiffstats
path: root/vlan_interface.cpp
blob: 1b4eaeeb3365ae0652bcf9b28ecc00704323291a (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
#include "config.h"

#include "vlan_interface.hpp"

#include "ethernet_interface.hpp"
#include "network_manager.hpp"

#include <algorithm>
#include <experimental/filesystem>
#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <string>
#include <xyz/openbmc_project/Common/error.hpp>

namespace phosphor
{
namespace network
{

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

VlanInterface::VlanInterface(sdbusplus::bus::bus& bus,
                             const std::string& objPath, bool dhcpEnabled,
                             uint32_t vlanID, EthernetInterface& intf,
                             Manager& parent) :
    VlanIface(bus, objPath.c_str()),
    DeleteIface(bus, objPath.c_str()),
    EthernetInterface(bus, objPath, dhcpEnabled, parent, false),
    parentInterface(intf)
{
    id(vlanID);
    VlanIface::interfaceName(EthernetInterface::interfaceName());
    MacAddressIntf::mACAddress(parentInterface.mACAddress());

    emit_object_added();
}

void VlanInterface::writeDeviceFile()
{
    using namespace std::string_literals;
    fs::path confPath = manager.getConfDir();
    std::string fileName = EthernetInterface::interfaceName() + ".netdev"s;
    confPath /= fileName;
    std::fstream stream;
    try
    {
        stream.open(confPath.c_str(), std::fstream::out);
    }
    catch (std::ios_base::failure& e)
    {
        log<level::ERR>("Unable to open the VLAN device file",
                        entry("FILE=%s", confPath.c_str()),
                        entry("ERROR=%s", e.what()));
        elog<InternalFailure>();
    }

    stream << "[NetDev]\n";
    stream << "Name=" << EthernetInterface::interfaceName() << "\n";
    stream << "Kind=vlan\n";
    stream << "[VLAN]\n";
    stream << "Id=" << id() << "\n";
    stream.close();
}

void VlanInterface::delete_()
{
    parentInterface.deleteVLANObject(EthernetInterface::interfaceName());
}

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