Skip to content

Instantly share code, notes, and snippets.

@joestringer
Created April 23, 2020 19:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joestringer/9ecf8389e84decc87fb439f7a70f1b9c to your computer and use it in GitHub Desktop.
Save joestringer/9ecf8389e84decc87fb439f7a70f1b9c to your computer and use it in GitHub Desktop.
bpftrace script for gathering stack traces for dropped packets
#!/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) 2020 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