Skip to content

Instantly share code, notes, and snippets.

@majek
majek / result.txt
Created Jul 15, 2019
available setsockopts
View result.txt
[SETSOCKOPT(SOL_ICMPV6, 1)]: {.bytes = 32}
[SETSOCKOPT(SOL_IP, IP_BIND_ADDRESS_NO_PORT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_CHECKSUM)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_FREEBIND)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_HDRINCL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_MINTTL)]: {.min = 0, .max = 255}
[SETSOCKOPT(SOL_IP, IP_MTU_DISCOVER)]: {.min = 0, .max = 6}
[SETSOCKOPT(SOL_IP, IP_MULTICAST_ALL)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_IP, IP_MULTICAST_IF)]: # not settable ??
// [SETSOCKOPT(SOL_IP, IP_MULTICAST_IF)]: # only single value 0
@majek
majek / reflect_test.py
Created Jul 9, 2019
Flow label reflection doesn't work for RST
View reflect_test.py
#!/usr/bin/python3
# Before you start you need to either enable flow label reflection
# sysctl -w net.ipv6.flowlabel_reflect = 1
# or disable flow label consistency
# sysctl -w net.ipv6.flowlabel_consistency = 0
import socket
import struct
IPV6_FL_A_GET = 0
@majek
majek / double_timer_add_bug.c
Last active Jul 4, 2019
NEIGH: BUG, double timer add, state is 8
View double_timer_add_bug.c
#include <linux/netlink.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
uint8_t buf1[] =
"\x28\x00\x00\x00\x1c\x00\x1b\x05\xb1\x00\x00\x80\xe2\xfc\x64\xfd\x02"
"\x00\x00\x00\x01\x00\x00\x00\x25\x84\x80\xf0\x0a\x00\x01\x00\x00\x40"
@majek
majek / .gitignore
Last active Mar 3, 2019
ebpf overlow bug
View .gitignore
ebpf-bug
venv
ebpf-bug-kern.o
ebpf-bug-ebpf.c
bpf_helpers.h
bpf.h
@majek
majek / accept2.stp
Created Jan 18, 2019
Accept latency -> time from final ACK to accept()
View accept2.stp
/*
* stap -v accept2.stp <port> <seconds>
*/
global socks[1024]
global intervals
probe kernel.function("inet_csk_reqsk_queue_add@net/ipv4/inet_connection_sock.c").call {
req = $req
socks[req] = gettimeofday_ns()
}
View .clang-format
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
AlwaysBreakBeforeMultilineStrings: true
AllowShortBlocksOnASingleLine: false
ContinuationIndentWidth: 8
@majek
majek / Makefile
Created Dec 13, 2018
TCP splice with splice() experimentation
View Makefile
all:
clang -g -O2 -Wall -Wextra net.c send.c -o send
clang -g -O2 -Wall -Wextra net.c receive.c -o receive
clang -g -O2 -Wall -Wextra net.c proxy-naive.c -o proxy-naive
clang -g -O2 -Wall -Wextra net.c proxy-splice.c -o proxy-splice
@majek
majek / client.go
Created Sep 18, 2015
tcp performance
View client.go
package main
import (
"flag"
"fmt"
"net"
"os"
"strings"
"sync/atomic"
"time"
View README.md

How to run:

go build udp.go; sudo bash -c "ulimit -n 100000; ./udpserver"
go build udpclient.go && ./udpclient
sudo netstat -l4np --udp|grep :1234|tr -s " "|egrep -v "p 0"

Sample output

127.0.87.133:1234    0.347 ms
View a.go
package main
import (
"fmt"
"os"
"strings"
"math/rand"
"github.com/gdamore/mangos"