Update project
This commit is contained in:
parent
a0336477dd
commit
7be7d5ad81
@ -5,6 +5,12 @@ This project collect some metrics for TCP. For doing that, I use eBPF.
|
||||
For executing and loading the eBPF program and to send data to InfluxDB, you need to install some packages:
|
||||
|
||||
```
|
||||
sudo apt install linux-headers-`uname -r` clang-11 gcc gcc-multilib libbpf-dev libbpfcc bpfcc-tools
|
||||
```
|
||||
|
||||
For installing bpftool command:
|
||||
```
|
||||
sudo apt install linux-tools-common linux-tools-generic
|
||||
```
|
||||
|
||||
## Compile eBPF program
|
||||
|
@ -93,7 +93,8 @@ int main(void){
|
||||
__s16 f = AF_INET;
|
||||
err = bpf_map_update_elem(map_fd_filter_family, &keys, &f, BPF_ANY);
|
||||
|
||||
|
||||
|
||||
printf("Waiting for new packets\n");
|
||||
while(1){
|
||||
// Get the index
|
||||
// and we compare with the local variable
|
||||
|
BIN
main
BIN
main
Binary file not shown.
24
main.c
24
main.c
@ -1,17 +1,31 @@
|
||||
#define BPF_NO_GLOBAL_DATA
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "ic.h"
|
||||
|
||||
int main(int argc, char *argv[], char *argp[]){
|
||||
printf("Hello world\n");
|
||||
char buf[300];
|
||||
char host[64];
|
||||
char account[64];
|
||||
char pwd[64];
|
||||
|
||||
ic_influx_database("192.168.1.68", 8086, "tcp");
|
||||
ic_influx_userpw("admin", "Geta,Fte#");
|
||||
if (argc < 3){
|
||||
printf("Usage: ./main <host> <user> <passwd>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(host, argv[1], 64);
|
||||
memcpy(account, argv[2], 64);
|
||||
memcpy(pwd, argv[3], 64);
|
||||
printf("Host: %s\n", host);
|
||||
printf("Account: %s\n", account);
|
||||
printf("Pwd: %s\n", pwd);
|
||||
|
||||
ic_influx_database(host, 8086, "tcp");
|
||||
ic_influx_userpw(account, pwd);
|
||||
ic_debug(2);
|
||||
|
||||
snprintf(buf, 300, "host=192.168.1.68");
|
||||
snprintf(buf, 300, "host=%s", host);
|
||||
ic_tags(buf);
|
||||
|
||||
ic_measure("tcp_reset");
|
||||
|
22
tcp_server.py
Normal file
22
tcp_server.py
Normal file
@ -0,0 +1,22 @@
|
||||
import socket
|
||||
import struct
|
||||
|
||||
def server(host, port):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
|
||||
l_onoff = 1
|
||||
l_linger = 0
|
||||
s.setsockopt(
|
||||
socket.SOL_SOCKET,
|
||||
socket.SO_LINGER,
|
||||
struct.pack('ii', l_onoff, l_linger)
|
||||
)
|
||||
s.bind(('', port))
|
||||
s.listen(5)
|
||||
|
||||
while 1:
|
||||
skclt, addrclt = s.accept()
|
||||
|
||||
|
||||
skclt.close()
|
||||
|
||||
server('0.0.0.0', 8080)
|
Loading…
Reference in New Issue
Block a user