Skip to content

Commit

Permalink
Merge pull request #296 from Hackerl/main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkenePan authored Sep 1, 2022
2 parents 60013f4 + 36e4a55 commit 195937c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 280 deletions.
6 changes: 3 additions & 3 deletions rasp/golang/client/smith_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ void from_json(const nlohmann::json &j, MatchRule &matchRule) {
}

void from_json(const nlohmann::json &j, Filter &filter) {
j.at("class_id").get_to(filter.classId);
j.at("class_id").get_to(filter.classID);
j.at("method_id").get_to(filter.methodID);
j.at("include").get_to(filter.include);
j.at("exclude").get_to(filter.exclude);
}

void from_json(const nlohmann::json &j, Block &block) {
j.at("class_id").get_to(block.classId);
j.at("class_id").get_to(block.classID);
j.at("method_id").get_to(block.methodID);
j.at("rules").get_to(block.rules);
}

void from_json(const nlohmann::json &j, Limit &limit) {
j.at("class_id").get_to(limit.classId);
j.at("class_id").get_to(limit.classID);
j.at("method_id").get_to(limit.methodID);
j.at("quota").get_to(limit.quota);
}
Expand Down
6 changes: 3 additions & 3 deletions rasp/golang/client/smith_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct MatchRule {
};

struct Filter {
int classId;
int classID;
int methodID;
std::list<MatchRule> include;
std::list<MatchRule> exclude;
Expand All @@ -85,7 +85,7 @@ struct FilterConfig {
};

struct Block {
int classId;
int classID;
int methodID;
std::list<MatchRule> rules;
};
Expand All @@ -96,7 +96,7 @@ struct BlockConfig {
};

struct Limit {
int classId;
int classID;
int methodID;
int quota;
};
Expand Down
36 changes: 21 additions & 15 deletions rasp/golang/client/smith_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void SmithProbe::onTimer() {

std::lock_guard<std::mutex> _0_(mLimitMutex);

for (const auto &api : GOLANG_API) {
for (const auto &api: GOLANG_API) {
auto it = mLimits.find({api.metadata.classID, api.metadata.methodID});

if (it == mLimits.end()) {
Expand Down Expand Up @@ -127,7 +127,7 @@ void SmithProbe::onMessage(const SmithMessage &message) {
mHeartbeat.filter = config.uuid;

for (const auto &filter: config.filters)
mFilters.insert({{filter.classId, filter.methodID}, filter});
mFilters.insert({{filter.classID, filter.methodID}, filter});

break;
}
Expand All @@ -139,38 +139,44 @@ void SmithProbe::onMessage(const SmithMessage &message) {

mHeartbeat.block = config.uuid;

for (const auto &block : config.blocks) {
auto it = std::find_if(GOLANG_API.begin(), GOLANG_API.end(), [&](const auto &r) {
return r.metadata.classID == block.classId && r.metadata.methodID == block.methodID;
for (const auto &api: GOLANG_API) {
z_rwlock_write_lock(&api.metadata.config->lock);

auto it = std::find_if(config.blocks.begin(), config.blocks.end(), [&](const auto &block) {
return block.classID == api.metadata.classID && block.methodID == api.metadata.methodID;
});

if (it == GOLANG_API.end())
if (it == config.blocks.end()) {
api.metadata.config->policies.count = 0;
z_rwlock_write_unlock(&api.metadata.config->lock);
continue;
}

if (block.rules.size() > BLOCK_RULE_COUNT) {
if (it->rules.size() > BLOCK_RULE_COUNT) {
LOG_WARNING("block rule size limit");

api.metadata.config->policies.count = 0;
z_rwlock_write_unlock(&api.metadata.config->lock);

continue;
}

z_rwlock_write_lock(&it->metadata.config->lock);

int count = 0;

for (const auto &r : block.rules) {
for (const auto &r: it->rules) {
if (r.regex.length() >= BLOCK_RULE_LENGTH) {
LOG_WARNING("block rule regex length limit");
continue;
}

auto rule = it->metadata.config->policies.rules + count++;
auto rule = api.metadata.config->policies.rules + count++;

rule->first = r.index;
strcpy(rule->second, r.regex.c_str());
}

it->metadata.config->policies.count = count;

z_rwlock_write_unlock(&it->metadata.config->lock);
api.metadata.config->policies.count = count;
z_rwlock_write_unlock(&api.metadata.config->lock);
}

break;
Expand All @@ -187,7 +193,7 @@ void SmithProbe::onMessage(const SmithMessage &message) {
mHeartbeat.limit = config.uuid;

for (const auto &limit: config.limits)
mLimits.insert({{limit.classId, limit.methodID}, limit.quota});
mLimits.insert({{limit.classID, limit.methodID}, limit.quota});

break;
}
Expand Down
227 changes: 0 additions & 227 deletions rasp/golang/go/api/smith.h

This file was deleted.

6 changes: 3 additions & 3 deletions rasp/php/client/smith_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ void from_json(const nlohmann::json &j, MatchRule &matchRule) {
}

void from_json(const nlohmann::json &j, Filter &filter) {
j.at("class_id").get_to(filter.classId);
j.at("class_id").get_to(filter.classID);
j.at("method_id").get_to(filter.methodID);
j.at("include").get_to(filter.include);
j.at("exclude").get_to(filter.exclude);
}

void from_json(const nlohmann::json &j, Block &block) {
j.at("class_id").get_to(block.classId);
j.at("class_id").get_to(block.classID);
j.at("method_id").get_to(block.methodID);
j.at("rules").get_to(block.rules);
}

void from_json(const nlohmann::json &j, Limit &limit) {
j.at("class_id").get_to(limit.classId);
j.at("class_id").get_to(limit.classID);
j.at("method_id").get_to(limit.methodID);
j.at("quota").get_to(limit.quota);
}
Expand Down
Loading

0 comments on commit 195937c

Please sign in to comment.