Skip to content

Add luatc binding#571

Open
sneaky-potato wants to merge 3 commits into
sneaky-potato/gsoc26from
sneaky-potato/luatc
Open

Add luatc binding#571
sneaky-potato wants to merge 3 commits into
sneaky-potato/gsoc26from
sneaky-potato/luatc

Conversation

@sneaky-potato
Copy link
Copy Markdown
Member

@sneaky-potato sneaky-potato commented May 22, 2026

Testing steps:

  1. Run TC Lua script in softirq (tc.lua)
local tc     = require("tc")
local action = require("linux.tc")

local function filter_sni(ctx)
	local skb = ctx:skb()
	print(string.format("[tc] skb_len: %d", #skb))
	ctx:action(action.ACT_OK)
end

tc.attach(filter_sni)
  1. Create a classifier eBPF prgram (tc.bpf.c)
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

extern int bpf_luatc_run(char *key, size_t key__sz, struct __sk_buff *tc_ctx) __ksym;

static char runtime[] = "examples/filter/tc";

int const TC_ACT_OK = 0;

SEC("classifier")
int filter_https(struct __sk_buff *tc_ctx)
{
	int action = bpf_luatc_run(runtime, sizeof(runtime), tc_ctx);
	return action < 0 ? TC_ACT_OK : action;
}

char _license[] SEC("license") = "Dual MIT/GPL";
  1. Attach the compiler eBPF program to docker bridge
tc qdisc del dev docker0 clsact 2>/dev/null
tc qdisc add dev docker0 clsact

tc filter add dev docker0 egress \
    bpf da obj examples/filter/tc.bpf.o sec classifier
  1. Generate traffic with docker
sudo docker run --rm alpine/curl http://localhost:8080

Signed-off-by: Ashwani Kumar Kamal <ashwanikamal.im421@gmail.com>
@sneaky-potato sneaky-potato force-pushed the sneaky-potato/luatc branch from f324f07 to e61e9b8 Compare May 23, 2026 16:46
Signed-off-by: Ashwani Kumar Kamal <ashwanikamal.im421@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant