Skip to content

Commit

Permalink
Revert "Fix base64"
Browse files Browse the repository at this point in the history
This reverts commit d9fa4df.
  • Loading branch information
simonemainardi committed Nov 22, 2019
1 parent d9fa4df commit 6d0b879
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 468 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/*.o
**/*.a
*.o
*.a
ebpflow.ebpf.enc
ebpftest
toolebpflow
autom4te.cache/
autom4te.cache/
11 changes: 4 additions & 7 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ all: ebpflowexport
container_info.o: container_info.cpp container_info.h
g++ -c $(CFLAGS) container_info.cpp -o container_info.o

libb64.a:
make -C ./libs/b64/src && mv ./libs/b64/src/libb64.a ./libb64.a && make -C ./libs/b64/src clean

libebpfflow.a: ebpf_flow.cpp ebpf_flow.h container_info.o ebpflow.ebpf.enc
g++ -c $(CFLAGS) ebpf_flow.cpp -I./libs/ -o ebpf_flow.o
g++ -c $(CFLAGS) ebpf_flow.cpp -o ebpf_flow.o
ar rvs $@ ebpf_flow.o container_info.o

ebpflowexport: ebpflowexport.cpp libebpfflow.a Makefile libb64.a
g++ $(CFLAGS) ebpflowexport.cpp -o $@ libebpfflow.a libb64.a $(LIBS)
ebpflowexport: ebpflowexport.cpp libebpfflow.a Makefile
g++ $(CFLAGS) ebpflowexport.cpp -o $@ libebpfflow.a $(LIBS)

ebpflow.ebpf.enc: ebpflow_header.ebpf ebpf_types.h ebpflow_code.ebpf Makefile
echo -n "const char * ebpf_code = R\"(" > ebpflow.ebpf.enc
Expand All @@ -48,4 +45,4 @@ go_ebpflowexport: ebpflowexport.go Makefile libebpfflow.a
go build -o go_ebpflowexport ebpflowexport.go

clean:
/bin/rm -f *~ container_info.a libebpfflow.a *.o ebpflow.ebpf.enc libb64.a
/bin/rm -f *~ container_info.a libebpfflow.a *.o ebpflow.ebpf.enc
50 changes: 41 additions & 9 deletions ebpf_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,52 @@
#include <unistd.h>
#include <linux/version.h>

#define BUFFERSIZE 1024
#include <b64/decode.h>
#include "ebpflow.ebpf.enc"

static ContainerInfo cinfo;

/* ******************************************* */

std::string b64decode(const void* data, const size_t len) {
unsigned char* p = (unsigned char*)data;
int pad = len > 0 && (len % 4 || p[len - 1] == '=');
const size_t L = ((len + 3) / 4 - pad) * 4;
std::string str(L / 4 * 3 + pad, '\0');
const int B64index[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0,
0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };

for(size_t i = 0, j = 0; i < L; i += 4) {
int n = B64index[p[i]] << 18 |
B64index[p[i + 1]] << 12 |
B64index[p[i + 2]] << 6 |
B64index[p[i + 3]];
str[j++] = n >> 16;
str[j++] = n >> 8 & 0xFF;
str[j++] = n & 0xFF;
}

if(pad) {
int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12;
str[str.size() - 1] = n >> 16;

if(len > L + 2 && p[L + 2] != '=') {
n |= B64index[p[L + 2]] << 6;
str.push_back(n >> 8 & 0xFF);
}
}

return str;
}

/* ******************************************* */
/* ******************************************* */

static int attachEBPFTracepoint(ebpf::BPF *bpf,
const char *tracepoint, const char *probe_func) {
ebpf::StatusTuple rc = bpf->attach_tracepoint(tracepoint, probe_func);
Expand Down Expand Up @@ -79,13 +117,7 @@ extern "C" {
void* init_ebpf_flow(void *priv_ptr, eBPFHandler ebpfHandler,
ebpfRetCode *rc, u_int16_t flags) {
ebpf::BPF *bpf = NULL;
// Decoding ebpf b64 (http://libb64.sourceforge.net)
std::stringstream ebpf_b64_s(ebpf_code);
std::stringstream code_s;
base64::decoder E;
E.decode(ebpf_b64_s, code_s);
std::string code = code_s.str().c_str();

std::string code = b64decode(ebpf_code, strlen(ebpf_code));
ebpf::StatusTuple open_res(0);

// Default value is 0
Expand Down
1 change: 0 additions & 1 deletion libs/b64/README.txt

This file was deleted.

29 changes: 0 additions & 29 deletions libs/b64/cdecode.h

This file was deleted.

32 changes: 0 additions & 32 deletions libs/b64/cencode.h

This file was deleted.

70 changes: 0 additions & 70 deletions libs/b64/decode.h

This file was deleted.

77 changes: 0 additions & 77 deletions libs/b64/encode.h

This file was deleted.

43 changes: 0 additions & 43 deletions libs/b64/src/Makefile

This file was deleted.

Loading

0 comments on commit 6d0b879

Please sign in to comment.