Skip to content

Instantly share code, notes, and snippets.

@ae6rt
Last active December 17, 2019 23:48
Show Gist options
  • Save ae6rt/a459f148d999eb384f8b2423724a3fa7 to your computer and use it in GitHub Desktop.
Save ae6rt/a459f148d999eb384f8b2423724a3fa7 to your computer and use it in GitHub Desktop.
Building tcng

build

tcng is a higher level language around the Linux traffic shaping tool tc. Users craft a tcng specification, and compile that to an equivalent set of tc commands.

Reference: http://linux-ip.net/gl/tcng/node1.html

Do this in a debian container

apt-get update
apt-get install -y git file make gcc bison flex perl

git clone https://github.com/spacepub/tcng.git
cd tcng

./configure --no-tcsim  --c99
cd shared
make 
cd ..
make
ln -s /tcng/lib/tcng/include /tcng/include

use

Given tcng configuration in a file sample-1.tc

dev eth0 {
    egress {
        drop if tcp_sport != PORT_HTTP;
    }
}

create this file inside the container in directory /t and run the compiler on it

/tcng/bin/tcc -r /t/sample-1.tc

which outputs

tc qdisc del dev eth0 root
tc qdisc del dev eth0 ingress

# ================================ Device eth0 ================================

tc qdisc add dev eth0 handle 1:0 root dsmark indices 1 default_index 0
tc filter add dev eth0 parent 1:0 protocol all prio 1 handle 1:0:0 u32 divisor 1
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u8 0x6 0xff at 9 offset at 0 mask 0f00 shift 6 eat link 1:0:0
tc filter add dev eth0 parent 1:0 protocol all prio 1 handle 1:0:1 u32 ht 1:0:0 match u16 0x50 0xffff at 0 classid 1:0
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u8 0x6 0xff at 9 classid 1:0 police index 1 rate 1bps burst 1 action drop/drop
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u32 0x0 0x0 at 0 classid 1:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment