Skip to content

Instantly share code, notes, and snippets.

@aspsk
aspsk / dump_hash_of_maps.bt
Created September 1, 2023 09:20
A simple bpftrace script to dump a hash_of_maps map (namely, some properties of interest unavailable with bpftool)
#! /usr/bin/env bpftrace
iter:bpf_map {
if (ctx->map->id == $1) {
$inner = ctx->map->inner_map_meta;
printf("map->name: %s\n", ctx->map->name);
printf("inner_map->map_type: %u\n", $inner->map_type);
printf("inner_map->key_size: %u\n", $inner->key_size);
printf("inner_map->value_size: %u\n", $inner->value_size);
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#define __section(X) __attribute__((section(X), used))
int error = 0;
__section("fentry/FUNC")
int BPF_PROG(fentry1)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#! /usr/bin/python3
#
# Very simple bcc tool written as an example. It counts how many
# times mutex_lock/mutex_unlock were called per second. Code is
# kinda based on the vfsstat example by Brendan Gregg, but the actual
# intersection is almost zero, and this one is smp-safe.
#
from bcc import BPF
from ctypes import c_int
@aspsk
aspsk / nolibbpf.c
Created August 7, 2020 17:24
A simple C program illustrating how to create, load, and attach a BPF program using maps without the use of libbpf
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* How to compile and run:
* cc nolibbpf.c -o nolibbpf
* sudo strace -e bpf ./nolibbpf
*
* Then look at progs and maps using bpftool:
* sudo bpftool prog
* sudo bpftool map
#! /usr/bin/env python3
"""
Generates a binary search BPF seccomp program for a blacklist of system call
numbers specified as space-separated integers in stdin.
Example:
$ echo 1 3 6 8 13 | ./generate_bin_search_bpf.py
ld [0]
package main
import (
"log"
"strings"
"flag"
"os"
"text/template"
)
@aspsk
aspsk / Dockerfile
Created January 25, 2019 19:08
Alpine-based docker image with wireguard tools installed
FROM alpine:edge
RUN \
echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \
apk update && \
apk upgrade && \
apk add bash iproute2 openresolv procps && \
apk add wireguard-tools
ENTRYPOINT ["bash"]