From 0afb1b02a520d269ba9bc142b368167b6c2dbae4 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Tue, 17 Dec 2024 19:56:14 +0800 Subject: [PATCH] synchronize eBPF lib header (#1973) * fix: use pipeline menber after pipeline destruction in FlusherSLS * amend --------- Co-authored-by: xunfei --- core/ebpf/SourceManager.cpp | 69 +++++++++++++------------- core/ebpf/SourceManager.h | 2 - core/ebpf/config.cpp | 4 +- core/ebpf/eBPFServer.cpp | 2 - core/ebpf/include/export.h | 20 +------- core/plugin/flusher/sls/FlusherSLS.cpp | 2 +- 6 files changed, 38 insertions(+), 61 deletions(-) diff --git a/core/ebpf/SourceManager.cpp b/core/ebpf/SourceManager.cpp index 3f833af299..caa15f374d 100644 --- a/core/ebpf/SourceManager.cpp +++ b/core/ebpf/SourceManager.cpp @@ -53,11 +53,35 @@ namespace ebpf { } \ res; \ }) - -SourceManager::SourceManager() { -} + +SourceManager::SourceManager() = default; SourceManager::~SourceManager() { + if (!DynamicLibSuccess()) { + return; + } + + for (size_t i = 0; i < mRunning.size(); i++) { + auto& x = mRunning[i]; + if (!x) { + continue; + } + // stop plugin + StopPlugin(static_cast(i)); + } + +#ifdef APSARA_UNIT_TEST_MAIN + return; +#endif + + // call deinit + void* f = mFuncs[(int)ebpf_func::EBPF_DEINIT]; + if (!f) { + return; + } + + auto deinit_f = (deinit_func)f; + deinit_f(); } void SourceManager::Init() { @@ -71,7 +95,7 @@ void SourceManager::Init() { } else { LOG_DEBUG(sLogger, ("running in host mode", "would not set host path prefix ...")); } - + mBinaryPath = GetProcessExecutionDir(); mFullLibName = "lib" + m_lib_name_ + ".so"; for (auto& x : mRunning) { @@ -81,8 +105,8 @@ void SourceManager::Init() { bool SourceManager::LoadDynamicLib(const std::string& lib_name) { if (DynamicLibSuccess()) { - // already load - return true; + // already load + return true; } #ifdef APSARA_UNIT_TEST_MAIN return true; @@ -120,8 +144,8 @@ bool SourceManager::LoadDynamicLib(const std::string& lib_name) { mOffsets[(int)ebpf_func::EBPF_SOCKET_TRACE_UPDATE_CONN_ADDR] = LOAD_UPROBE_OFFSET(mFuncs[(int)ebpf_func::EBPF_SOCKET_TRACE_UPDATE_CONN_ADDR]); // check function load success - for (auto& x : mFuncs) { - if (x == nullptr) return false; + if (std::any_of(mFuncs.begin(), mFuncs.end(), [](auto* x) { return x == nullptr; })) { + return false; } // update meta @@ -135,8 +159,8 @@ bool SourceManager::DynamicLibSuccess() { return true; #endif if (!mLib) return false; - for (auto x : mFuncs) { - if (x == nullptr) return false; + if (!std::all_of(mFuncs.begin(), mFuncs.end(), [](auto* x) { return x != nullptr; })) { + return false; } return true; } @@ -217,31 +241,6 @@ bool SourceManager::UpdatePlugin(nami::PluginType plugin_type, std::unique_ptr(i)); - } - -#ifdef APSARA_UNIT_TEST_MAIN - return true; -#endif - - // call deinit - auto deinit_f = (deinit_func)mFuncs[(int)ebpf_func::EBPF_DEINIT]; - deinit_f(); - return true; -} - bool SourceManager::SuspendPlugin(nami::PluginType plugin_type) { if (!CheckPluginRunning(plugin_type)) { LOG_WARNING(sLogger, ("plugin not started, cannot suspend. type", int(plugin_type))); diff --git a/core/ebpf/SourceManager.h b/core/ebpf/SourceManager.h index 89b12e43e7..77784da6f7 100644 --- a/core/ebpf/SourceManager.h +++ b/core/ebpf/SourceManager.h @@ -53,8 +53,6 @@ class SourceManager { bool SuspendPlugin(nami::PluginType plugin_type); - bool StopAll(); - bool CheckPluginRunning(nami::PluginType plugin_type); SourceManager(); diff --git a/core/ebpf/config.cpp b/core/ebpf/config.cpp index 559b026bfd..bc97f64133 100644 --- a/core/ebpf/config.cpp +++ b/core/ebpf/config.cpp @@ -379,13 +379,13 @@ bool SecurityOptions::Init(SecurityProbeType probeType, case SecurityProbeType::FILE: { nami::SecurityFileFilter thisFileFilter; InitSecurityFileFilter(innerConfig, thisFileFilter, mContext, sName); - thisFilter.emplace(thisFileFilter); + thisFilter.emplace(std::move(thisFileFilter)); break; } case SecurityProbeType::NETWORK: { nami::SecurityNetworkFilter thisNetworkFilter; InitSecurityNetworkFilter(innerConfig, thisNetworkFilter, mContext, sName); - thisFilter.emplace(thisNetworkFilter); + thisFilter.emplace(std::move(thisNetworkFilter)); break; } case SecurityProbeType::PROCESS: { diff --git a/core/ebpf/eBPFServer.cpp b/core/ebpf/eBPFServer.cpp index 9c08757fe8..0654a7f6a3 100644 --- a/core/ebpf/eBPFServer.cpp +++ b/core/ebpf/eBPFServer.cpp @@ -130,7 +130,6 @@ void EnvManager::InitEnvInfo() { LOG_WARNING(sLogger, ("not redhat release, will not start eBPF plugin ...", "")); m310Support = false; - return; } bool eBPFServer::IsSupportedEnv(nami::PluginType type) { @@ -183,7 +182,6 @@ void eBPFServer::Stop() { if (!mInited) return; mInited = false; LOG_INFO(sLogger, ("begin to stop all plugins", "")); - mSourceManager->StopAll(); // destroy source manager mSourceManager.reset(); for (int i = 0; i < int(nami::PluginType::MAX); i ++) { diff --git a/core/ebpf/include/export.h b/core/ebpf/include/export.h index cf8c5c6304..716367f7f5 100644 --- a/core/ebpf/include/export.h +++ b/core/ebpf/include/export.h @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include enum class SecureEventType { SECURE_EVENT_TYPE_SOCKET_SECURE, @@ -238,24 +238,6 @@ struct SecurityNetworkFilter { struct SecurityOption { std::vector call_names_; std::variant filter_; - - SecurityOption() = default; - - SecurityOption(const SecurityOption& other) = default; - - SecurityOption(SecurityOption&& other) noexcept - : call_names_(std::move(other.call_names_)), filter_(std::move(other.filter_)) {} - - SecurityOption& operator=(const SecurityOption& other) = default; - - SecurityOption& operator=(SecurityOption&& other) noexcept { - call_names_ = other.call_names_; - filter_ = other.filter_; - return *this; - } - - ~SecurityOption() {} - bool operator==(const SecurityOption& other) const { return call_names_ == other.call_names_ && filter_ == other.filter_; diff --git a/core/plugin/flusher/sls/FlusherSLS.cpp b/core/plugin/flusher/sls/FlusherSLS.cpp index 67a87aa1ad..e9c0e39861 100644 --- a/core/plugin/flusher/sls/FlusherSLS.cpp +++ b/core/plugin/flusher/sls/FlusherSLS.cpp @@ -697,10 +697,10 @@ void FlusherSLS::OnSendDone(const HttpResponse& response, SenderQueueItem* item) GetProjectConcurrencyLimiter(mProject)->OnSuccess(); GetLogstoreConcurrencyLimiter(mProject, mLogstore)->OnSuccess(); SenderQueueManager::GetInstance()->DecreaseConcurrencyLimiterInSendingCnt(item->mQueueKey); - DealSenderQueueItemAfterSend(item, false); if (mSuccessCnt) { mSuccessCnt->Add(1); } + DealSenderQueueItemAfterSend(item, false); } else { OperationOnFail operation; SendResult sendResult = ConvertErrorCode(slsResponse.mErrorCode);