ebpf-networking
ebpf-networking copied to clipboard
network.py actually contains C source
Hi! I just stumbled on this awesome repo after watching the eBPF Day presentation!
It looks like the network.py
file may have been mistakenly added to the repo with the same contents as the network.c
file:
┌─╼[~/ebpf-networking] [main]
└────╼ diff network.c network.py | wc
0 0 0
Just figured I'd bring this to your attention in case there are other folks who want to follow along with the example here.
Thanks!
yeah just stumbled on that - https://github.com/lizrice/ebpf-networking/blob/main/network.py
import os
from time import sleep
from pyroute2 import IPRoute
from bcc import BPF
interface = "eth0"
b = BPF(src_file="network.c")
b.attach_kprobe(event="tcp_v4_connect", fn_name="tcpconnect")
print("Ready")
try:
b.trace_print()
except KeyboardInterrupt:
print("unloading")
exit()
import os
import socket
from time import sleep
from pyroute2 import IPRoute
from bcc import BPF
interface = "eth0"
b = BPF(src_file="network.c")
f = b.load_func("socket_filter", BPF.SOCKET_FILTER)
BPF.attach_raw_socket(f, interface)
fd = f.sock
sock = socket.fromfd(fd, socket.PF_PACKET, socket.SOCK_RAW, socket.IPPROTO_IP)
sock.setblocking(True)
print("Ready")
try:
while True:
packet_str = os.read(fd, 4096)
print("Userspace Data: {}".format(packet_str))
except KeyboardInterrupt:
print("unloading")
exit()
you can try those, untested but the code is straightforward
This is helpful!