Skip to content

Instantly share code, notes, and snippets.

@florianl
Created September 14, 2019 12:32
Show Gist options
  • Save florianl/621521c431029bb2b85ec113b031e1fe to your computer and use it in GitHub Desktop.
Save florianl/621521c431029bb2b85ec113b031e1fe to your computer and use it in GitHub Desktop.
simple bpftrace script to print out forwarding traffic
#!/bin/bpftrace
#include <linux/skbuff.h>
#include <linux/ip.h>
BEGIN
{
printf("follow the white rabbit\n");
}
kprobe:netif_rx
{
$skb = (struct sk_buff*) arg0;
$ipheader = ((iphdr *) ($skb->head + $skb->network_header));
$version = ($ipheader->version) >>4;
printf("[%d] %d\t%s > %s\n", $version, $ipheader->protocol,
ntop($ipheader->saddr), ntop($ipheader->daddr));
}
END
{
printf("good bye, Alice\n");
}
@jschwinger233
Copy link

iphdr * should be struct iphdr *

@florianl
Copy link
Author

This gist is not maintend and therefore I don't recomment using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment