ipaddress: Remove obsolete gateway parameter
Change-Id: I0eb7c84951c2277a5c69fb35eb989e7e19bd897d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 3f1743c..fc1e6b0 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -184,16 +184,14 @@
{
origin = IP::AddressOrigin::LinkLocal;
}
- // Obsolete parameter
- std::string gateway = "";
- std::string ipAddressObjectPath = generateObjectPath(
- addressType, address, addr.prefix, gateway, origin);
+ auto ipAddressObjectPath =
+ generateObjectPath(addressType, address, addr.prefix, origin);
this->addrs.insert_or_assign(
- address, std::make_unique<IPAddress>(
- bus, ipAddressObjectPath.c_str(), *this, addressType,
- address, origin, addr.prefix, gateway));
+ address, std::make_unique<IPAddress>(bus, ipAddressObjectPath,
+ *this, addressType, address,
+ origin, addr.prefix));
}
}
@@ -211,12 +209,12 @@
{
continue;
}
- std::string ip = toString(neighbor.address);
- std::string mac = mac_address::toString(*neighbor.mac);
- std::string objectPath = generateStaticNeighborObjectPath(ip, mac);
+ auto ip = toString(neighbor.address);
+ auto mac = mac_address::toString(*neighbor.mac);
+ auto objectPath = generateStaticNeighborObjectPath(ip, mac);
staticNeighbors.emplace(
- ip, std::make_unique<Neighbor>(bus, objectPath.c_str(), *this, ip,
- mac, Neighbor::State::Permanent));
+ ip, std::make_unique<Neighbor>(bus, objectPath, *this, ip, mac,
+ Neighbor::State::Permanent));
}
}
@@ -232,7 +230,7 @@
}
ObjectPath EthernetInterface::ip(IP::Protocol protType, std::string ipaddress,
- uint8_t prefixLength, std::string gateway)
+ uint8_t prefixLength, std::string)
{
if (dhcpIsEnabled(protType))
{
@@ -264,9 +262,6 @@
Argument::ARGUMENT_VALUE(ipaddress.c_str()));
}
- // Gateway is an obsolete parameter
- gateway = "";
-
if (!isValidPrefix(addressFamily, prefixLength))
{
log<level::ERR>("PrefixLength is not correct "),
@@ -276,12 +271,12 @@
Argument::ARGUMENT_VALUE(std::to_string(prefixLength).c_str()));
}
- std::string objectPath =
- generateObjectPath(protType, ipaddress, prefixLength, gateway, origin);
+ auto objectPath =
+ generateObjectPath(protType, ipaddress, prefixLength, origin);
this->addrs.insert_or_assign(
ipaddress,
- std::make_unique<IPAddress>(bus, objectPath.c_str(), *this, protType,
- ipaddress, origin, prefixLength, gateway));
+ std::make_unique<IPAddress>(bus, objectPath, *this, protType, ipaddress,
+ origin, prefixLength));
writeConfigurationFile();
manager.reloadConfigs();
@@ -307,11 +302,10 @@
Argument::ARGUMENT_VALUE(macAddress.c_str()));
}
- std::string objectPath =
- generateStaticNeighborObjectPath(ipAddress, macAddress);
+ auto objectPath = generateStaticNeighborObjectPath(ipAddress, macAddress);
staticNeighbors.emplace(
ipAddress,
- std::make_unique<Neighbor>(bus, objectPath.c_str(), *this, ipAddress,
+ std::make_unique<Neighbor>(bus, objectPath, *this, ipAddress,
macAddress, Neighbor::State::Permanent));
writeConfigurationFile();
@@ -388,13 +382,11 @@
std::string EthernetInterface::generateId(std::string_view ipaddress,
uint8_t prefixLength,
- std::string_view gateway,
std::string_view origin)
{
std::stringstream hexId;
std::string hashString = std::string(ipaddress);
hashString += std::to_string(prefixLength);
- hashString += gateway;
hashString += origin;
// Only want 8 hex digits.
@@ -487,7 +479,7 @@
std::string EthernetInterface::generateObjectPath(
IP::Protocol addressType, std::string_view ipaddress, uint8_t prefixLength,
- std::string_view gateway, IP::AddressOrigin origin) const
+ IP::AddressOrigin origin) const
{
std::string type = convertForMessage(addressType);
type = type.substr(type.rfind('.') + 1);
@@ -497,7 +489,7 @@
objectPath /= objPath;
objectPath /= type;
objectPath /=
- generateId(ipaddress, prefixLength, gateway, convertForMessage(origin));
+ generateId(ipaddress, prefixLength, convertForMessage(origin));
return objectPath.string();
}
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index f726f48..deada56 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -96,11 +96,10 @@
* @param[in] addressType - Type of ip address.
* @param[in] ipAddress- IP address.
* @param[in] prefixLength - Length of prefix.
- * @param[in] gateway - Gateway ip address.
*/
ObjectPath ip(IP::Protocol addressType, std::string ipAddress,
- uint8_t prefixLength, std::string gateway) override;
+ uint8_t prefixLength, std::string) override;
/** @brief Function to create static neighbor dbus object.
* @param[in] ipAddress - IP address.
@@ -259,7 +258,6 @@
* @param[in] addressType - Type of ip address.
* @param[in] ipAddress - IP address.
* @param[in] prefixLength - Length of prefix.
- * @param[in] gateway - Gateway address.
* @param[in] origin - The origin entry of the IP::Address
* @return path of the address object.
@@ -268,25 +266,21 @@
std::string generateObjectPath(IP::Protocol addressType,
std::string_view ipAddress,
uint8_t prefixLength,
- std::string_view gateway,
IP::AddressOrigin origin) const;
std::string
generateStaticNeighborObjectPath(std::string_view ipAddress,
std::string_view macAddress) const;
- /** @brief generates the id by doing hash of ipAddress,
- * prefixlength and the gateway.
+ /** @brief generates the id by doing hash of ipAddress and prefixLength
* @param[in] ipAddress - IP address.
* @param[in] prefixLength - Length of prefix.
- * @param[in] gateway - Gateway address.
* @param[in] origin - The string of the address origin
* @return hash string.
*/
static std::string generateId(std::string_view ipAddress,
uint8_t prefixLength,
- std::string_view gateway,
std::string_view origin);
/** @brief generates the id by doing hash of ipAddress
diff --git a/src/ipaddress.cpp b/src/ipaddress.cpp
index ac9c0b0..6aebc94 100644
--- a/src/ipaddress.cpp
+++ b/src/ipaddress.cpp
@@ -38,17 +38,16 @@
using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
-IPAddress::IPAddress(sdbusplus::bus_t& bus, const char* objPath,
+IPAddress::IPAddress(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
EthernetInterface& parent, IP::Protocol type,
- const std::string& ipaddress, IP::AddressOrigin origin,
- uint8_t prefixLength, const std::string& gateway) :
- IPIfaces(bus, objPath, IPIfaces::action::defer_emit),
+ std::string_view ipaddress, IP::AddressOrigin origin,
+ uint8_t prefixLength) :
+ IPIfaces(bus, objPath.c_str(), IPIfaces::action::defer_emit),
parent(parent)
{
- IP::address(ipaddress);
+ IP::address(std::string(ipaddress));
IP::prefixLength(prefixLength);
- IP::gateway(gateway);
IP::type(type);
IP::origin(origin);
diff --git a/src/ipaddress.hpp b/src/ipaddress.hpp
index b46d64e..e7bf479 100644
--- a/src/ipaddress.hpp
+++ b/src/ipaddress.hpp
@@ -7,7 +7,7 @@
#include <optional>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include <string>
+#include <stdplus/zstring.hpp>
#include <string_view>
#include <vector>
#include <xyz/openbmc_project/Network/IP/server.hpp>
@@ -74,12 +74,11 @@
* @param[in] ipAddress - ipadress.
* @param[in] origin - origin of ipaddress(dhcp/static/SLAAC/LinkLocal).
* @param[in] prefixLength - Length of prefix.
- * @param[in] gateway - gateway address.
*/
- IPAddress(sdbusplus::bus_t& bus, const char* objPath,
+ IPAddress(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
EthernetInterface& parent, IP::Protocol type,
- const std::string& ipAddress, IP::AddressOrigin origin,
- uint8_t prefixLength, const std::string& gateway);
+ std::string_view ipAddress, IP::AddressOrigin origin,
+ uint8_t prefixLength);
std::string address(std::string ipAddress) override;
uint8_t prefixLength(uint8_t) override;
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index 0775756..4f2b204 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -74,19 +74,18 @@
}
std::string getObjectPath(const std::string& ipaddress, uint8_t subnetMask,
- const std::string& gateway,
IP::AddressOrigin origin)
{
IP::Protocol addressType = IP::Protocol::IPv4;
return interface.generateObjectPath(addressType, ipaddress, subnetMask,
- gateway, origin);
+ origin);
}
void createIPObject(IP::Protocol addressType, const std::string& ipaddress,
- uint8_t subnetMask, const std::string& gateway)
+ uint8_t subnetMask)
{
- interface.ip(addressType, ipaddress, subnetMask, gateway);
+ interface.ip(addressType, ipaddress, subnetMask, "");
}
};
@@ -99,15 +98,15 @@
TEST_F(TestEthernetInterface, AddIPAddress)
{
IP::Protocol addressType = IP::Protocol::IPv4;
- createIPObject(addressType, "10.10.10.10", 16, "10.10.10.1");
+ createIPObject(addressType, "10.10.10.10", 16);
EXPECT_EQ(true, isIPObjectExist("10.10.10.10"));
}
TEST_F(TestEthernetInterface, AddMultipleAddress)
{
IP::Protocol addressType = IP::Protocol::IPv4;
- createIPObject(addressType, "10.10.10.10", 16, "10.10.10.1");
- createIPObject(addressType, "20.20.20.20", 16, "20.20.20.1");
+ createIPObject(addressType, "10.10.10.10", 16);
+ createIPObject(addressType, "20.20.20.20", 16);
EXPECT_EQ(true, isIPObjectExist("10.10.10.10"));
EXPECT_EQ(true, isIPObjectExist("20.20.20.20"));
}
@@ -115,8 +114,8 @@
TEST_F(TestEthernetInterface, DeleteIPAddress)
{
IP::Protocol addressType = IP::Protocol::IPv4;
- createIPObject(addressType, "10.10.10.10", 16, "10.10.10.1");
- createIPObject(addressType, "20.20.20.20", 16, "20.20.20.1");
+ createIPObject(addressType, "10.10.10.10", 16);
+ createIPObject(addressType, "20.20.20.20", 16);
deleteIPObject("10.10.10.10");
EXPECT_EQ(false, isIPObjectExist("10.10.10.10"));
EXPECT_EQ(true, isIPObjectExist("20.20.20.20"));
@@ -131,7 +130,6 @@
{
std::string ipaddress = "10.10.10.10";
uint8_t prefix = 16;
- std::string gateway = "10.10.10.1";
IP::AddressOrigin origin = IP::AddressOrigin::Static;
std::string expectedObjectPath = "/xyz/openbmc_test/network/test0/ipv4/";
@@ -139,18 +137,15 @@
std::string hashString = ipaddress;
hashString += std::to_string(prefix);
- hashString += gateway;
hashString += convertForMessage(origin);
hexId << std::hex << ((std::hash<std::string>{}(hashString)) & 0xFFFFFFFF);
expectedObjectPath += hexId.str();
- EXPECT_EQ(expectedObjectPath,
- getObjectPath(ipaddress, prefix, gateway, origin));
+ EXPECT_EQ(expectedObjectPath, getObjectPath(ipaddress, prefix, origin));
origin = IP::AddressOrigin::DHCP;
- EXPECT_NE(expectedObjectPath,
- getObjectPath(ipaddress, prefix, gateway, origin));
+ EXPECT_NE(expectedObjectPath, getObjectPath(ipaddress, prefix, origin));
}
TEST_F(TestEthernetInterface, addStaticNameServers)