#!/usr/bin/python


from bcc import BPF

# eBPF Program
#########################################
bpf_text = """

int skb_matching(struct __sk_buff *skb)
{
  u8 *cursor = 0;
  bpf_trace_printk("Hello World!\\n");
  // return 0; // drop packet
  return -1; // pass packet

}

"""
#########################################

from ctypes import *

import sys
import socket
import os
import struct

# initialize BPF - load source code from http-parse-simple.c
bpf = BPF(text=bpf_text)

#load eBPF program http_filter of type SOCKET_FILTER into the kernel eBPF vm
#more info about eBPF program types
#http://man7.org/linux/man-pages/man2/bpf.2.html
function_skb_matching = bpf.load_func("skb_matching", BPF.SOCKET_FILTER)


#create raw socket, bind it to eth0
#attach bpf program to socket created
BPF.attach_raw_socket(function_skb_matching, "enp0s2")

bpf.trace_print()
