Skip to content

Commit 6d0b879

Browse files
Revert "Fix base64"
This reverts commit d9fa4df.
1 parent d9fa4df commit 6d0b879

File tree

11 files changed

+48
-468
lines changed

11 files changed

+48
-468
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
**/*.o
2-
**/*.a
1+
*.o
2+
*.a
33
ebpflow.ebpf.enc
44
ebpftest
55
toolebpflow
6-
autom4te.cache/
6+
autom4te.cache/

Makefile.in

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ all: ebpflowexport
2929
container_info.o: container_info.cpp container_info.h
3030
g++ -c $(CFLAGS) container_info.cpp -o container_info.o
3131

32-
libb64.a:
33-
make -C ./libs/b64/src && mv ./libs/b64/src/libb64.a ./libb64.a && make -C ./libs/b64/src clean
34-
3532
libebpfflow.a: ebpf_flow.cpp ebpf_flow.h container_info.o ebpflow.ebpf.enc
36-
g++ -c $(CFLAGS) ebpf_flow.cpp -I./libs/ -o ebpf_flow.o
33+
g++ -c $(CFLAGS) ebpf_flow.cpp -o ebpf_flow.o
3734
ar rvs $@ ebpf_flow.o container_info.o
3835

39-
ebpflowexport: ebpflowexport.cpp libebpfflow.a Makefile libb64.a
40-
g++ $(CFLAGS) ebpflowexport.cpp -o $@ libebpfflow.a libb64.a $(LIBS)
36+
ebpflowexport: ebpflowexport.cpp libebpfflow.a Makefile
37+
g++ $(CFLAGS) ebpflowexport.cpp -o $@ libebpfflow.a $(LIBS)
4138

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

5047
clean:
51-
/bin/rm -f *~ container_info.a libebpfflow.a *.o ebpflow.ebpf.enc libb64.a
48+
/bin/rm -f *~ container_info.a libebpfflow.a *.o ebpflow.ebpf.enc

ebpf_flow.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,52 @@
3434
#include <unistd.h>
3535
#include <linux/version.h>
3636

37-
#define BUFFERSIZE 1024
38-
#include <b64/decode.h>
3937
#include "ebpflow.ebpf.enc"
4038

4139
static ContainerInfo cinfo;
4240

4341
/* ******************************************* */
4442

43+
std::string b64decode(const void* data, const size_t len) {
44+
unsigned char* p = (unsigned char*)data;
45+
int pad = len > 0 && (len % 4 || p[len - 1] == '=');
46+
const size_t L = ((len + 3) / 4 - pad) * 4;
47+
std::string str(L / 4 * 3 + pad, '\0');
48+
const int B64index[256] = {
49+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55,
52+
56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
53+
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0,
54+
0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
55+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
56+
57+
for(size_t i = 0, j = 0; i < L; i += 4) {
58+
int n = B64index[p[i]] << 18 |
59+
B64index[p[i + 1]] << 12 |
60+
B64index[p[i + 2]] << 6 |
61+
B64index[p[i + 3]];
62+
str[j++] = n >> 16;
63+
str[j++] = n >> 8 & 0xFF;
64+
str[j++] = n & 0xFF;
65+
}
66+
67+
if(pad) {
68+
int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12;
69+
str[str.size() - 1] = n >> 16;
70+
71+
if(len > L + 2 && p[L + 2] != '=') {
72+
n |= B64index[p[L + 2]] << 6;
73+
str.push_back(n >> 8 & 0xFF);
74+
}
75+
}
76+
77+
return str;
78+
}
79+
80+
/* ******************************************* */
81+
/* ******************************************* */
82+
4583
static int attachEBPFTracepoint(ebpf::BPF *bpf,
4684
const char *tracepoint, const char *probe_func) {
4785
ebpf::StatusTuple rc = bpf->attach_tracepoint(tracepoint, probe_func);
@@ -79,13 +117,7 @@ extern "C" {
79117
void* init_ebpf_flow(void *priv_ptr, eBPFHandler ebpfHandler,
80118
ebpfRetCode *rc, u_int16_t flags) {
81119
ebpf::BPF *bpf = NULL;
82-
// Decoding ebpf b64 (http://libb64.sourceforge.net)
83-
std::stringstream ebpf_b64_s(ebpf_code);
84-
std::stringstream code_s;
85-
base64::decoder E;
86-
E.decode(ebpf_b64_s, code_s);
87-
std::string code = code_s.str().c_str();
88-
120+
std::string code = b64decode(ebpf_code, strlen(ebpf_code));
89121
ebpf::StatusTuple open_res(0);
90122

91123
// Default value is 0

libs/b64/README.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/b64/cdecode.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

libs/b64/cencode.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

libs/b64/decode.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

libs/b64/encode.h

Lines changed: 0 additions & 77 deletions
This file was deleted.

libs/b64/src/Makefile

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)