Add IPv6 addresses to Dbus
Checking if the interface name is not the same as the previous is based
upon the assumption that your list of interface names (ifa->ifa_name) will
always come back in sorted order of the interface they belong to, i.e.
eth0:
169.172.0.1
128.42.38.7
eth1:
14.243.48.103
fe80::740:61ff:fe74:3eb2
This assumption is wrong since the IP address can come in any order they
please, i.e.
eth0:
169.172.0.1
eth1:
fe80::740:61ff:fe74:3eb2
eth0:
128.42.38.7
eth1:
14.243.48.103
The if condition I removed is looking to see if the interface name is not
equal to the previous interface name, where it would assume it was
rolling over to the next free interface, always leaving you with the
last valid IP in the interface. In my case it was leaving me with only
IPv4 addresses and not including IPv6 addresses.
Tested By: Resetting my network to factory defaults, checking DBUS for
all ipv6 addresses:
dbus-send --system \
--print-reply \
--dest=xyz.openbmc_project.Network \
/xyz/openbmc_project/network/eth0/ipv6\
org.freedesktop.DBus.Introspectable.Introspect
Adding an IPv6 Address:
dbus-send --system \
--dest=xyz.openbmc_project.Network \
--type=method_call \
--print-reply \
/xyz/openbmc_project/network/eth0 \
xyz.openbmc_project.Network.IP.Create.IP \
string:"xyz.openbmc_project.Network.IP.Protocol.IPv6" \
string:"2002:1001:1001:1001:1001:1001:1001:1006" byte:10 \
string:"1001:1001:1001:1001:1001:1001:1001:1001" \
Validating the static IPv6 address appeared by the initial introspect command.
Change-Id: I3b85cecded696c251028accb28448f6e53bd9a7f
Signed-off-by: David Cobbley <david.j.cobbley@linux.intel.com>
diff --git a/util.cpp b/util.cpp
index 4b234f8..c4e989a 100644
--- a/util.cpp
+++ b/util.cpp
@@ -240,7 +240,6 @@
IntfAddrMap getInterfaceAddrs()
{
IntfAddrMap intfMap {};
- AddrList addrList {};
struct ifaddrs* ifaddr = nullptr;
// attempt to fill struct with ifaddrs
@@ -275,14 +274,6 @@
{
continue;
}
- // if the interface name is not same as the previous
- // iteration then add the addr list into
- // the map.
- if (intfName != "" && intfName != std::string(ifa->ifa_name))
- {
- intfMap.emplace(intfName, addrList);
- addrList.clear();
- }
intfName = ifa->ifa_name;
AddrInfo info {};
char ip[INET6_ADDRSTRLEN] = { 0 };
@@ -319,10 +310,9 @@
info.addrType = ifa->ifa_addr->sa_family;
info.ipaddress = ip;
info.prefix = toCidr(info.addrType, std::string(subnetMask));
- addrList.emplace_back(info);
+ intfMap[intfName].push_back(info);
}
}
- intfMap.emplace(intfName, addrList);
return intfMap;
}