Skip to content

Commit 5250185

Browse files
authored
Merge pull request #1000 from NetSys/remove_entry
BPF: commands for removing a BPF rule
2 parents bd438ce + 14c532f commit 5250185

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

core/modules/bpf.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
const Commands BPF::cmds = {
5252
{"add", "BPFArg", MODULE_CMD_FUNC(&BPF::CommandAdd),
5353
Command::THREAD_UNSAFE},
54+
{"delete", "BPFArg", MODULE_CMD_FUNC(&BPF::CommandDelete),
55+
Command::THREAD_UNSAFE},
5456
{"clear", "EmptyArg", MODULE_CMD_FUNC(&BPF::CommandClear),
5557
Command::THREAD_UNSAFE},
5658
{"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&BPF::GetInitialArg),
@@ -125,6 +127,24 @@ CommandResponse BPF::CommandAdd(const bess::pb::BPFArg &arg) {
125127
return CommandSuccess();
126128
}
127129

130+
CommandResponse BPF::CommandDelete(const bess::pb::BPFArg &arg) {
131+
for (const auto &f : arg.filters()) {
132+
if (f.gate() < 0 || f.gate() >= MAX_GATES) {
133+
return CommandFailure(EINVAL, "Invalid gate");
134+
}
135+
136+
for (auto i = filters_.begin(); i != filters_.end(); ++i) {
137+
if (f.priority() == i->priority && f.gate() == i->gate &&
138+
f.filter() == i->exp) {
139+
filters_.erase(i);
140+
break;
141+
}
142+
}
143+
}
144+
145+
return CommandSuccess();
146+
}
147+
128148
CommandResponse BPF::CommandClear(const bess::pb::EmptyArg &) {
129149
DeInit();
130150
return CommandSuccess();

core/modules/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class BPF final : public Module {
5454

5555
CommandResponse GetInitialArg(const bess::pb::EmptyArg &);
5656
CommandResponse CommandAdd(const bess::pb::BPFArg &arg);
57+
CommandResponse CommandDelete(const bess::pb::BPFArg &arg);
5758
CommandResponse CommandClear(const bess::pb::EmptyArg &arg);
5859

5960
private:

0 commit comments

Comments
 (0)