Skip to content

Instantly share code, notes, and snippets.

@florianl
florianl / nvidia-smi.bt
Created January 12, 2024 07:52
Listen to nvidia-smi ioctl commands
#!/usr/bin/env bpftrace
/*
* sudo bpftrace nvidia-smi.bt -o nvidia-smi.$(date +%s%N | cut -b1-13).out
*
* Dump is limited to 64 byte as enforced by BPFTRACE_STRLEN and stack size limitations.
*/
BEGIN
{
printf("Tracing nvidia-smi ioctl calls ... Hit Ctrl-C to end.\n\n");
@florianl
florianl / lookups.go
Created June 28, 2022 18:58
continous map lookups
package main
import (
"fmt"
"math/rand"
"os"
"unsafe"
"github.com/cilium/ebpf"
)
@florianl
florianl / main.go
Created January 24, 2022 20:10
eBPF program on perf event in Go
package main
import (
"errors"
"log"
"os"
"os/signal"
"strconv"
"syscall"
@florianl
florianl / xdp-example.go
Created November 11, 2021 20:21
xdp ebpf example
package main
import (
"fmt"
"log"
"net"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/asm"
"github.com/cilium/ebpf/rlimit"
@florianl
florianl / fibonacci.go
Created February 24, 2020 19:20
Calculate the fibonacci number in three different ways
package main
import (
"math/rand"
"time"
)
//go:noinline
func fibonacciRecursive(n uint32) uint32 {
if n < 2 {
@florianl
florianl / dlopen.bt
Last active February 5, 2020 20:12
Tracing potential dlopen() usage
#!/usr/bin/env bpftrace
/*
* dlopen.bt reports potential usage of dlopen() usage which is a combination
* of a open syscall followed by mmap syscall
*/
BEGIN
{
printf("Tracing potential dlopen() usage... Hit Ctrl-C to end.\n");
@florianl
florianl / flow.bt
Created September 14, 2019 12:32
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");
}
package main
import (
"fmt"
"net"
"os"
"time"
bpf "github.com/iovisor/gobpf/bcc"
"github.com/florianl/go-tc"
@florianl
florianl / netlink-attribute-unwrap.go
Created August 14, 2019 18:20
inspect netlink attributes
@florianl
florianl / gist:8269072
Created January 5, 2014 14:48
Output of route -6
How it is now:
$ ./route -6
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref Use If
::1/128 :: U 256 0 0 lo
2001:590:3401::3f8d:c211/128 fe80::200:24ff:fece:8965 UG 1 0 0 em1
2001:668:108:9::4d43:60d8/128 fe80::200:24ff:fece:8965 UG 1 0 0 em1
2001:67c:26f4:224::229/128 fe80::200:24ff:fece:8965 UG 1 3 3 em1
2001:67c:26f4:224::231/128 fe80::200:24ff:fece:8965 UG 1 0 0 em1