summaryrefslogtreecommitdiffstats
path: root/ncsi_util.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 /ncsi_util.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 'ncsi_util.cpp')
-rw-r--r--ncsi_util.cpp119
1 files changed, 47 insertions, 72 deletions
diff --git a/ncsi_util.cpp b/ncsi_util.cpp
index c177bec..2b3fb54 100644
--- a/ncsi_util.cpp
+++ b/ncsi_util.cpp
@@ -1,9 +1,9 @@
#include "ncsi_util.hpp"
#include <linux/ncsi.h>
-#include <netlink/netlink.h>
-#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
+#include <netlink/genl/genl.h>
+#include <netlink/netlink.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
@@ -19,7 +19,7 @@ namespace ncsi
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-using CallBack = int(*)(struct nl_msg* msg, void* arg);
+using CallBack = int (*)(struct nl_msg* msg, void* arg);
namespace internal
{
@@ -27,40 +27,26 @@ namespace internal
using nlMsgPtr = std::unique_ptr<nl_msg, decltype(&::nlmsg_free)>;
using nlSocketPtr = std::unique_ptr<nl_sock, decltype(&::nl_socket_free)>;
-CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
-{
+CallBack infoCallBack = [](struct nl_msg* msg, void* arg) {
using namespace phosphor::network::ncsi;
auto nlh = nlmsg_hdr(msg);
- struct nlattr* tb[NCSI_ATTR_MAX + 1] = { nullptr };
- struct nla_policy ncsiPolicy[NCSI_ATTR_MAX + 1] =
- {
- { type: NLA_UNSPEC },
- { type: NLA_U32 },
- { type: NLA_NESTED },
- { type: NLA_U32 },
- { type: NLA_U32 },
+ struct nlattr* tb[NCSI_ATTR_MAX + 1] = {nullptr};
+ struct nla_policy ncsiPolicy[NCSI_ATTR_MAX + 1] = {
+ {type : NLA_UNSPEC}, {type : NLA_U32}, {type : NLA_NESTED},
+ {type : NLA_U32}, {type : NLA_U32},
};
- struct nlattr* packagetb[NCSI_PKG_ATTR_MAX + 1] = { nullptr };
- struct nla_policy packagePolicy[NCSI_PKG_ATTR_MAX + 1] =
- {
- { type: NLA_UNSPEC },
- { type: NLA_NESTED },
- { type: NLA_U32 },
- { type: NLA_FLAG },
- { type: NLA_NESTED },
+ struct nlattr* packagetb[NCSI_PKG_ATTR_MAX + 1] = {nullptr};
+ struct nla_policy packagePolicy[NCSI_PKG_ATTR_MAX + 1] = {
+ {type : NLA_UNSPEC}, {type : NLA_NESTED}, {type : NLA_U32},
+ {type : NLA_FLAG}, {type : NLA_NESTED},
};
- struct nlattr* channeltb[NCSI_CHANNEL_ATTR_MAX + 1] = { nullptr };
- struct nla_policy channelPolicy[NCSI_CHANNEL_ATTR_MAX + 1] =
- {
- { type: NLA_UNSPEC },
- { type: NLA_NESTED },
- { type: NLA_U32 },
- { type: NLA_FLAG },
- { type: NLA_NESTED },
- { type: NLA_UNSPEC},
+ struct nlattr* channeltb[NCSI_CHANNEL_ATTR_MAX + 1] = {nullptr};
+ struct nla_policy channelPolicy[NCSI_CHANNEL_ATTR_MAX + 1] = {
+ {type : NLA_UNSPEC}, {type : NLA_NESTED}, {type : NLA_U32},
+ {type : NLA_FLAG}, {type : NLA_NESTED}, {type : NLA_UNSPEC},
};
auto ret = genlmsg_parse(nlh, 0, tb, NCSI_ATTR_MAX, ncsiPolicy);
@@ -91,8 +77,7 @@ CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
if (packagetb[NCSI_PKG_ATTR_ID])
{
auto attrID = nla_get_u32(packagetb[NCSI_PKG_ATTR_ID]);
- log<level::DEBUG>("Package has id",
- entry("ID=%x", attrID));
+ log<level::DEBUG>("Package has id", entry("ID=%x", attrID));
}
else
{
@@ -105,7 +90,7 @@ CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
}
auto channelListTarget = static_cast<nlattr*>(
- nla_data(packagetb[NCSI_PKG_ATTR_CHANNEL_LIST]));
+ nla_data(packagetb[NCSI_PKG_ATTR_CHANNEL_LIST]));
auto channelrem = nla_len(packagetb[NCSI_PKG_ATTR_CHANNEL_LIST]);
nla_for_each_nested(channelListTarget,
@@ -125,7 +110,7 @@ CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
if (channeltb[NCSI_CHANNEL_ATTR_ACTIVE])
{
log<level::DEBUG>("Channel Active",
- entry("CHANNEL=%x", channel));
+ entry("CHANNEL=%x", channel));
}
else
{
@@ -145,26 +130,30 @@ CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
if (channeltb[NCSI_CHANNEL_ATTR_VERSION_MAJOR])
{
- auto major = nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MAJOR]);
+ auto major =
+ nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MAJOR]);
log<level::DEBUG>("Channel Major Version",
entry("VERSION=%x", major));
}
if (channeltb[NCSI_CHANNEL_ATTR_VERSION_MINOR])
{
- auto minor = nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MINOR]);
+ auto minor =
+ nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MINOR]);
log<level::DEBUG>("Channel Minor Version",
entry("VERSION=%x", minor));
}
if (channeltb[NCSI_CHANNEL_ATTR_VERSION_STR])
{
- auto str = nla_get_string(channeltb[NCSI_CHANNEL_ATTR_VERSION_STR]);
+ auto str =
+ nla_get_string(channeltb[NCSI_CHANNEL_ATTR_VERSION_STR]);
log<level::DEBUG>("Channel Version Str",
entry("VERSION=%s", str));
}
if (channeltb[NCSI_CHANNEL_ATTR_LINK_STATE])
{
- auto link = nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_LINK_STATE]);
+ auto link =
+ nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_LINK_STATE]);
log<level::DEBUG>("Channel Link State",
entry("STATE=%x", link));
}
@@ -177,14 +166,11 @@ CallBack infoCallBack = [](struct nl_msg* msg, void* arg)
while (nla_ok(vid, len))
{
auto id = nla_get_u16(vid);
- log<level::DEBUG>("VID",
- entry("VID=%d", id));
+ log<level::DEBUG>("VID", entry("VID=%d", id));
vid = nla_next(vid, &len);
}
}
-
}
-
}
return (int)NL_SKIP;
};
@@ -193,31 +179,28 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
int channel = DEFAULT_VALUE, int flags = NONE,
CallBack function = nullptr)
{
- nlSocketPtr socket(nl_socket_alloc(),&::nl_socket_free);
+ nlSocketPtr socket(nl_socket_alloc(), &::nl_socket_free);
auto ret = genl_connect(socket.get());
if (ret < 0)
{
- log<level::ERR>("Failed to open the socket",
- entry("RC=%d", ret));
+ log<level::ERR>("Failed to open the socket", entry("RC=%d", ret));
return ret;
}
auto driverID = genl_ctrl_resolve(socket.get(), "NCSI");
if (driverID < 0)
{
- log<level::ERR>("Failed to resolve",
- entry("RC=%d", ret));
+ log<level::ERR>("Failed to resolve", entry("RC=%d", ret));
return driverID;
}
nlMsgPtr msg(nlmsg_alloc(), &::nlmsg_free);
- auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags,
- cmd, 0);
+ auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags, cmd, 0);
if (!msgHdr)
{
log<level::ERR>("Unable to add the netlink headers",
- entry("COMMAND=%d", cmd));
+ entry("COMMAND=%d", cmd));
return -1;
}
@@ -227,8 +210,7 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
package);
if (ret < 0)
{
- log<level::ERR>("Failed to set the attribute",
- entry("RC=%d", ret),
+ log<level::ERR>("Failed to set the attribute", entry("RC=%d", ret),
entry("PACKAGE=%x", package));
return ret;
}
@@ -240,8 +222,7 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
channel);
if (ret < 0)
{
- log<level::ERR>("Failed to set the attribute",
- entry("RC=%d", ret),
+ log<level::ERR>("Failed to set the attribute", entry("RC=%d", ret),
entry("CHANNEL=%x", channel));
return ret;
}
@@ -250,8 +231,7 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_IFINDEX, ifindex);
if (ret < 0)
{
- log<level::ERR>("Failed to set the attribute",
- entry("RC=%d", ret),
+ log<level::ERR>("Failed to set the attribute", entry("RC=%d", ret),
entry("INTERFACE=%x", ifindex));
return ret;
}
@@ -259,33 +239,30 @@ int applyCmd(int ifindex, int cmd, int package = DEFAULT_VALUE,
if (function)
{
// Add a callback function to the socket
- nl_socket_modify_cb(socket.get(), NL_CB_VALID, NL_CB_CUSTOM,
- function, nullptr);
+ nl_socket_modify_cb(socket.get(), NL_CB_VALID, NL_CB_CUSTOM, function,
+ nullptr);
}
ret = nl_send_auto(socket.get(), msg.get());
if (ret < 0)
{
- log<level::ERR>("Failed to send the message",
- entry("RC=%d", ret));
+ log<level::ERR>("Failed to send the message", entry("RC=%d", ret));
return ret;
}
ret = nl_recvmsgs_default(socket.get());
if (ret < 0)
{
- log<level::ERR>("Failed to receive the message",
- entry("RC=%d", ret));
+ log<level::ERR>("Failed to receive the message", entry("RC=%d", ret));
}
return ret;
}
-}//namespace internal
+} // namespace internal
int setChannel(int ifindex, int package, int channel)
{
- log<level::DEBUG>("Set Channel",
- entry("CHANNEL=%x", channel),
+ log<level::DEBUG>("Set Channel", entry("CHANNEL=%x", channel),
entry("PACKAGE=%x", package),
entry("IFINDEX=%x", ifindex));
return internal::applyCmd(ifindex, ncsi_nl_commands::NCSI_CMD_SET_INTERFACE,
@@ -294,16 +271,14 @@ int setChannel(int ifindex, int package, int channel)
int clearInterface(int ifindex)
{
- log<level::DEBUG>("ClearInterface",
- entry("IFINDEX=%x", ifindex));
+ log<level::DEBUG>("ClearInterface", entry("IFINDEX=%x", ifindex));
return internal::applyCmd(ifindex,
ncsi_nl_commands::NCSI_CMD_CLEAR_INTERFACE);
}
int getInfo(int ifindex, int package)
{
- log<level::DEBUG>("Get Info",
- entry("PACKAGE=%x", package),
+ log<level::DEBUG>("Get Info", entry("PACKAGE=%x", package),
entry("IFINDEX=%x", ifindex));
if (package == DEFAULT_VALUE)
{
@@ -319,6 +294,6 @@ int getInfo(int ifindex, int package)
}
}
-}//namespace ncsi
-}//namespace network
-}//namespace phosphor
+} // namespace ncsi
+} // namespace network
+} // namespace phosphor
OpenPOWER on IntegriCloud