Skip to content

Instantly share code, notes, and snippets.

@yunazuno
yunazuno / drop_ipv4_tcp_80.c
Last active Mar 5, 2020
Testing a XDP program with BPF_PROG_TEST_RUN through Python
View drop_ipv4_tcp_80.c
#include <uapi/linux/if_ether.h>
#include <uapi/linux/in.h>
#include <uapi/linux/ip.h>
#include <uapi/linux/tcp.h>
int drop_ipv4_tcp_80(struct xdp_md *ctx) {
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth;
@yunazuno
yunazuno / tcl3switch.py
Created Jul 8, 2018
PoC: Offloading L3 FIB into a NIC hardware through tc
View tcl3switch.py
#!/usr/bin/env python3
import pyroute2
import socket
from pyroute2.netlink import rtnl
import subprocess
import time
from operator import itemgetter
class TCL3Switch(object):
@yunazuno
yunazuno / ethtool.py
Last active Oct 2, 2020
ethtool -S in Python
View ethtool.py
#!/usr/bin/env python
import socket
import fcntl
import struct
import array
SIOCETHTOOL = 0x8946
ETHTOOL_GSTRINGS = 0x0000001b
ETHTOOL_GSSET_INFO = 0x00000037
ETHTOOL_GSTATS = 0x0000001d
@yunazuno
yunazuno / description.md
Last active Oct 27, 2017
In Consul v0.8.4 or later, `consul watch -type event HANDLER` gives same events several time to the `HANDLER`.
View description.md

Summary

In Consul v0.8.4 or later, consul watch -type event HANDLER gives same events several time to the HANDLER.

Reproduction steps

  1. Invoke consul watch -type event HANDLER to wait events
  2. Invoke consul event -name "foo" several time to fire events

Expected result

View maglev.py
import hashlib
class MaglevHash(object):
def __init__(self, m=65537):
self.m = m
self.permutation = {}
self.entry = [None] * self.m
def add(self, node):
@yunazuno
yunazuno / drop_80_8080.c
Last active May 31, 2018
XDP: drop 80/tcp and 8080/tcp
View drop_80_8080.c
#define KBUILD_MODNAME "xdp_drop_80_8080"
#include <uapi/linux/bpf.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
BPF_HASH(counter, uint32_t, long);
@yunazuno
yunazuno / dns64.py
Created Sep 2, 2015
A DNS64 resolver with AAAA filter-like behavior (similar to the Internet Shareing on OSX El Capitan)
View dns64.py
#!/usr/bin/env python2
from twisted.internet import reactor
from twisted.names import client, dns, server
import ipaddr
import socket
class SixFourResolver(client.Resolver):
def __init__(
self,
View mizuno_netstat.log
[root@HOSTNAME:~]# netstat -natup
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
(snip)
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 38681/java
tcp 0 0 127.0.0.1:48176 127.0.0.1:8080 ESTABLISHED 38681/java
tcp 71 0 127.0.0.1:8080 127.0.0.1:48176 ESTABLISHED 38681/java
View terminal.log
[testuser@HOSTNAME norikra]$ uname -a
Linux HOSTNAME 2.6.32-431.29.2.el6.x86_64 #1 SMP Tue Sep 9 21:36:05 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[testuser@HOSTNAME norikra]$ cat /etc/redhat-release
CentOS release 6.5 (Final)
[testuser@HOSTNAME norikra]$ rbenv version
jruby-1.7.17 (set by RBENV_VERSION environment variable)
[testuser@HOSTNAME norikra]$ jruby --version
jruby 1.7.17 (1.9.3p392) 2014-12-09 fafd1a7 on OpenJDK 64-Bit Server VM 1.7.0_65-mockbuild_2014_07_16_06_06-b00 +jit [linux-amd64]
[testuser@HOSTNAME norikra]$ gem list
View norikra_sample.py
#!/usr/bin/env python
from norikraclient.client import Client
import pprint
norikra = Client()
def __read_data():
# Actually, here we read data from a data source (e.g., csv file)
You can’t perform that action at this time.