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>
diff --git a/util.cpp b/util.cpp
index 4297590..b66f908 100644
--- a/util.cpp
+++ b/util.cpp
@@ -34,12 +34,12 @@
uint8_t pos = 0;
uint8_t prevPos = 0;
uint8_t cidr = 0;
- uint16_t buff {};
+ uint16_t buff{};
do
{
- //subnet mask look like ffff:ffff::
+ // subnet mask look like ffff:ffff::
// or ffff:c000::
- pos = subnetMask.find(":", prevPos);
+ pos = subnetMask.find(":", prevPos);
if (pos == std::string::npos)
{
break;
@@ -53,7 +53,7 @@
{
return cidr;
}
- //converts it into number.
+ // converts it into number.
if (sscanf(str.c_str(), "%hx", &buff) <= 0)
{
log<level::ERR>("Invalid Mask",
@@ -69,7 +69,8 @@
if (__builtin_popcount(buff) != 16)
{
- if (((sizeof(buff) * 8) - (__builtin_ctz(buff))) != __builtin_popcount(buff))
+ if (((sizeof(buff) * 8) - (__builtin_ctz(buff))) !=
+ __builtin_popcount(buff))
{
log<level::ERR>("Invalid Mask",
entry("SUBNETMASK=%s", subnetMask.c_str()));
@@ -81,12 +82,11 @@
}
cidr += 16;
- }
- while (1);
+ } while (1);
return cidr;
}
-}// anonymous namespace
+} // anonymous namespace
uint8_t toCidr(int addressFamily, const std::string& subnetMask)
{
@@ -107,7 +107,8 @@
buff = be32toh(buff);
// total no of bits - total no of leading zero == total no of ones
- if (((sizeof(buff) * 8) - (__builtin_ctz(buff))) == __builtin_popcount(buff))
+ if (((sizeof(buff) * 8) - (__builtin_ctz(buff))) ==
+ __builtin_popcount(buff))
{
return __builtin_popcount(buff);
}
@@ -123,19 +124,18 @@
{
if (addressFamily == AF_INET6)
{
- //TODO:- conversion for v6
+ // TODO:- conversion for v6
return "";
}
if (prefix < 1 || prefix > 30)
{
- log<level::ERR>("Invalid Prefix",
- entry("PREFIX=%d", prefix));
+ log<level::ERR>("Invalid Prefix", entry("PREFIX=%d", prefix));
return "";
}
/* Create the netmask from the number of bits */
unsigned long mask = 0;
- for (auto i = 0 ; i < prefix ; i++)
+ for (auto i = 0; i < prefix; i++)
{
mask |= 1 << (31 - i);
}
@@ -149,12 +149,13 @@
{
unsigned char* pntMask = nullptr;
unsigned char* pntNetwork = nullptr;
- int bit {};
- int offset {};
- struct in6_addr netmask {};
+ int bit{};
+ int offset{};
+ struct in6_addr netmask
+ {
+ };
const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0,
- 0xf8, 0xfc, 0xfe, 0xff
- };
+ 0xf8, 0xfc, 0xfe, 0xff};
pntMask = reinterpret_cast<unsigned char*>(&netmask);
@@ -186,13 +187,13 @@
pntMask = reinterpret_cast<unsigned char*>(&netmask);
pntNetwork = reinterpret_cast<unsigned char*>(&ipaddressNetwork);
- for (int i = 0; i < 16 ; i++)
+ for (int i = 0; i < 16; i++)
{
pntNetwork[i] = pntNetwork[i] & pntMask[i];
}
- //convert the network address into string fomat.
- char networkString[INET6_ADDRSTRLEN] = { 0 };
+ // convert the network address into string fomat.
+ char networkString[INET6_ADDRSTRLEN] = {0};
if (inet_ntop(addressFamily, &ipaddressNetwork, networkString,
INET6_ADDRSTRLEN) == NULL)
{
@@ -239,7 +240,7 @@
IntfAddrMap getInterfaceAddrs()
{
- IntfAddrMap intfMap {};
+ IntfAddrMap intfMap{};
struct ifaddrs* ifaddr = nullptr;
// attempt to fill struct with ifaddrs
@@ -254,7 +255,7 @@
AddrPtr ifaddrPtr(ifaddr);
ifaddr = nullptr;
- std::string intfName {};
+ std::string intfName{};
for (ifaddrs* ifa = ifaddrPtr.get(); ifa != nullptr; ifa = ifa->ifa_next)
{
@@ -275,36 +276,32 @@
continue;
}
intfName = ifa->ifa_name;
- AddrInfo info {};
- char ip[INET6_ADDRSTRLEN] = { 0 };
- char subnetMask[INET6_ADDRSTRLEN] = { 0 };
+ AddrInfo info{};
+ char ip[INET6_ADDRSTRLEN] = {0};
+ char subnetMask[INET6_ADDRSTRLEN] = {0};
if (ifa->ifa_addr->sa_family == AF_INET)
{
inet_ntop(ifa->ifa_addr->sa_family,
&(((struct sockaddr_in*)(ifa->ifa_addr))->sin_addr),
- ip,
- sizeof(ip));
+ ip, sizeof(ip));
- inet_ntop(ifa->ifa_addr->sa_family,
- &(((struct sockaddr_in*)(ifa->ifa_netmask))->sin_addr),
- subnetMask,
- sizeof(subnetMask));
-
+ inet_ntop(
+ ifa->ifa_addr->sa_family,
+ &(((struct sockaddr_in*)(ifa->ifa_netmask))->sin_addr),
+ subnetMask, sizeof(subnetMask));
}
else
{
inet_ntop(ifa->ifa_addr->sa_family,
&(((struct sockaddr_in6*)(ifa->ifa_addr))->sin6_addr),
- ip,
- sizeof(ip));
+ ip, sizeof(ip));
- inet_ntop(ifa->ifa_addr->sa_family,
- &(((struct sockaddr_in6*)(ifa->ifa_netmask))->sin6_addr),
- subnetMask,
- sizeof(subnetMask));
-
+ inet_ntop(
+ ifa->ifa_addr->sa_family,
+ &(((struct sockaddr_in6*)(ifa->ifa_netmask))->sin6_addr),
+ subnetMask, sizeof(subnetMask));
}
info.addrType = ifa->ifa_addr->sa_family;
@@ -318,7 +315,7 @@
InterfaceList getInterfaces()
{
- InterfaceList interfaces {};
+ InterfaceList interfaces{};
struct ifaddrs* ifaddr = nullptr;
// attempt to fill struct with ifaddrs
@@ -337,8 +334,7 @@
{
// walk interfaces
// if loopback, or not running ignore
- if ((ifa->ifa_flags & IFF_LOOPBACK) ||
- !(ifa->ifa_flags & IFF_RUNNING))
+ if ((ifa->ifa_flags & IFF_LOOPBACK) || !(ifa->ifa_flags & IFF_RUNNING))
{
continue;
}
@@ -347,27 +343,24 @@
return interfaces;
}
-
void deleteInterface(const std::string& intf)
{
pid_t pid = fork();
- int status {};
+ int status{};
if (pid == 0)
{
execl("/sbin/ip", "ip", "link", "delete", "dev", intf.c_str(), nullptr);
auto error = errno;
- log<level::ERR>("Couldn't delete the device",
- entry("ERRNO=%d", error),
+ log<level::ERR>("Couldn't delete the device", entry("ERRNO=%d", error),
entry("INTF=%s", intf.c_str()));
elog<InternalFailure>();
}
else if (pid < 0)
{
auto error = errno;
- log<level::ERR>("Error occurred during fork",
- entry("ERRNO=%d", error));
+ log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", error));
elog<InternalFailure>();
}
else if (pid > 0)
@@ -375,13 +368,13 @@
while (waitpid(pid, &status, 0) == -1)
{
if (errno != EINTR)
- { /* Error other than EINTR */
+ { /* Error other than EINTR */
status = -1;
break;
}
}
- if(status < 0)
+ if (status < 0)
{
log<level::ERR>("Unable to delete the interface",
entry("INTF=%s", intf.c_str()),
@@ -395,7 +388,7 @@
{
bool dhcp = false;
// Get the interface mode value from systemd conf
- //using namespace std::string_literals;
+ // using namespace std::string_literals;
fs::path confPath = confDir;
std::string fileName = systemd::config::networkFilePrefix + intf +
systemd::config::networkFileSuffix;
@@ -409,7 +402,7 @@
if (rc != config::ReturnCode::SUCCESS)
{
log<level::DEBUG>("Unable to get the value for Network[DHCP]",
- entry("RC=%d", rc));
+ entry("RC=%d", rc));
return dhcp;
}
// There will be only single value for DHCP key.
@@ -427,7 +420,7 @@
{
using namespace std::string_literals;
pid_t pid = fork();
- int status {};
+ int status{};
if (pid == 0)
{
@@ -436,9 +429,9 @@
// create the command from var args.
std::string command = path + " "s;
- for(int i = 0; args[i]; i++)
+ for (int i = 0; args[i]; i++)
{
- command += args[i] + " "s;
+ command += args[i] + " "s;
}
log<level::ERR>("Couldn't exceute the command",
@@ -449,8 +442,7 @@
else if (pid < 0)
{
auto error = errno;
- log<level::ERR>("Error occurred during fork",
- entry("ERRNO=%d", error));
+ log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", error));
elog<InternalFailure>();
}
else if (pid > 0)
@@ -458,16 +450,16 @@
while (waitpid(pid, &status, 0) == -1)
{
if (errno != EINTR)
- { //Error other than EINTR
+ { // Error other than EINTR
status = -1;
break;
}
}
- if(status < 0)
+ if (status < 0)
{
std::string command = path + " "s;
- for(int i = 0; args[i]; i++)
+ for (int i = 0; args[i]; i++)
{
command += args[i] + " "s;
}
@@ -478,9 +470,8 @@
elog<InternalFailure>();
}
}
-
}
-} //namespace internal
+} // namespace internal
namespace mac_address
{
@@ -494,12 +485,12 @@
using DbusObjectPath = std::string;
using DbusService = std::string;
using DbusInterface = std::string;
-using ObjectTree = std::map<DbusObjectPath,
- std::map<DbusService, std::vector<DbusInterface>>>;
+using ObjectTree =
+ std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
constexpr auto invBus = "xyz.openbmc_project.Inventory.Manager";
constexpr auto invNetworkIntf =
- "xyz.openbmc_project.Inventory.Item.NetworkInterface";
+ "xyz.openbmc_project.Inventory.Item.NetworkInterface";
constexpr auto invRoot = "/xyz/openbmc_project/inventory";
std::string getfromInventory(sdbusplus::bus::bus& bus)
@@ -509,10 +500,8 @@
auto depth = 0;
- auto mapperCall = bus.new_method_call(mapperBus,
- mapperObj,
- mapperIntf,
- "GetSubTree");
+ auto mapperCall =
+ bus.new_method_call(mapperBus, mapperObj, mapperIntf, "GetSubTree");
mapperCall.append(invRoot, depth, interfaces);
@@ -540,18 +529,15 @@
sdbusplus::message::variant<std::string> value;
- auto method = bus.new_method_call(
- service.c_str(),
- objPath.c_str(),
- propIntf,
- methodGet);
+ auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
+ propIntf, methodGet);
method.append(invNetworkIntf, "MACAddress");
auto reply = bus.call(method);
if (reply.is_method_error())
{
- log<level::ERR>("Failed to get MACAddress",
+ log<level::ERR>("Failed to get MACAddress",
entry("PATH=%s", objPath.c_str()),
entry("INTERFACE=%s", invNetworkIntf));
elog<InternalFailure>();
@@ -561,6 +547,6 @@
return value.get<std::string>();
}
-}//namespace mac_address
-}//namespace network
-}//namespace phosphor
+} // namespace mac_address
+} // namespace network
+} // namespace phosphor