Skip to content

Instantly share code, notes, and snippets.

View serfreeman1337's full-sized avatar

serfreeman1337

View GitHub Profile
@serfreeman1337
serfreeman1337 / einat-nft.md
Created October 8, 2025 06:00
Endpoint-Independent NAT with Linux Netfilter

Endpoint-Independent NAT with Linux Netfilter.
Well, kindof. It just creates DNAT mappings when doing NAT hole punching with STUN servers on ports 3478, 19302.
I.e. lan_ip:54321 -> wan_ip:12345 -> stun_server_ip:3478 will create mapping wan_ip:12345 -> lan_ip:54321.
The mappings have 5 minutes expiry time that refreshes on packet sent on those ports.

  • ppp0 - wan interface.
  • br0 - lan interface.
nft add table ip einat
@serfreeman1337
serfreeman1337 / res_pjsip_outbound_registration_contact_rewrite.c
Last active January 20, 2025 06:28
PJSIP Outbound Registration Contact Rewrite Module
/*
* Asterisk Module to rewrite contact for outbound registrations.
* On successful registration the contact's host and port will be updated to match "received" and "rport" params from the response "Via" header.
* Outbound registration's "contact_user" param needs to be set for proper contact rewrites in INVITEs too.
*
* Copy to the "res/" folder and compile asterisk.
*/
/*** MODULEINFO
<depend>pjproject</depend>
@serfreeman1337
serfreeman1337 / cf_fix.sh
Last active February 23, 2024 14:45
destination address rewrite example with nftables
#!/bin/sh
# Rewrite 104.21.0.69 - 104.21.95.255 to 172.64.41.0
# https://community.cloudflare.com/t/routing-loop-to-cloudflare-ips/618854
nft add table cf_fix
nft add map cf_fix ct_daddr '{ typeof ct id : ip daddr; flags dynamic; timeout 10s; }'
# I have no idea how to convert mark value to addr.
nft add map cf_fix mark_to_daddr '{ typeof mark : ip daddr; flags dynamic; timeout 10s; }'
@serfreeman1337
serfreeman1337 / rtnetlink.go
Created December 7, 2023 13:36
Golang Rtnetlink RTM_GETSTATS example to get network interface statistics
@serfreeman1337
serfreeman1337 / 0-playlister-test.md
Last active November 21, 2023 14:39
golang server to serve mkvs over http

Preview

A dumb idea to serve mkvs over HTTP with auto m3u8 playlist generation and bloat material 2 UI.

@serfreeman1337
serfreeman1337 / 0-natmap-qbittorrent-systemd.md
Last active November 20, 2023 15:13
natmap tcp hole redirect with nftables