Skip to content

Instantly share code, notes, and snippets.

@majek
majek / slow_network.sh
Created Jul 8, 2022
Bash script to selectively slow down traffic to given IP's - using tc netem
View slow_network.sh
#!/bin/bash
set -e
set -u
set -o pipefail
IFACE="lo"
LATENCY=200
CLEAN=""
IPS=()
@majek
majek / Makefile
Created Jun 17, 2022
repro_access_to_stack_error_bpf
View Makefile
.PHONY: repro
repro:
$(CLANG) -Wall -Wextra -O2 --target=bpf -c -g \
repro.bpf.c \
-o repro.bpf.o
bpftool gen skeleton repro.bpf.o > repro.bpf.skel.h
$(CLANG) -Wall -fno-omit-frame-pointer -Wextra -O2 -g \
repro.c \
-lbpf \
-lelf \
View plot_qa.gnuplot
#!/usr/bin/gnuplot -c
set terminal pngcairo transparent enhanced linewidth 2 font 'Helvetica,15' size 2000, 1200 background rgb 'white'
set xtics nomirror rotate by -45
set ytics nomirror
set grid ytics
set grid xtics
set ylabel "Bytes"
set datafile separator ","
set output ARG3
set key autotitle columnheader outside
@majek
majek / compile-kernel.sh
Created Feb 1, 2021
repro for kvm gvisor
View compile-kernel.sh
rm .config
make tinyconfig
make kvm_guest.config
make kvmconfig
./scripts/config \
-e EARLY_PRINTK \
-e 64BIT \
-e BPF -d EMBEDDED -d EXPERT \
-e INOTIFY_USER
@majek
majek / echo.go
Created Dec 3, 2020
echo server in go
View echo.go
package main
import (
"flag"
"fmt"
"net"
"os"
"strings"
)
View test_tcp_halfopen.py
import atexit
import os
import socket
import subprocess
import shlex
import time
import signal
tcpdump_bin = os.popen('which tcpdump').read().strip()
ss_bin = os.popen('which ss').read().strip()
@majek
majek / netstack4netns.go
Last active Apr 16, 2021
netstack from gvisor 4 netns
View netstack4netns.go
package main
import (
"flag"
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"runtime"
@majek
majek / gvtcpdump.c
Created Dec 17, 2019
gVisor tcpdump
View gvtcpdump.c
/*
* Usage: ./gvtcpdump | tcpdump -n -r -
*/
#include <arpa/inet.h>
#include <errno.h>
#include <error.h>
#include <getopt.h>
#include <linux/filter.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
@majek
majek / rungvisor.sh
Last active Dec 16, 2019
gvisor performance with slirp4netns
View rungvisor.sh
#!/bin/bash
set -e
# Dependencies:
# apt install jq
if [ ]; then
GVFLAGS=--network=host
FILESZ=1G
else
FILESZ=16M
@majek
majek / common.h
Last active Aug 20, 2020
conntrack experiment
View common.h
#define PFATAL(x...) \
do { \
fprintf(stderr, "[-] SYSTEM ERROR : " x); \
fprintf(stderr, "\n\tLocation : %s(), %s:%u\n", __FUNCTION__, __FILE__, \
__LINE__); \
perror(" OS message "); \
fprintf(stderr, "\n"); \
exit(EXIT_FAILURE); \
} while (0)