Skip to content

Instantly share code, notes, and snippets.

@chendotjs
Forked from florianl/flow.bt
Last active January 14, 2021 06:05
Show Gist options
  • Save chendotjs/31a13acfba91812161be0a45063b60cc to your computer and use it in GitHub Desktop.
Save chendotjs/31a13acfba91812161be0a45063b60cc to your computer and use it in GitHub Desktop.
simple bpftrace script to print out drop packet
#!/bin/bpftrace
#include <linux/skbuff.h>
#include <linux/ip.h>
BEGIN
{
printf("follow the white rabbit\n");
}
kprobe:kfree_skb
{
$skb = (struct sk_buff*) arg0;
$ipheader = ((struct 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");
}
#!/bin/bpftrace
#include <linux/skbuff.h>
#include <linux/ip.h>
BEGIN
{
printf("follow the white rabbit\n");
}
tracepoint:skb:kfree_skb
{
$skb = (struct sk_buff*) (args->skbaddr);
$ipheader = ((struct 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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment