MCPcopy Create free account
hub / github.com/NetSys/bess / CommandAdd

Method CommandAdd

core/modules/bpf.cc:73–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73CommandResponse BPF::CommandAdd(const bess::pb::BPFArg &arg) {
74 for (const auto &f : arg.filters()) {
75 if (f.gate() < 0 || f.gate() >= MAX_GATES) {
76 return CommandFailure(EINVAL, "Invalid gate");
77 }
78
79 bess::utils::Filter filter;
80 filter.priority = f.priority();
81 filter.gate = f.gate();
82 filter.exp = f.filter();
83
84 struct bpf_program il;
85 if (pcap_compile_nopcap(SNAPLEN, DLT_EN10MB, // Ethernet
86 &il, filter.exp.c_str(),
87 1, // optimize (IL only)
88 PCAP_NETMASK_UNKNOWN) == -1) {
89 return CommandFailure(EINVAL, "BPF compilation error");
90 }
91
92#ifdef __x86_64
93 filter.func =
94 bess::utils::bpf_jit_compile(il.bf_insns, il.bf_len, &filter.mmap_size);
95 pcap_freecode(&il);
96 if (!filter.func) {
97 return CommandFailure(ENOMEM, "BPF JIT compilation error");
98 }
99#else
100 filter.il_code = il;
101#endif
102
103 filters_.push_back(filter);
104 }
105
106 std::sort(filters_.begin(), filters_.end(),
107 [](const bess::utils::Filter &a, const bess::utils::Filter &b) {
108 // descending order of priority number
109 return b.priority < a.priority;
110 });
111
112 return CommandSuccess();
113}
114
115CommandResponse BPF::CommandClear(const bess::pb::EmptyArg &) {
116 DeInit();

Callers

nothing calls this directly

Calls 7

CommandFailureFunction · 0.85
bpf_jit_compileFunction · 0.85
CommandSuccessFunction · 0.85
gateMethod · 0.80
priorityMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected