| name | littlesnitch-linux |
| description | Open source eBPF-based network monitoring and blocking components for Little Snitch on Linux |
| triggers | ["little snitch linux","ebpf network monitoring rust","block hosts linux ebpf","littlesnitch ebpf setup","linux network firewall ebpf rust","load ebpf programs rust aya","ebpf maps blocklist linux","littlesnitch linux demo runner"] |
Little Snitch for Linux — eBPF Network Monitor
Skill by ara.so — Daily 2026 Skills collection.
Little Snitch for Linux is an open-source eBPF-based network monitoring and blocking toolkit written in Rust. It attaches eBPF programs to the Linux kernel to intercept network connections, then shares data between kernel and user space via eBPF maps. The open-source portion includes eBPF programs, shared types, and a demo runner; the full product from Objective Development includes additional proprietary UI and rule-engine components.
Architecture Overview
┌─────────────────────────────────┐
│ demo-runner (user space) │
│ - loads eBPF programs │
│ - populates eBPF maps │
│ - reads events from kernel │
└────────────┬────────────────────┘
│ eBPF maps (shared memory)
┌────────────▼────────────────────┐
│ ebpf crate (kernel) │
│ - eBPF programs (TC, LSM, etc) │
│ - intercepts network syscalls │
└─────────────────────────────────┘
│
┌────────────▼────────────────────┐
│ common crate │
│ - shared types & functions │
│ - used by both kernel & user │
└─────────────────────────────────┘
Crates:
ebpf/ — eBPF kernel-space programs (compiled to BPF bytecode)
common/ — Shared types between kernel and user space
demo-runner/ — User-space loader and event consumer
webroot/ — JavaScript web UI
Prerequisites
Rust Toolchains
rustup toolchain install stable
rustup toolchain install nightly --component rust-src
System Dependencies
cargo install bpf-linker
sudo apt install clang
sudo dnf install clang
sudo pacman -S clang
Kernel Requirements
- Linux kernel 5.15+ (for BTF and CO-RE support)
- eBPF enabled in kernel config (
CONFIG_BPF=y, CONFIG_BPF_SYSCALL=y)
CAP_BPF or root privileges to load eBPF programs
Build & Run
git clone https://github.com/obdev/littlesnitch-linux
cd littlesnitch-linux
cargo build --release
sudo cargo run --release
cargo check
Note: Cargo build scripts automatically compile the eBPF programs and embed them in the binary — no manual eBPF compilation step needed.
Blocklist Configuration
The demo runner loads two blocklist files at startup:
blocked_hosts.txt
One IP address or hostname per line:
93.184.216.34
203.0.113.0
198.51.100.1
blocked_domains.txt
One domain suffix per line (blocks domain and all subdomains):
example.com
ads.doubleclick.net
tracking.example.org
Place these files in the working directory before running:
echo "93.184.216.34" > blocked_hosts.txt
echo "example.com" > blocked_domains.txt
sudo cargo run --release
Common Crate — Shared Types
The common crate defines types shared between kernel eBPF code and user-space. When extending the project, add new shared types here.
#![no_std]
#[repr(C)]
#[derive(Clone, Copy)]
pub struct ConnectionEvent {
pub pid: u32,
pub uid: u32,
pub src_addr: u32,
pub dst_addr: u32,
pub src_port: u16,
pub dst_port: u16,
pub protocol: u8,
pub action: u8,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct IpKey {
pub addr: u32,
}
eBPF Crate — Kernel Programs
eBPF programs live in ebpf/src/ and are compiled to BPF bytecode using the nightly toolchain.
#![no_std]
#![no_main]
use aya_ebpf::{
macros::classifier,
programs::TcContext,
maps::HashMap,
};
use aya_ebpf::bindings::TC_ACT_SHOT;
use aya_ebpf::bindings::TC_ACT_OK;
use common::IpKey;
#[map]
static BLOCKED_HOSTS: HashMap<IpKey, u8> = HashMap::with_max_entries(65536, 0);
#[classifier]
pub fn egress_filter(ctx: TcContext) -> i32 {
match try_egress_filter(ctx) {
Ok(action) => action,
Err(_) => TC_ACT_OK,
}
}
fn try_egress_filter(ctx: TcContext) -> Result<i32, ()> {
let dst_addr = 0u32;
let key = IpKey { addr: dst_addr };
if unsafe { BLOCKED_HOSTS.get(&key) }.is_some() {
return Ok(TC_ACT_SHOT);
}
Ok(TC_ACT_OK)
}
Demo Runner — User Space Loader
The demo runner uses Aya to load eBPF programs and interact with maps.
use aya::{Bpf, maps::HashMap};
use aya::programs::{tc, SchedClassifier, TcAttachType};
use std::net::Ipv4Addr;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut bpf = Bpf::load(aya::include_loaded_bytes!("../../target/bpfel-unknown-none/release/ebpf"))?;
let iface = "eth0";
tc::qdisc_add_clsact(iface)?;
let program: &mut SchedClassifier = bpf
.program_mut("egress_filter")
.unwrap()
.try_into()?;
program.load()?;
program.attach(iface, TcAttachType::Egress)?;
let mut blocked_hosts: HashMap<_, u32, u8> =
HashMap::try_from(bpf.map_mut("BLOCKED_HOSTS").unwrap())?;
let hosts = std::fs::read_to_string("blocked_hosts.txt")?;
hosts.() {
= line.();
line.() || line.() { ; }
(addr) = line.parse::<Ipv4Addr>() {
= ::(addr).();
blocked_hosts.(ip_u32, , )?;
(, line);
}
}
();
tokio::signal::().?;
();
(())
}
Adding a New Blocked Domain
use aya::maps::HashMap;
fn load_blocked_domains(
bpf: &mut aya::Bpf,
path: &str,
) -> anyhow::Result<()> {
let mut map: HashMap<_, [u8; 256], u8> =
HashMap::try_from(bpf.map_mut("BLOCKED_DOMAINS").unwrap())?;
let content = std::fs::read_to_string(path)?;
for domain in content.lines() {
let domain = domain.trim();
if domain.is_empty() { continue; }
let mut key = [0u8; 256];
let bytes = domain.as_bytes();
key[..bytes.len()].copy_from_slice(bytes);
map.insert(key, 1, 0)?;
}
Ok(())
}
Reading Events from Kernel
use aya::maps::RingBuf;
use aya::util::online_cpus;
use common::ConnectionEvent;
use tokio::io::unix::AsyncFd;
async fn read_events(bpf: &mut aya::Bpf) -> anyhow::Result<()> {
let ring_buf = RingBuf::try_from(bpf.map_mut("EVENTS").unwrap())?;
let mut async_fd = AsyncFd::new(ring_buf)?;
loop {
let mut guard = async_fd.readable_mut().await?;
let ring_buf = guard.get_inner_mut();
while let Some(item) = ring_buf.next() {
let event: &ConnectionEvent = unsafe {
&*(item.as_ptr() as *const ConnectionEvent)
};
println!(
"pid={} dst={}:{} action={}",
event.pid,
Ipv4Addr::from(u32::from_be(event.dst_addr)),
::(event.dst_port),
event.action == { } { }
);
}
guard.();
}
}
Cargo.toml Structure
[package]
name = "demo-runner"
version = "0.1.0"
edition = "2021"
[dependencies]
aya = { version = "0.12", features = ["async_tokio"] }
aya-log = "0.2"
common = { path = "../common" }
anyhow = "1"
tokio = { version = "1", features = ["full"] }
log = "0.4"
env_logger = "0.10"
[build-dependencies]
aya-build = "0.1"
[package]
name = "ebpf"
version = "0.1.0"
edition = "2021"
[dependencies]
aya-ebpf = "0.1"
aya-log-ebpf = "0.1"
common = { path = "../common" }
[[bin]]
name = "ebpf"
path = "src/main.rs"
Troubleshooting
"Operation not permitted" when loading eBPF
sudo cargo run --release
sudo setcap cap_bpf,cap_net_admin+eip target/release/demo-runner
./target/release/demo-runner
Build fails: bpf-linker not found
cargo install bpf-linker
sudo apt install llvm-dev libclang-dev
eBPF verifier rejects program
- Reduce map sizes or loop bounds
- Ensure all memory accesses are bounds-checked
- Check kernel version supports the helpers you're using:
uname -r
Map not found error
cargo build --release 2>&1 | grep -i ebpf
blocked_hosts.txt not found
touch blocked_hosts.txt blocked_domains.txt
sudo cargo run --release
License
All code in this repository is licensed under GPL-2.0. Contributions submitted to this project are licensed under the same terms.