From a59dd96bdc825ec497c128421c61c7a2aa7d9506 Mon Sep 17 00:00:00 2001 From: "amit.vikas.warbhe" Date: Thu, 5 Mar 2026 18:20:43 +0530 Subject: [PATCH] Fix Tap interface restart failure during lifecycle transition on POSIX During lifecycle transition from LC1 to LC9 the Tap Ethernet driver failed to start on POSIX platform. The failure occurred because the stop call for the driver was missing and Tap file descriptor was not closed. Also refactored TapEthernetDriver::start() to avoid double initialization. --- .../main/src/systems/TapEthernetSystem.cpp | 1 + .../src/TapEthernetDriver.cpp | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/executables/referenceApp/platforms/posix/main/src/systems/TapEthernetSystem.cpp b/executables/referenceApp/platforms/posix/main/src/systems/TapEthernetSystem.cpp index 163a88353ca..c2054025fab 100644 --- a/executables/referenceApp/platforms/posix/main/src/systems/TapEthernetSystem.cpp +++ b/executables/referenceApp/platforms/posix/main/src/systems/TapEthernetSystem.cpp @@ -33,6 +33,7 @@ void TapEthernetSystem::run() void TapEthernetSystem::shutdown() { + _driver.stop(); _rxTimeout.cancel(); transitionDone(); } diff --git a/platforms/posix/bsp/tapEthernetDriver/src/TapEthernetDriver.cpp b/platforms/posix/bsp/tapEthernetDriver/src/TapEthernetDriver.cpp index 3ed4d8252a7..1c4de5365f3 100644 --- a/platforms/posix/bsp/tapEthernetDriver/src/TapEthernetDriver.cpp +++ b/platforms/posix/bsp/tapEthernetDriver/src/TapEthernetDriver.cpp @@ -64,11 +64,29 @@ TapEthernetDriver::TapEthernetDriver(::etl::array const macAdd bool TapEthernetDriver::start(char const* const ifName) { - _tapFd = allocTapInterface(ifName); - return _tapFd >= 0; + if (_tapFd >= 0) + { + close(_tapFd); + _tapFd = -1; + } + + int const fd = allocTapInterface(ifName); + if (fd < 0) + { + return false; + } + _tapFd = fd; + return true; } -void TapEthernetDriver::stop() { _tapFd = -1; } +void TapEthernetDriver::stop() +{ + if (_tapFd >= 0) + { + close(_tapFd); + _tapFd = -1; + } +} void TapEthernetDriver::readFrame() {