Skip to content

Instantly share code, notes, and snippets.

View nyrahul's full-sized avatar
🐞

Rahul Jadhav nyrahul

🐞
View GitHub Profile
@nyrahul
nyrahul / hyperthreading_ctl.sh
Created January 10, 2018 06:03
Enable/Disable hyperthreading & multicore on x86 machines with linux (ubuntu distro tested)
#!/bin/bash
trap byefunc EXIT
byefunc()
{
[[ "$NO_CPUINFO" == "1" ]] && return
lscpu
}
@nyrahul
nyrahul / writepcap.c
Last active March 15, 2023 14:33
Write a packet buffer to a file in pcap format without using pcap libs/hdrs.
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/time.h>
/*---------------------------------------------------------------------------*/
/* CITT CRC16 polynomial ^16 + ^12 + ^5 + 1 */
/*---------------------------------------------------------------------------*/
unsigned short crc16_add(unsigned char b, unsigned short acc)
{
#!/bin/bash
set -E
trap 'echo Failed line: $LINENO command: $BASH_COMMAND && exit $?' ERR
lcnt=1
nw_pref="192.168.10"
create_node()
{
ns="$1"; shift;
@joestringer
joestringer / micro-k8s-setup.md
Last active April 20, 2021 17:06
MicroK8s development environment setup for Cilium

Set up microk8s with Cilium for development

Microk8s is a Canonical project to provide a kubernetes environment for local development, similar to minikube but without requiring a separate VM to manage. These instructions describe setting it up for common development use cases with Cilium and may be helpful in particular for testing BPF kernel extensions with Cilium.

Microk8s will run its own containerd runtime, which may be initially confusing when building containers locally with docker. This guide assumes that you will use docker locally for building containers, and push these into a microk8s registry for use by containerd in the microk8s environment.

This guide works with MicroK8s 1.14 or above, with containerd. If you are running an earlier version, see the previous instructions.

Requirements

@nyrahul
nyrahul / interesting c one-liners
Last active June 10, 2020 02:18
cpu efficient c one-liners
bool isPowOf2(val)
{
return val && !( val & ( val - 1));
// val && is required so that val=0 is handled. 0 is not the pow of 2
}
/* increment val only if MAX_UINT val not reached. Use-case: for stats incr, you dont want the val to cycle */
#define STAT(S) (S) += (!!(S ^ 0xffffffff)) // S will incr by 1 only till it reach 0xffffffff
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalVariableCase, value: camelBack }
@nyrahul
nyrahul / Makefile
Last active April 10, 2019 10:39
Makefile trick: disable verbose compilation .. enable verbose only if 'make V=1'
CC=gcc
AR=ar
V = 0
ACTUAL_CC := $(CC)
CC_0 = @echo "CC [$<]"; $(ACTUAL_CC)
CC_1 = $(ACTUAL_CC)
CC = $(CC_$(V))
ACTUAL_AR := $(AR)
@nyrahul
nyrahul / log_timestamp_perf.c
Created May 27, 2020 02:10
Measures impact of fancy timestamps in logging
/*
gtd format: ss:usec ... raw time of day format .. difficult to read ..
whitefield format: ss:ms .. eases timestamp reading cuz ms format used
cooja format: hh:mm:ss.ms ... most easiest to read
./a.out 7 // show sample test of all timestamps with print
./a.out 1 1 // perf-test gettimeofday only
./a.out 2 1 // perf-test whitefield style
./a.out 4 1 // perf-test cooja style
@nyrahul
nyrahul / idspoof.py
Created December 31, 2020 11:51
Spoofing Cilium identity value in vxlan tunneled mode
#! /usr/bin/env python
# Aim of this script is to send a vxlan tunneled HTTP request with spoofed
# identity and pass through the authz checks implemented in cilium-ebpf.
# Configuration you need to set correct:
# 1. The target pod address (dip, dport) to which you want to make unauthorized access
# 2. The source identity (identity = 8849 below) to spoof. Use `cilium identity
# list` to check valid identity values.
# 3. The target node's vxlan IP address (vxlan_ip) and port (vxlan_port = 8472