Skip to content

Instantly share code, notes, and snippets.

View yushijinhun's full-sized avatar

Haowei Wen yushijinhun

View GitHub Profile
#!/usr/bin/python3
import argparse
from bcc import BPF
import pyroute2
def main():
parser = argparse.ArgumentParser(description='Redirect traffic to another interface with VLAN')
subparsers = parser.add_subparsers(dest='command')
load_parser = subparsers.add_parser('load')
load_parser.add_argument('--iface-in', required=True, help='Name of interface to attach BPF program')
@yushijinhun
yushijinhun / ra_prefix_filter.c
Last active April 27, 2023 03:10
eBPF program to filter prefixes in IPv6 RA
/**
* ra_prefix_filter.c - eBPF program to filter prefixes in IPv6 RA
* Copyright (C) 2023 Haowei Wen <yushijinhun@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@yushijinhun
yushijinhun / ipset.js
Created December 24, 2022 06:25
Manipulate CIDRs with Node.js (Trie implementation)
import { parseIp, stringifyIp } from "ip-bigint";
/**
* @typedef { { version: 4 | 6; address: bigint; mask: number; } } CIDR
*/
/**
* @param {string} str
* @returns {CIDR}
*/
@yushijinhun
yushijinhun / ring_buffer.c
Created January 27, 2022 23:55
Ring Buffer in C
#include "ring_buffer.h"
#include <string.h>
#include <sys/param.h>
void ringbuf_init(ringbuf_t *rb, uint8_t *buf, size_t buf_size) {
rb->buf = buf;
rb->size = buf_size;
rb->begin = rb->end = 0;
}
@yushijinhun
yushijinhun / lxd-resolve-domain.md
Created April 29, 2021 10:19
[LXD] Resolve .lxd domains

Steps

Check your host IP address on LXD network interface:

$ lxc network show lxdbr0
config:
  ipv4.address: 172.17.233.1/24 # <--- IP address is 172.17.233.1
...

Edit /etc/systemd/resolved.conf.d/lxdbr0.conf:

@yushijinhun
yushijinhun / lxd-forward-desktop.md
Last active March 11, 2024 12:12
[LXD] Forward X11 & Wayland to container

Steps

First, create a LXD profile named forward-desktop:

lxc profile create forward-desktop

Edit the profile:

lxc profile forward-desktop

Replace config: {} and devices: {} with:

@yushijinhun
yushijinhun / gpg_cheatsheet.md
Last active February 26, 2020 07:21
GPG Cheatsheet
@yushijinhun
yushijinhun / enable-preview.gradle
Last active December 19, 2019 04:38
[gradle]enable java preview features
// - Adds '--enable-preview' parameter
application {
applicationDefaultJvmArgs << '--enable-preview'
}
compileJava {
options.compilerArgs << '--enable-preview'
}
@yushijinhun
yushijinhun / eclipse-modularity.gradle
Last active December 19, 2019 04:39
[gradle|jpms|eclipse|buildship] Add modularity support to Buildship
// - Adds modularity support to Buildship
// Code is originally from https://github.com/java9-modularity/gradle-modules-plugin/issues/33#issue-376998502
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
@yushijinhun
yushijinhun / download-minecraft-skin.sh
Last active December 19, 2019 04:39
[shell]Download Minecraft skin
#!/bin/bash
name=$1
wget -O - $(curl --silent https://sessionserver.mojang.com/session/minecraft/profile/$(curl --silent -X POST -H 'Content-Type: application/json' --data "[\"$name\"]" https://api.mojang.com/profiles/minecraft|grep -Po '"id"\s*:\s*"\K[^"]+')|grep -Po '"value"\s*:\s*"\K[^"]+'|base64 -d|grep -Po '"SKIN"\s*:\s*{\s*"url"\s*:\s*"\K[^"]+')