Skip to content

Instantly share code, notes, and snippets.

View YutaroHayakawa's full-sized avatar
🌴
On vacation

Yutaro Hayakawa YutaroHayakawa

🌴
On vacation
  • Isovalent at Cisco
  • San Jose, California, US
  • 01:28 (UTC -07:00)
  • X @YutaroHayakawa
View GitHub Profile
@YutaroHayakawa
YutaroHayakawa / list.h
Created April 13, 2016 14:27
Linux kernel linked list, modified for userspace
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
#include <stdio.h>
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
@YutaroHayakawa
YutaroHayakawa / get_eth_addr.c
Last active April 29, 2016 05:52
Get ethernet address from interface name in FreeBSD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <ifaddrs.h>
@YutaroHayakawa
YutaroHayakawa / get_ip4_addr.c
Created April 29, 2016 05:52
Get IPv4 address from interface name in FreeBSD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/if.h>
#include <ifaddrs.h>
#define FORMAT_IP4_ADDR "%u.%u.%u.%u"
@YutaroHayakawa
YutaroHayakawa / report.lua
Created October 10, 2016 14:10
Lua script for formatting output of wrk to csv
done = function(summary, latency, requests)
-- open output file
f = io.open("result.csv", "a+")
-- write below results to file
-- minimum latency
-- max latency
-- mean of latency
-- standard deviation of latency
-- 50percentile latency
@YutaroHayakawa
YutaroHayakawa / Makefile
Last active January 17, 2019 12:57
Detect deletion of kernel internal TCP socket structure on Linux using ULP and eventfd.
obj-m:=tcp_monitor.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
@YutaroHayakawa
YutaroHayakawa / fedora_chroot.bash
Last active January 4, 2023 01:56
Bash script to setup simple Fedora chroot environment from container layer image
#!/bin/bash
# You can find the container image for each release from here. Please rewrite below url to your nearest one.
# https://admin.fedoraproject.org/mirrormanager/
CONTAINER_IMAGE="http://mirror.crucial.com.au/fedora/linux/releases/30/Container/x86_64/images/Fedora-Container-Base-30-1.2.x86_64.tar.xz"
function setup() {
local CHROOT=$1
@YutaroHayakawa
YutaroHayakawa / iptrace.py
Last active September 18, 2019 18:12
Linux kernel L3 routing tracing
import re
import click
import socket
import ipaddress
import dataclasses
from bcc import BPF
from ctypes import *
from jinja2 import Template
@YutaroHayakawa
YutaroHayakawa / tap_test.c
Created October 28, 2019 13:05
Send gso frame using virtio-net header from tap
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stddef.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <assert.h>
@YutaroHayakawa
YutaroHayakawa / tun.c
Created October 28, 2019 14:29
Extension for tun device to handle IPIP GSO
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* TUN - Universal TUN/TAP device driver.
* Copyright (C) 1999-2002 Maxim Krasnyansky <[email protected]>
*
* $Id: tun.c,v 1.15 2002/03/01 02:44:24 maxk Exp $
*/
/*
* Changes:
BPF = {}
local emit = function (code, dst, src, off, imm)
return string.pack("=I1I1I2I4", code, dst << 4 | src, off, imm)
end
-- Register
BPF.R0 = 0
BPF.R1 = 1
BPF.R2 = 2