From 80e9d77ccf7fcc83629b6cf4fed8eb9f707ac966 Mon Sep 17 00:00:00 2001 From: kokilav Date: Tue, 7 Jan 2025 10:21:51 -0600 Subject: [PATCH] Handle IPv4 address for IPv6 Static Default Gateway Error is not thrown when an IPV4 address is provided. This commit addresses the issue by explicitly handling such cases and returning an InvalidArgument error when a IPV4address is configured for IPV6 Static Default Gateway field. Tested By: Verified the test case and ensured proper invalid argument error is thrown. Change-Id: Ibc3d2a77ae56f5b23c3f8bca12409693aa2f3ad9 Signed-off-by: kokilav --- src/ethernet_interface.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp index 9fa874c6..78e92291 100644 --- a/src/ethernet_interface.cpp +++ b/src/ethernet_interface.cpp @@ -553,7 +553,17 @@ ObjectPath EthernetInterface::staticGateway(std::string gateway, std::string route; try { - addr.emplace(stdplus::fromStr(gateway)); + switch (protocolType) + { + case IP::Protocol::IPv4: + addr.emplace(stdplus::fromStr(gateway)); + break; + case IP::Protocol::IPv6: + addr.emplace(stdplus::fromStr(gateway)); + break; + default: + throw std::logic_error("Exhausted protocols"); + } route = gateway; } catch (const std::exception& e)