Skip to content

Commit

Permalink
synchronize eBPF lib header (#1973)
Browse files Browse the repository at this point in the history
* fix: use pipeline menber after pipeline destruction in FlusherSLS

* amend

---------

Co-authored-by: xunfei <yt348264@alibaba-inc.com>
  • Loading branch information
yyuuttaaoo and xunfei authored Dec 17, 2024
1 parent 3906305 commit 0afb1b0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 61 deletions.
69 changes: 34 additions & 35 deletions core/ebpf/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nami::PluginType>(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() {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -217,31 +241,6 @@ bool SourceManager::UpdatePlugin(nami::PluginType plugin_type, std::unique_ptr<n
return !res;
}

bool SourceManager::StopAll() {
if (!DynamicLibSuccess()) {
LOG_WARNING(sLogger, ("dynamic lib not load, just exit", "need check"));
return true;
}

for (size_t i = 0; i < mRunning.size(); i ++) {
auto& x = mRunning[i];
if (!x) {
continue;
}
// stop plugin
StopPlugin(static_cast<nami::PluginType>(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)));
Expand Down
2 changes: 0 additions & 2 deletions core/ebpf/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class SourceManager {

bool SuspendPlugin(nami::PluginType plugin_type);

bool StopAll();

bool CheckPluginRunning(nami::PluginType plugin_type);

SourceManager();
Expand Down
4 changes: 2 additions & 2 deletions core/ebpf/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ bool SecurityOptions::Init(SecurityProbeType probeType,
case SecurityProbeType::FILE: {
nami::SecurityFileFilter thisFileFilter;
InitSecurityFileFilter(innerConfig, thisFileFilter, mContext, sName);
thisFilter.emplace<nami::SecurityFileFilter>(thisFileFilter);
thisFilter.emplace<nami::SecurityFileFilter>(std::move(thisFileFilter));
break;
}
case SecurityProbeType::NETWORK: {
nami::SecurityNetworkFilter thisNetworkFilter;
InitSecurityNetworkFilter(innerConfig, thisNetworkFilter, mContext, sName);
thisFilter.emplace<nami::SecurityNetworkFilter>(thisNetworkFilter);
thisFilter.emplace<nami::SecurityNetworkFilter>(std::move(thisNetworkFilter));
break;
}
case SecurityProbeType::PROCESS: {
Expand Down
2 changes: 0 additions & 2 deletions core/ebpf/eBPFServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ++) {
Expand Down
20 changes: 1 addition & 19 deletions core/ebpf/include/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <memory>
#include <string>
#include <variant>
#include <future>
#include <vector>
#include <future>

enum class SecureEventType {
SECURE_EVENT_TYPE_SOCKET_SECURE,
Expand Down Expand Up @@ -238,24 +238,6 @@ struct SecurityNetworkFilter {
struct SecurityOption {
std::vector<std::string> call_names_;
std::variant<std::monostate, SecurityFileFilter, SecurityNetworkFilter> 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_;
Expand Down
2 changes: 1 addition & 1 deletion core/plugin/flusher/sls/FlusherSLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0afb1b0

Please sign in to comment.