Skip to content

Instantly share code, notes, and snippets.

@joestringer
Created June 24, 2020 21:34
Show Gist options
  • Save joestringer/4db12af8fef5df3bdfa39d01702313cb to your computer and use it in GitHub Desktop.
Save joestringer/4db12af8fef5df3bdfa39d01702313cb to your computer and use it in GitHub Desktop.
Collect stack traces for dropped packets and print them after ^C
#!/usr/bin/env bpftrace
/*
* skb_free.bt Trace skb drops when the socket is associated with the skb.
* For Linux, uses bpftrace and eBPF.
*
* USAGE: skb_free.bt
*
* Copyright (c) 2019 Joe Stringer.
* Licensed under the Apache License, Version 2.0 (the "License")
*
* 08-May-2019 Joe Stringer created this.
*/
#include <linux/netdevice.h>
#include <linux/skbuff.h>
kprobe:kfree_skb {
$skb = (struct sk_buff *)arg0;
$sk = $skb->sk;
if ($sk) {
@ip4_stacks[kstack] = count();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment