summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-11-30 16:53:52 -0800
committerWilliam A. Kennington III <wak@google.com>2019-01-18 02:36:40 +0000
commitfbafa25b0cbc9e20b9da0cc0fd007370b9f8fadd (patch)
tree05b927119783e99548a381e684c5aead87cbb629
parenta5b1b0d04197dc7b11afd0358c51ffb2320afcd6 (diff)
downloadphosphor-networkd-fbafa25b0cbc9e20b9da0cc0fd007370b9f8fadd.tar.gz
phosphor-networkd-fbafa25b0cbc9e20b9da0cc0fd007370b9f8fadd.zip
ethernet_interface: Clean up object creation
This cleans up the loop and makes sure the interface parsing code updates the local variables for each iteration of the loop. Tested: Built and verified that objects were still being created as expected. Change-Id: I5ba442538f6d2b5a4dc6a8a1261777c0303818d1 Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--ethernet_interface.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index f2ad372..94bfecd 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -57,23 +57,31 @@ EthernetInterface::EthernetInterface(sdbusplus::bus::bus& bus,
}
}
+static IP::Protocol convertFamily(int family)
+{
+ switch (family)
+ {
+ case AF_INET:
+ return IP::Protocol::IPv4;
+ case AF_INET6:
+ return IP::Protocol::IPv6;
+ }
+
+ throw std::invalid_argument("Bad address family");
+}
+
void EthernetInterface::createIPAddressObjects()
{
- std::string gateway;
addrs.clear();
auto addrs = getInterfaceAddrs()[interfaceName()];
- IP::Protocol addressType = IP::Protocol::IPv4;
- IP::AddressOrigin origin = IP::AddressOrigin::Static;
route::Table routingTable;
for (auto& addr : addrs)
{
- if (addr.addrType == AF_INET6)
- {
- addressType = IP::Protocol::IPv6;
- }
+ IP::Protocol addressType = convertFamily(addr.addrType);
+ IP::AddressOrigin origin = IP::AddressOrigin::Static;
if (dHCPEnabled())
{
origin = IP::AddressOrigin::DHCP;
@@ -82,7 +90,7 @@ void EthernetInterface::createIPAddressObjects()
{
origin = IP::AddressOrigin::LinkLocal;
}
- gateway =
+ std::string gateway =
routingTable.getGateway(addr.addrType, addr.ipaddress, addr.prefix);
std::string ipAddressObjectPath = generateObjectPath(
@@ -93,8 +101,6 @@ void EthernetInterface::createIPAddressObjects()
bus, ipAddressObjectPath.c_str(), *this,
addressType, addr.ipaddress, origin,
addr.prefix, gateway));
-
- origin = IP::AddressOrigin::Static;
}
}
OpenPOWER on IntegriCloud