Skip to content
Permalink
Browse files

Revert "Fix base64"

This reverts commit d9fa4df.
  • Loading branch information
simonemainardi committed Nov 22, 2019
1 parent d9fa4df commit 6d0b87924ea6788bbe77f57b8f704f9dfb3fdbff
Showing with 48 additions and 468 deletions.
  1. +3 −3 .gitignore
  2. +4 −7 Makefile.in
  3. +41 −9 ebpf_flow.cpp
  4. +0 −1 libs/b64/README.txt
  5. +0 −29 libs/b64/cdecode.h
  6. +0 −32 libs/b64/cencode.h
  7. +0 −70 libs/b64/decode.h
  8. +0 −77 libs/b64/encode.h
  9. +0 −43 libs/b64/src/Makefile
  10. +0 −88 libs/b64/src/cdecode.c
  11. +0 −109 libs/b64/src/cencode.c
@@ -1,6 +1,6 @@
**/*.o
**/*.a
*.o
*.a
ebpflow.ebpf.enc
ebpftest
toolebpflow
autom4te.cache/
autom4te.cache/
@@ -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
@@ -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
@@ -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);
@@ -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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6d0b879

Please sign in to comment.
You can’t perform that action at this time.