summaryrefslogtreecommitdiffstats
path: root/ethernet_interface.cpp
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2018-09-14 14:42:34 -0500
committerRatan K Gupta <ratagupt@linux.vnet.ibm.com>2018-09-15 00:47:14 -0400
commit57d9c5066e2fc28d3e89b1bd9fd3ee98e27c4c48 (patch)
treef232adeab7b6a89cd392d4300be70451d335d14f /ethernet_interface.cpp
parentce26282763be6a9d7fa21fcc93d5da8682d3a021 (diff)
downloadphosphor-networkd-57d9c5066e2fc28d3e89b1bd9fd3ee98e27c4c48.tar.gz
phosphor-networkd-57d9c5066e2fc28d3e89b1bd9fd3ee98e27c4c48.zip
clang-format: Update to match docs repo
Update the .clang-format file and run clang-format-6.0. This .clang-format matches the example one in https://github.com/openbmc/docs/blob/master/cpp-style-and-conventions.md#clang-formatting Change-Id: Ia331c9a5b040e1a3c45a0ebf1b8d776d93b05ae5 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'ethernet_interface.cpp')
-rw-r--r--ethernet_interface.cpp255
1 files changed, 112 insertions, 143 deletions
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 04f9009..19dfec4 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -1,6 +1,7 @@
+#include "config.h"
+
#include "ethernet_interface.hpp"
-#include "config.h"
#include "config_parser.hpp"
#include "ipaddress.hpp"
#include "network_manager.hpp"
@@ -36,13 +37,10 @@ using Argument = xyz::openbmc_project::Common::InvalidArgument;
EthernetInterface::EthernetInterface(sdbusplus::bus::bus& bus,
const std::string& objPath,
- bool dhcpEnabled,
- Manager& parent,
+ bool dhcpEnabled, Manager& parent,
bool emitSignal) :
- Ifaces(bus, objPath.c_str(), true),
- bus(bus),
- manager(parent),
- objPath(objPath)
+ Ifaces(bus, objPath.c_str(), true),
+ bus(bus), manager(parent), objPath(objPath)
{
auto intfName = objPath.substr(objPath.rfind("/") + 1);
std::replace(intfName.begin(), intfName.end(), '_', '.');
@@ -84,34 +82,24 @@ void EthernetInterface::createIPAddressObjects()
{
origin = IP::AddressOrigin::LinkLocal;
}
- gateway = routingTable.getGateway(addr.addrType, addr.ipaddress, addr.prefix);
-
- std::string ipAddressObjectPath = generateObjectPath(addressType,
- addr.ipaddress,
- addr.prefix,
- gateway);
-
- this->addrs.emplace(
- addr.ipaddress,
- std::make_shared<phosphor::network::IPAddress>(
- bus,
- ipAddressObjectPath.c_str(),
- *this,
- addressType,
- addr.ipaddress,
- origin,
- addr.prefix,
- gateway));
+ gateway =
+ routingTable.getGateway(addr.addrType, addr.ipaddress, addr.prefix);
+
+ std::string ipAddressObjectPath = generateObjectPath(
+ addressType, addr.ipaddress, addr.prefix, gateway);
+
+ this->addrs.emplace(addr.ipaddress,
+ std::make_shared<phosphor::network::IPAddress>(
+ bus, ipAddressObjectPath.c_str(), *this,
+ addressType, addr.ipaddress, origin,
+ addr.prefix, gateway));
origin = IP::AddressOrigin::Static;
}
-
}
-void EthernetInterface::iP(IP::Protocol protType,
- std::string ipaddress,
- uint8_t prefixLength,
- std::string gateway)
+void EthernetInterface::iP(IP::Protocol protType, std::string ipaddress,
+ uint8_t prefixLength, std::string gateway)
{
if (dHCPEnabled())
@@ -121,7 +109,6 @@ void EthernetInterface::iP(IP::Protocol protType,
dHCPEnabled(false);
}
-
IP::AddressOrigin origin = IP::AddressOrigin::Static;
int addressFamily = (protType == IP::Protocol::IPv4) ? AF_INET : AF_INET6;
@@ -146,32 +133,21 @@ void EthernetInterface::iP(IP::Protocol protType,
{
log<level::ERR>("PrefixLength is not correct "),
entry("PREFIXLENGTH=%d", gateway.c_str());
- elog<InvalidArgument>(Argument::ARGUMENT_NAME("prefixLength"),
- Argument::ARGUMENT_VALUE(std::to_string(
- prefixLength).c_str()));
- }
-
-
- std::string objectPath = generateObjectPath(protType,
- ipaddress,
- prefixLength,
- gateway);
- this->addrs.emplace(
- ipaddress,
- std::make_shared<phosphor::network::IPAddress>(
- bus,
- objectPath.c_str(),
- *this,
- protType,
- ipaddress,
- origin,
- prefixLength,
- gateway));
+ elog<InvalidArgument>(
+ Argument::ARGUMENT_NAME("prefixLength"),
+ Argument::ARGUMENT_VALUE(std::to_string(prefixLength).c_str()));
+ }
+
+ std::string objectPath =
+ generateObjectPath(protType, ipaddress, prefixLength, gateway);
+ this->addrs.emplace(ipaddress,
+ std::make_shared<phosphor::network::IPAddress>(
+ bus, objectPath.c_str(), *this, protType, ipaddress,
+ origin, prefixLength, gateway));
manager.writeToConfigurationFile();
}
-
/*
Note: We don't have support for ethtool now
will enable this code once we bring the ethtool
@@ -182,11 +158,17 @@ TODO: https://github.com/openbmc/openbmc/issues/1484
InterfaceInfo EthernetInterface::getInterfaceInfo() const
{
int sock{-1};
- struct ifreq ifr{0};
- struct ethtool_cmd edata{0};
- LinkSpeed speed {0};
- Autoneg autoneg {0};
- DuplexMode duplex {0};
+ struct ifreq ifr
+ {
+ 0
+ };
+ struct ethtool_cmd edata
+ {
+ 0
+ };
+ LinkSpeed speed{0};
+ Autoneg autoneg{0};
+ DuplexMode duplex{0};
do
{
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
@@ -207,13 +189,11 @@ InterfaceInfo EthernetInterface::getInterfaceInfo() const
log<level::ERR>("ioctl failed for SIOCETHTOOL:",
entry("ERROR=%s", strerror(errno)));
break;
-
}
speed = edata.speed;
duplex = edata.duplex;
autoneg = edata.autoneg;
- }
- while (0);
+ } while (0);
if (sock)
{
@@ -226,11 +206,13 @@ InterfaceInfo EthernetInterface::getInterfaceInfo() const
* @return macaddress on success
*/
-std::string EthernetInterface::getMACAddress(
- const std::string& interfaceName) const
+std::string
+ EthernetInterface::getMACAddress(const std::string& interfaceName) const
{
- struct ifreq ifr{};
- char macAddress[mac_address::size] {};
+ struct ifreq ifr
+ {
+ };
+ char macAddress[mac_address::size]{};
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock < 0)
@@ -244,14 +226,14 @@ std::string EthernetInterface::getMACAddress(
if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0)
{
log<level::ERR>("ioctl failed for SIOCGIFHWADDR:",
- entry("ERROR=%s", strerror(errno)));
+ entry("ERROR=%s", strerror(errno)));
return macAddress;
}
snprintf(macAddress, mac_address::size, mac_address::format,
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
- ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
- ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+ ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
+ ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
+ ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
return macAddress;
}
@@ -266,8 +248,7 @@ std::string EthernetInterface::generateId(const std::string& ipaddress,
hashString += gateway;
// Only want 8 hex digits.
- hexId << std::hex << ((std::hash<std::string> {}(
- hashString)) & 0xFFFFFFFF);
+ hexId << std::hex << ((std::hash<std::string>{}(hashString)) & 0xFFFFFFFF);
return hexId.str();
}
@@ -316,7 +297,6 @@ void EthernetInterface::deleteVLANFromSystem(const std::string& interface)
{
commit<InternalFailure>();
}
-
}
void EthernetInterface::deleteVLANObject(const std::string& interface)
@@ -325,7 +305,7 @@ void EthernetInterface::deleteVLANObject(const std::string& interface)
if (it == vlanInterfaces.end())
{
log<level::ERR>("DeleteVLANObject:Unable to find the object",
- entry("INTERFACE=%s",interface.c_str()));
+ entry("INTERFACE=%s", interface.c_str()));
return;
}
@@ -336,10 +316,9 @@ void EthernetInterface::deleteVLANObject(const std::string& interface)
manager.writeToConfigurationFile();
}
-std::string EthernetInterface::generateObjectPath(IP::Protocol addressType,
- const std::string& ipaddress,
- uint8_t prefixLength,
- const std::string& gateway) const
+std::string EthernetInterface::generateObjectPath(
+ IP::Protocol addressType, const std::string& ipaddress,
+ uint8_t prefixLength, const std::string& gateway) const
{
std::string type = convertForMessage(addressType);
type = type.substr(type.rfind('.') + 1);
@@ -393,8 +372,7 @@ ServerList EthernetInterface::getNameServerFromConf()
fs::path confPath = manager.getConfDir();
std::string fileName = systemd::config::networkFilePrefix +
- interfaceName() +
- systemd::config::networkFileSuffix;
+ interfaceName() + systemd::config::networkFileSuffix;
confPath /= fileName;
ServerList servers;
config::Parser parser(confPath.string());
@@ -421,7 +399,7 @@ void EthernetInterface::writeDNSEntries(const ServerList& dnsList,
}
outStream << "### Generated manually via dbus settings ###\n";
- for(const auto& server : dnsList)
+ for (const auto& server : dnsList)
{
outStream << "nameserver " << server << "\n";
}
@@ -429,24 +407,18 @@ void EthernetInterface::writeDNSEntries(const ServerList& dnsList,
void EthernetInterface::loadVLAN(VlanId id)
{
- std::string vlanInterfaceName = interfaceName() + "." +
- std::to_string(id);
+ std::string vlanInterfaceName = interfaceName() + "." + std::to_string(id);
std::string path = objPath;
path += "_" + std::to_string(id);
- auto dhcpEnabled = getDHCPValue(manager.getConfDir().string(),
- vlanInterfaceName);
+ auto dhcpEnabled =
+ getDHCPValue(manager.getConfDir().string(), vlanInterfaceName);
auto vlanIntf = std::make_unique<phosphor::network::VlanInterface>(
- bus,
- path.c_str(),
- dhcpEnabled,
- id,
- *this,
- manager);
-
- // Fetch the ip address from the system
- // and create the dbus object.
+ bus, path.c_str(), dhcpEnabled, id, *this, manager);
+
+ // Fetch the ip address from the system
+ // and create the dbus object.
vlanIntf->createIPAddressObjects();
this->vlanInterfaces.emplace(std::move(vlanInterfaceName),
@@ -455,25 +427,17 @@ void EthernetInterface::loadVLAN(VlanId id)
void EthernetInterface::createVLAN(VlanId id)
{
- std::string vlanInterfaceName = interfaceName() + "." +
- std::to_string(id);
+ std::string vlanInterfaceName = interfaceName() + "." + std::to_string(id);
std::string path = objPath;
path += "_" + std::to_string(id);
-
auto vlanIntf = std::make_unique<phosphor::network::VlanInterface>(
- bus,
- path.c_str(),
- false,
- id,
- *this,
- manager);
+ bus, path.c_str(), false, id, *this, manager);
// write the device file for the vlan interface.
vlanIntf->writeDeviceFile();
- this->vlanInterfaces.emplace(vlanInterfaceName,
- std::move(vlanIntf));
+ this->vlanInterfaces.emplace(vlanInterfaceName, std::move(vlanIntf));
// write the new vlan device entry to the configuration(network) file.
manager.writeToConfigurationFile();
}
@@ -482,8 +446,8 @@ ServerList EthernetInterface::getNTPServersFromConf()
{
fs::path confPath = manager.getConfDir();
- std::string fileName = systemd::config::networkFilePrefix + interfaceName() +
- systemd::config::networkFileSuffix;
+ std::string fileName = systemd::config::networkFilePrefix +
+ interfaceName() + systemd::config::networkFileSuffix;
confPath /= fileName;
ServerList servers;
@@ -502,7 +466,7 @@ ServerList EthernetInterface::getNTPServersFromConf()
ServerList EthernetInterface::nTPServers(ServerList servers)
{
- auto ntpServers = EthernetInterfaceIntf::nTPServers(servers);
+ auto ntpServers = EthernetInterfaceIntf::nTPServers(servers);
writeConfigurationFile();
// timesynchd reads the NTP server configuration from the
@@ -526,15 +490,15 @@ void EthernetInterface::writeConfigurationFile()
// if there is vlan interafce then write the configuration file
// for vlan also.
- for (const auto& intf: vlanInterfaces)
+ for (const auto& intf : vlanInterfaces)
{
intf.second->writeConfigurationFile();
}
fs::path confPath = manager.getConfDir();
- std::string fileName = systemd::config::networkFilePrefix + interfaceName() +
- systemd::config::networkFileSuffix;
+ std::string fileName = systemd::config::networkFilePrefix +
+ interfaceName() + systemd::config::networkFileSuffix;
confPath /= fileName;
std::fstream stream;
@@ -547,13 +511,17 @@ void EthernetInterface::writeConfigurationFile()
}
// Write the device
- stream << "[" << "Match" << "]\n";
+ stream << "["
+ << "Match"
+ << "]\n";
stream << "Name=" << interfaceName() << "\n";
auto addrs = getAddresses();
// write the network section
- stream << "[" << "Network" << "]\n";
+ stream << "["
+ << "Network"
+ << "]\n";
#ifdef LINK_LOCAL_AUTOCONFIGURATION
stream << "LinkLocalAddressing=yes\n";
#else
@@ -562,10 +530,10 @@ void EthernetInterface::writeConfigurationFile()
stream << "IPv6AcceptRA=false\n";
// Add the VLAN entry
- for (const auto& intf: vlanInterfaces)
+ for (const auto& intf : vlanInterfaces)
{
stream << "VLAN=" << intf.second->EthernetInterface::interfaceName()
- << "\n";
+ << "\n";
}
// Add the DHCP entry
auto value = dHCPEnabled() ? "true"s : "false"s;
@@ -575,13 +543,13 @@ void EthernetInterface::writeConfigurationFile()
// in config file.
if (dHCPEnabled() == false)
{
- //Add the NTP server
+ // Add the NTP server
for (const auto& ntp : EthernetInterfaceIntf::nTPServers())
{
stream << "NTP=" << ntp << "\n";
}
- //Add the DNS entry
+ // Add the DNS entry
for (const auto& dns : EthernetInterfaceIntf::nameservers())
{
stream << "DNS=" << dns << "\n";
@@ -596,8 +564,9 @@ void EthernetInterface::writeConfigurationFile()
#endif
)
{
- std::string address = addr.second->address() + "/" +
- std::to_string(addr.second->prefixLength());
+ std::string address =
+ addr.second->address() + "/" +
+ std::to_string(addr.second->prefixLength());
stream << "Address=" << address << "\n";
}
@@ -614,20 +583,21 @@ void EthernetInterface::writeConfigurationFile()
{
if (addr.second->origin() == AddressOrigin::Static)
{
- int addressFamily = addr.second->type() == IP::Protocol::IPv4 ?
- AF_INET : AF_INET6;
+ int addressFamily = addr.second->type() == IP::Protocol::IPv4
+ ? AF_INET
+ : AF_INET6;
- std::string destination = getNetworkID(
- addressFamily,
- addr.second->address(),
- addr.second->prefixLength());
+ std::string destination =
+ getNetworkID(addressFamily, addr.second->address(),
+ addr.second->prefixLength());
if (addr.second->gateway() != "0.0.0.0" &&
- addr.second->gateway() != "" &&
- destination != "0.0.0.0" &&
+ addr.second->gateway() != "" && destination != "0.0.0.0" &&
destination != "")
{
- stream << "[" << "Route" << "]\n";
+ stream << "["
+ << "Route"
+ << "]\n";
stream << "Gateway=" << addr.second->gateway() << "\n";
stream << "Destination=" << destination << "\n";
}
@@ -672,7 +642,7 @@ std::string EthernetInterface::mACAddress(std::string value)
if (!mac_address::validate(value))
{
log<level::ERR>("MACAddress is not valid.",
- entry("MAC=%s", value.c_str()));
+ entry("MAC=%s", value.c_str()));
elog<InvalidArgument>(Argument::ARGUMENT_NAME("MACAddress"),
Argument::ARGUMENT_VALUE(value.c_str()));
}
@@ -683,7 +653,7 @@ std::string EthernetInterface::mACAddress(std::string value)
if (!(intMac ^ mac_address::broadcastMac))
{
log<level::ERR>("MACAddress is a broadcast mac.",
- entry("MAC=%s", value.c_str()));
+ entry("MAC=%s", value.c_str()));
elog<InvalidArgument>(Argument::ARGUMENT_NAME("MACAddress"),
Argument::ARGUMENT_VALUE(value.c_str()));
}
@@ -705,17 +675,18 @@ std::string EthernetInterface::mACAddress(std::string value)
try
{
auto inventoryMac = mac_address::getfromInventory(bus);
- auto intInventoryMac = mac_address::internal::convertToInt(inventoryMac);
+ auto intInventoryMac =
+ mac_address::internal::convertToInt(inventoryMac);
if (intInventoryMac != intMac)
{
log<level::ERR>("Given MAC address is neither a local Admin "
- "type nor is same as in inventory");
+ "type nor is same as in inventory");
elog<InvalidArgument>(Argument::ARGUMENT_NAME("MACAddress"),
Argument::ARGUMENT_VALUE(value.c_str()));
}
}
- catch(InternalFailure& e)
+ catch (InternalFailure& e)
{
log<level::ERR>("Exception occurred during getting of MAC "
"address from Inventory");
@@ -724,18 +695,18 @@ std::string EthernetInterface::mACAddress(std::string value)
}
auto interface = interfaceName();
execute("/sbin/fw_setenv", "fw_setenv", "ethaddr", value.c_str());
- //TODO: would replace below three calls
+ // TODO: would replace below three calls
// with restarting of systemd-netwokd
// through https://github.com/systemd/systemd/issues/6696
execute("/sbin/ip", "ip", "link", "set", "dev", interface.c_str(), "down");
- execute("/sbin/ip", "ip", "link", "set", "dev", interface.c_str(), "address",
- value.c_str());
+ execute("/sbin/ip", "ip", "link", "set", "dev", interface.c_str(),
+ "address", value.c_str());
execute("/sbin/ip", "ip", "link", "set", "dev", interface.c_str(), "up");
auto mac = MacAddressIntf::mACAddress(std::move(value));
- //update all the vlan interfaces
- for(const auto& intf: vlanInterfaces)
+ // update all the vlan interfaces
+ for (const auto& intf : vlanInterfaces)
{
intf.second->updateMacAddress();
}
@@ -747,16 +718,14 @@ std::string EthernetInterface::mACAddress(std::string value)
restartSystemdUnit(networkdService);
}
return mac;
-
}
void EthernetInterface::deleteAll()
{
- if(EthernetInterfaceIntf::dHCPEnabled())
+ if (EthernetInterfaceIntf::dHCPEnabled())
{
log<level::INFO>("DHCP enabled on the interface"),
- entry("INTERFACE=%s", interfaceName().c_str());
-
+ entry("INTERFACE=%s", interfaceName().c_str());
}
// clear all the ip on the interface
@@ -764,5 +733,5 @@ void EthernetInterface::deleteAll()
manager.writeToConfigurationFile();
}
-}//namespace network
-}//namespace phosphor
+} // namespace network
+} // namespace phosphor
OpenPOWER on IntegriCloud