Skip to content

Instantly share code, notes, and snippets.

@majek
majek / manage_mptcp_endpoint.sh
Created August 18, 2023 10:38
Manage `ip mptcp endpoint` state on linux
#!/bin/bash
set -e
echo "[+] Clearling old mptcp endpoints"
for i in `ip mptcp endpoint show|cut -d " " -f 3`; do
ip mptcp endpoint delete id $i;
done
declare -A OLD
@majek
majek / slow_network.sh
Created July 8, 2022 08:52
Bash script to selectively slow down traffic to given IP's - using tc netem
#!/bin/bash
set -e
set -u
set -o pipefail
IFACE="lo"
LATENCY=200
CLEAN=""
IPS=()
@majek
majek / Makefile
Created June 17, 2022 15:04
repro_access_to_stack_error_bpf
.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 \
#!/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 February 1, 2021 15:36
repro for kvm gvisor
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 December 3, 2020 09:28
echo server in go
package main
import (
"flag"
"fmt"
"net"
"os"
"strings"
)
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 April 16, 2021 07:07
netstack from gvisor 4 netns
package main
import (
"flag"
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"runtime"
@majek
majek / gvtcpdump.c
Created December 17, 2019 14:46
gVisor tcpdump
/*
* 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 December 16, 2019 12:18
gvisor performance with slirp4netns
#!/bin/bash
set -e
# Dependencies:
# apt install jq
if [ ]; then
GVFLAGS=--network=host
FILESZ=1G
else
FILESZ=16M